Hi again,
i have a general question. Does jME import the textures/texturecoordinates automatically? That means if I create a modell and texture it in 3ds max and save it up as a textured 3ds.file. Will jME show me the modell WITH the texture if i load it into jme or do i have to import and apply the texture separately…?
i am still trying to import a 3ds file…jme is very cool…but also not as easy as i thought…
You should be able to create your model, complete with textures, export, then import and get everything all at once. See the tests for more.
Here's a three little helper methods: (note: these are only for 3ds models)
public static void convert(String s, String s1, String s2)
{
URL url = game.class.getClassLoader().getResource(s);
URL url1 = game.class.getClassLoader().getResource(s1);
MaxToJme maxtojme = new MaxToJme();
maxtojme.setProperty("texurl", url1);
try
{
FileOutputStream fileoutputstream = new FileOutputStream(s2);
maxtojme.convert(url.openStream(), fileoutputstream);
}
catch(IOException ioexception)
{
ioexception.printStackTrace();
System.exit(0);
}
}
public static Node Load3DSFile(String s, String s1, String s2)
{
Node node = new Node(s);
URL url = game.class.getClassLoader().getResource(s1);
URL url1 = game.class.getClassLoader().getResource(s2);
MaxToJme maxtojme = new MaxToJme();
maxtojme.setProperty("texurl", url1);
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
try
{
maxtojme.convert(url.openStream(), bytearrayoutputstream);
Node node1 = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(bytearrayoutputstream.toByteArray()));
node1.setLocalScale(0.1F);
node1.setLocalRotation((new Quaternion()).fromAngleAxis(- FastMath.PI/2, new Vector3f(1.0F, 0.0F, 0.0F)));
node1.setCullMode(3);
node1.setModelBound(new BoundingBox());
node1.updateModelBound();
node.attachChild(node1);
}
catch(IOException ioexception)
{
ioexception.printStackTrace();
System.exit(0);
}
return node;
}
public static Node LoadJmeFile(String s, String s1)
{
Node node = new Node(s);
URL url = game.class.getClassLoader().getResource(s1);
try
{
Node node1 = (Node)BinaryImporter.getInstance().load(url);
node1.setLocalScale(0.1F);
node1.setLocalRotation((new Quaternion()).fromAngleAxis(-FastMath.PI/2, new Vector3f(1.0F, 0.0F, 0.0F)));
node1.setCullMode(3);
node1.setModelBound(new BoundingBox());
node1.updateModelBound();
node.attachChild(node1);
}
catch(IOException ioexception)
{
ioexception.printStackTrace();
System.exit(0);
}
return node;
}
If you wanna load a 3ds model, you can load it by calling Load3dsFile(nodename, modellocation, textureslocation); (replace the values). This takes a lot of time to load each time, thats what convert(modellocation, textureslocation, outputlocation) is for. It converts it to a jme native format file, which means it will speed up stuff a lot (needs only to be done once). Next you can load such a jme file by calling LoadJmeFile(nodename, modellocation);
Well, i have used the"maggie" - example and adjusted it to 3ds. It worked well with the bike.3ds but if i try to load my own 3ds.file it doesnt work. I just change the name from…/bike.3ds -> /MyModel.3ds
You mentioned somthing with "load3dsfile (location,…,)" how does this command work?
Do you have a example/tutorial for "loading 3dsfiles.???"
I think there is no really good documentation or instruction manual for learning jme…many good examples…but no explanations…
thanx alot
okyo
Okyo said:
I think there is no really good documentation or instruction manual for learning jme..many good examples..but no explanations...
Have you seen http://www.jmonkeyengine.com/wiki/doku.php yet?
I have a Problem! I use this code to import a 3ds file. And with the included 3ds.mesh "Bike" it does work!
But if I create my own object in 3ds (just a simple box without textures) and export it as 3ds mesh, it doesnt work! I have just exchanged the 3ds file and then it tells me:
ERROR CODE
20.08.2007 16:33:34 com.jme.app.BaseGame start
INFO: Application started.
20.08.2007 16:33:34 com.jme.system.PropertiesIO <init>
INFO: PropertiesIO created
20.08.2007 16:33:34 com.jme.system.PropertiesIO load
INFO: Read properties
20.08.2007 16:33:34 com.jme.app.BaseSimpleGame initSystem
INFO: jME version 1.0 alpha
20.08.2007 16:33:34 com.jme.input.joystick.DummyJoystickInput <init>
INFO: Joystick support is disabled
20.08.2007 16:33:34 com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
20.08.2007 16:33:35 com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W: 320H: 240
20.08.2007 16:33:35 com.jme.app.BaseSimpleGame initSystem
INFO: Running on: ati2dvag
Driver version: 6.14.10.6587
ATI Technologies Inc. - ATI Mobility Radeon X1600 x86/SSE2 - 2.0.5527 WinXP Release
20.08.2007 16:33:35 com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
20.08.2007 16:33:35 com.jme.util.lwjgl.LWJGLTimer <init>
INFO: Timer resolution: 1000 ticks per second
20.08.2007 16:33:35 com.jme.scene.Node <init>
INFO: Node created.
20.08.2007 16:33:35 com.jme.scene.Node <init>
INFO: Node created.
20.08.2007 16:33:35 com.jme.scene.Node attachChild
INFO: Child (FPS label) attached to this node (FPS node)
20.08.2007 16:33:35 class jmetest.TutorialGuide.HelloModelLoading start()
SCHWERWIEGEND: Exception in game loop
java.lang.NullPointerException
at jmetest.TutorialGuide.HelloModelLoading.simpleInitGame(HelloModelLoading.java:30)
at com.jme.app.BaseSimpleGame.initGame(BaseSimpleGame.java:503)
at com.jme.app.BaseGame.start(BaseGame.java:69)
at jmetest.TutorialGuide.HelloModelLoading.main(HelloModelLoading.java:20)
20.08.2007 16:33:35 com.jme.app.BaseSimpleGame cleanup
INFO: Cleaning up resources.
20.08.2007 16:33:35 com.jme.app.BaseGame start
INFO: Application ending.
LOADING 3Ds
package jmetest.TutorialGuide;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import com.jme.app.SimpleGame;
import com.jme.scene.Node;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.converters.MaxToJme;
public class HelloModelLoading extends SimpleGame
{
public static void main(String[] args)
{
HelloModelLoading app = new HelloModelLoading();
app.start();
}
protected void simpleInitGame()
{ URL url = HelloModelLoading.class.getClassLoader().getResource("jmetest/data/model/Bike.3ds");
MaxToJme maxtojme = new MaxToJme();
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
try
{
maxtojme.convert(url.openStream(), bytearrayoutputstream);
Node Bike = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(bytearrayoutputstream.toByteArray()));
rootNode.attachChild(Bike);
}
catch(IOException ioexception)
{
ioexception.printStackTrace();
System.exit(0);
}
}
}
Java is case sensitive… try bike.3ds, not Bike
No case sensitive, it works both! I have recognize that i cant use my own datas even textures doesnt work!?!?!
I have load an example and just changed the texture from "jmetest/data/texture/bottom.jpg" to "jmetest/data/texture/bottom2.jpg"
And ofcourse the texture is the same size/type/solution and in the same folder like bottom.jpg
But the bottom2 texture (my own texture ) is not shown …"missing texture" is shown on the box…its the same like the 3ds datas …i have downloaded a 3ds file from Internet…and tried it with this, but no chance…it doesnt work neither texture nor models…
Use the method's I gave you… They work for me.
SeySayux said:
Use the method's I gave you... They work for me.
hey thanks for your helper methods they are really usefull...
here's all of the imports for those of you who are lazy :
import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.TriMesh;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.XMLparser.Converters.FormatConverter;
import com.jmex.model.XMLparser.Converters.MaxToJme;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;