Hi, complete newbie to JME, LWGL, and gaming. Having real problems loading Sketchup material files. Hope someone here can help.
I'm hoping to use Sketchup for graphical model-building, then animate the models with Java+JME. Situation is: can load Sketchup models (.obj files) fine, but the materials file (.mtl) appears to be loaded properly, but ignored. End result is ugly, with what seems to be artificially generated textures (mostly black) used instead of the .mtl file contents.
The maggie demo loads fine. But I gather it uses textures rather than materials.
Here's the code I'm using. The commented out section seems to make no difference.
The .obj and .mtl files (from ./models) will follow:
this.bomb = new ModelNode("Bomb.obj");
rootNode.updateRenderState();
}
catch (IOException e)
{
System.out.println("Damn exceptions!" + e);
e.printStackTrace();
}
}
public static void main(String[] args)
{
Main main = new Main();
main.start();
}
class ModelNode
{
final Node node;
ModelNode(String file) throws IOException
{
URL url = Main.class.getClassLoader().getResource(file);
FormatConverter converter = new ObjToJme();
converter.setProperty("mtllib", url);
converter.setProperty("texurl", url);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
JmeBinaryReader jbr = new JmeBinaryReader();
BinaryToXML btx = new BinaryToXML();
OutputStreamWriter osw = new OutputStreamWriter(System.out);
converter.convert(url.openStream(), bos);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
btx.sendBinarytoXML(bis, osw);
jbr.setProperty("bound", "box");
this.node = new Node(file);
bis = new ByteArrayInputStream(bos.toByteArray());
jbr.loadBinaryFormat(node, bis);
node.setLocalScale(10f);
node.setName(file);
// node.setModelBound(new BoundingBox());
And the .obj file, if it fits (is this site really that short of RAM? 20K? Sheesh).
# Alias OBJ Model File
# Exported from SketchUp, (c) 2000-2005 @Last Software, Inc.
# File units = feet
mtllib Bomb.mtl
g Group2223 Group_24767 Model
usemtl Material1_
v 3.612 -1.4287 -1.10347
vt 10.5512 -2.07083e-34
vn 0.707107 -6.27641e-18 0.707107
v 3.15814 -0.279095 -0.649602
vt 0 18.8976
v 3.15814 -1.4287 -0.649602
vt 0 0
f 1/1/1 2/2/1 3/3/1
v 3.39841 0.442067 -0.889878
vt 5.58579 30.7524
f 2/2/1 1/1/1 4/4/1
v 3.39841 0.65768 -0.889878
vt 5.58579 34.2967
f 4/4/1 1/1/1 5/5/1
v 3.612 -0.288675 -1.10347
vt 10.5512 18.7402
f 5/5/1 1/1/1 6/6/1
usemtl Material1_
vn -0.707107 6.27641e-18 -0.707107
f 3/3/2 2/2/2 1/1/2
f 4/4/2 1/1/2 2/2/2
f 5/5/2 1/1/2 4/4/2
f 6/6/2 1/1/2 5/5/2
l 2 3
l 3 1
l 1 6
l 5 6
l 4 5
l 2 4
g Group2224 Group_24767 Model
usemtl Material1_
v 2.01629 -1.4287 -1.10347
vn 0.707107 -6.27641e-18 -0.707107
v 2.47015 -0.279095 -0.649602
v 2.47015 -1.4287 -0.649602
f 7/1/3 8/2/3 9/3/3
v 2.22988 0.442067 -0.889878
f 8/2/3 7/1/3 10/4/3
v 2.22988 0.65768 -0.889878
f 10/4/3 7/1/3 11/5/3
v 2.01629 -0.288675 -1.10347
f 11/5/3 7/1/3 12/6/3
usemtl Material1_
vn -0.707107 6.27641e-18 0.707107
f 9/3/4 8/2/4 7/1/4
f 10/4/4 7/1/4 8/2/4
f 11/5/4 7/1/4 10/4/4
f 12/6/4 7/1/4 11/5/4
l 8 9
l 9 7
l 7 12
l 11 12
l 10 11
l 8 10
g Group2225 Group_24767 Model
usemtl Material1_
v 3.612 -1.4287 0.492247
vn -0.707107 -6.27641e-18 0.707107
v 3.15814 -0.279095 0.0383811
v 3.15814 -1.4287 0.0383811
f 13/1/5 14/2/5 15/3/5
v 3.39841 0.442067 0.278658
f 14/2/5 13/1/5 16/4/5
v 3.39841 0.65768 0.278658
f 16/4/5 13/1/5 17/5/5
v 3.612 -0.288675 0.492247
f 17/5/5 13/1/5 18/6/5
usemtl Material1_
vn 0.707107 6.27641e-18 -0.707107
f 15/3/6 14/2/6 13/1/6
f 16/4/6 13/1/6 14/2/6
f 17/5/6 13/1/6 16/4/6
f 18/6/6 13/1/6 17/5/6
l 14 15
l 15 13
l 13 18
l 17 18
l 16 17
l 14 16
g Group2226 Group_24767 Model
usemtl Material1_
v 3.15814 -0.279095 -0.649602
v 3.15814 -1.4287 -0.649602
f 1/1/1 19/2/1 20/3/1
v 3.39841 0.442067 -0.889878
f 19/2/1 1/1/1 21/4/1
v 3.39841 0.65768 -0.889878
f 21/4/1 1/1/1 22/5/1
f 22/5/1 1/1/1 6/6/1
usemtl Material1_
f 20/3/2 19/2/2 1/1/2
f 21/4/2 1/1/2 19/2/2
f 22/5/2 1/1/2 21/4/2
f 6/6/2 1/1/2 22/5/2
l 19 20
l 20 1
l 1 6
l 22 6
l 21 22
l 19 21
g Group2227 Group_24767 Model
usemtl Material1_
v 2.01629 -1.4287 0.492247
vn -0.707107 -6.27641e-18 -0.707107
v 2.47015 -0.279095 0.0383811
v 2.47015 -1.4287 0.0383811
f 23/1/7 24/2/7 25/3/7
v 2.22988 0.442067 0.278658
f 24/2/7 23/1/7 26/4/7
v 2.22988 0.65768 0.278658
f 26/4/7 23/1/7 27/5/7
v 2.01629 -0.288675 0.492247
f 27/5/7 23/1/7 28/6/7
usemtl Material1_
vn 0.707107 6.27641e-18 0.707107
f 25/3/8 24/2/8 23/1/8
f 26/4/8 23/1/8 24/2/8
f 27/5/8 23/1/8 26/4/8
f 28/6/8 23/1/8 27/5/8
l 24 25
l 25 23
l 23 28
l 27 28
l 26 27
l 24 26
g Group_24767 Model
usemtl Material3_
v 3.3785 4.46078 -0.45683
vt 1.8438 10.3925
vn -0.682913 -0.70721 0.182986
v 3.17193 4.59209 -0.51218
vt -1.08911 9.70929
vn -0.432917 -0.866089 0.249945
v 3.32014 4.46078 -0.597744
vt 1.27405 8.65314
vn -0.612283 -0.70721 0.353502
f 29/7/9 30/8/10 31/9/11
v 3.21321 4.59209 -0.412539
vt -0.68623 10.9392
vn -0.482856 -0.866089 0.129381
f 30/8/10 29/7/9 32/10/12
usemtl Material3_
v 2.60029 3.87652 -1.10373
vt -31.2035 -13.2448
vn 0 1 0
v 3.028 3.87652 -1.10373
vt -36.336 -13.2448
v 2.81414 3.87652 -1.13189
vt -33.7697 -13.5827
f 55/57/77 56/58/77 57/59/77
v 2.40101 3.87652 -1.02119
vt -28.8121 -12.2543
f 56/58/77 55/57/77 58/60/77
v 3.22728 3.87652 -1.02119
vt -38.7274 -12.2543
f 56/58/77 58/60/77 59/61/77
v 3.39841 3.87652 -0.889878
vt -40.781 -10.6785
f 59/61/77 58/60/77 60/62/77
v 2.22988 3.87652 -0.889878
vt -26.7585 -10.6785
f 60/62/77 58/60/77 61/63/77
vt -42.3567 -8.625
f 60/62/77 61/63/77 36/64/77
v 2.09857 3.87652 -0.71875
vt -25.1828 -8.625
f 36/64/77 61/63/77 62/65/77
vt -43.3472 -6.23361
f 36/64/77 62/65/77 37/66/77
v 2.01602 3.87652 -0.519467
vt -24.1922 -6.23361
f 37/66/77 62/65/77 63/67/77
v 3.64042 3.87652 -0.30561
vt -43.6851 -3.66732
f 37/66/77 63/67/77 64/68/77
v 1.98787 3.87652 -0.30561
vt -23.8544 -3.66732
f 64/68/77 63/67/77 65/69/77
v 2.01602 3.87652 -0.0917534
vt -24.1922 -1.10104
f 64/68/77 65/69/77 66/70/77
v 3.61227 3.87652 -0.0917534
vt -43.3472 -1.10104
f 64/68/77 66/70/77 67/71/77
v 3.52972 3.87652 0.10753
vt -42.3567 1.29035
f 67/71/77 66/70/77 68/72/77
v 2.09857 3.87652 0.10753
vt -25.1828 1.29035
f 68/72/77 66/70/77 69/73/77
v 3.39841 3.87652 0.278658
vt -40.781 3.34389
f 68/72/77 69/73/77 70/74/77
v 2.22988 3.87652 0.278658
vt -26.7585 3.34389
f 70/74/77 69/73/77 71/75/77
v 2.40101 3.87652 0.409969
vt -28.8121 4.91963
f 70/74/77 71/75/77 72/76/77
v 3.22728 3.87652 0.409969
vt -38.7274 4.91963
f 70/74/77 72/76/77 73/77/77
v 3.028 3.87652 0.492514
vt -36.336 5.91017
f 73/77/77 72/76/77 74/78/77
v 2.60029 3.87652 0.492514
vt -31.2035 5.91017
f 74/78/77 72/76/77 75/79/77
v 2.81414 3.87652 0.520669
vt -33.7697 6.24803
f 74/78/77 75/79/77 76/80/77
usemtl Material3_
vn -0 -1 -0
f 57/59/78 56/58/78 55/57/78
f 58/60/78 55/57/78 56/58/78
f 59/61/78 58/60/78 56/58/78
f 60/62/78 58/60/78 59/61/78
f 61/63/78 58/60/78 60/62/78
f 36/64/78 61/63/78 60/62/78
f 62/65/78 61/63/78 36/64/78
f 37/66/78 62/65/78 36/64/78
f 63/67/78 62/65/78 37/66/78
f 64/68/78 63/67/78 37/66/78
f 65/69/78 63/67/78 64/68/78
f 66/70/78 65/69/78 64/68/78
f 67/71/78 66/70/78 64/68/78
f 68/72/78 66/70/78 67/71/78
f 69/73/78 66/70/78 68/72/78
f 70/74/78 69/73/78 68/72/78
f 71/75/78 69/73/78 70/74/78
f 72/76/78 71/75/78 70/74/78
f 73/77/78 72/76/78 70/74/78
f 74/78/78 72/76/78 73/77/78
f 75/79/78 72/76/78 74/78/78
f 76/80/78 75/79/78 74/78/78
usemtl Material3_
v 3.64042 0.442067 -0.30561
vt -23.4191 0.764347
vn -0.90461 0.426241 2.44578e-16
vt -13.7679 -0.757245
v 3.30062 -0.279095 -0.30561
vt -13.8527 0.764347
f 77/81/79 49/82/63 78/83/79
vt -23.2751 -1.82007
f 49/82/63 77/81/79 47/84/63
usemtl Material1_
vn 0.90461 -0.426241 -2.44578e-16
f 78/83/80 49/82/65 77/81/80
f 47/84/65 77/81/80 49/82/65
usemtl Material3_
vt -46.5182 2.0661
vn -1 1.35683e-15 -6.71882e-16
vt -43.638 -0.522326
v 3.64042 3.6365 -0.30561
vt -43.638 2.0661
f 64/85/81 52/86/67 79/87/81
vt -46.5182 -0.522326
f 52/86/67 64/85/81 37/88/67
usemtl Material2_
vn 1 -1.35683e-15 6.71882e-16
f 79/87/82 52/86/69 64/85/82
f 37/88/69 64/85/82 52/86/69
.obj/.mlt is the wavefront alias format. note that it doesn't support animations.
it might be easier for you if you would post a link to the files
one thing i noticed is that you use the material file as texture hint. the obj loader/converter doesn't use such a texture hint. either you edit the .mtl file to point to the right directory, or you put the textures in the same directory whith the .obj and .mtl file.
Not sure what you mean by "use material file as texture hint". The only code related to textures is commented out, and it made no difference in or out. I don't plan to use textures, just materials.
Also don't understand "doesn't support animations". Once loaded and chewed on by JmeLoader,
how would the aniimator know from whence the node came? And if not animation, surely it supports
motion commands, which is all I mean by animation. I want to load them and move them around
with explicit motion calls from my code. Don't plan to use canned animation routines.
whan i said that obj doesn't support animations i meant that you can't save animation data in obj files. ofcourse you may do anything you want with the model after you load it in your program.
by texture hint i meant : converter.setProperty("texurl", url);
that line has no effect.
there are some wrong things about your model:
your bomb model has an inside. quite much of an inside i would say. there are a lot of polys on the inside of the model, which one will never see, but which will be processed jme(and opengl). it seems like you have wa too much geometry (~1900+ triangles). that's very much for a bomb (unless the bomb is very important in your game) ;)
your model is not centered (you might wonder later why the bomb doesn't strike at the location it's supposed to strike at)
you use very sharp triangles (very bad for texturing - if you intend to texture your model)
there seems to be something wrong whith the normals, but i'm not sure what it is. i'm currently at work, but when i get home i can take a closer look
if you want, i can redo that bomb model for you this evening. it's quite simple. just tell me how detailed you want it to be :P