hi,
I got a code here on the site of loading textures with models, but a message appears saying "Unable to locate url". But this url is correct!
loading the model is working correctly, only the textures that are not loaded …
I'll post my code and q error message:
static Spatial criaModelo (String urlModelo, String textura[])
{
Texture texturas[] = criaTextura (textura);
for (int i=0; i<texturas.length;i++)
{
if (texturas[i] != null)
{
//JOptionPane.showMessageDialog(null,i,"file binary", JOptionPane.INFORMATION_MESSAGE);
File textures = new File( texturas[i].getImageLocation() );
SimpleResourceLocator location=null;
try {
try {
location = new SimpleResourceLocator(textures.toURI().toURL());
} catch (MalformedURLException ex) {
Logger.getLogger(ModeloBinario.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (URISyntaxException ex) {
Logger.getLogger(ModeloBinario.class.getName()).log(Level.SEVERE, null, ex);
}
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, location );
}
}
FormatConverter CONVERTER = null;
String modelFormat = urlModelo.substring(urlModelo.lastIndexOf(".") + 1, urlModelo.length());
if (modelFormat.equalsIgnoreCase("3ds"))
CONVERTER = new MaxToJme();
else
{
if (modelFormat.equalsIgnoreCase("obj"))
CONVERTER = new ObjToJme();
else
{
if (modelFormat.equalsIgnoreCase("x3d"))
{
try
{
CONVERTER = new X3dToJme();
}
catch (Exception ex)
{
Logger.getLogger(ModeloBinario.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
Spatial Modelo=null;
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
FileInputStream rawIn = null;
//JOptionPane.showMessageDialog(null,"-1!","file binary", JOptionPane.INFORMATION_MESSAGE);
try {
rawIn = new FileInputStream(urlModelo);
} catch (FileNotFoundException ex) {
Logger.getLogger(ModeloBinario.class.getName()).log(Level.SEVERE, null, ex);
}
try {
//JOptionPane.showMessageDialog(null,"0!","file binary", JOptionPane.INFORMATION_MESSAGE);
CONVERTER.convert(rawIn, outStream);
//JOptionPane.showMessageDialog(null,"passou!","file binary", JOptionPane.INFORMATION_MESSAGE);
} catch (IOException ex) {
Logger.getLogger(ModeloBinario.class.getName()).log(Level.SEVERE, null, ex);
}
try {
rawIn.close();
} catch (IOException ex) {
Logger.getLogger(ModeloBinario.class.getName()).log(Level.SEVERE, null, ex);
}
ByteArrayInputStream convertedIn = new ByteArrayInputStream(outStream.toByteArray());
try {
Modelo = (Spatial) BinaryImporter.getInstance().load(convertedIn);
} catch (IOException ex) {
Logger.getLogger(ModeloBinario.class.getName()).log(Level.SEVERE, null, ex);
}
Modelo.setModelBound(new BoundingSphere());
Modelo.updateWorldBound();
Modelo.updateModelBound();
Modelo.updateRenderState();
Modelo.updateGeometricState( 0, true );
//JOptionPane.showMessageDialog(null,"1","file binary", JOptionPane.INFORMATION_MESSAGE);
export(Modelo,urlModelo);
// JOptionPane.showMessageDialog(null,"2!","file binary", JOptionPane.INFORMATION_MESSAGE);
return Modelo;
}
static Texture textura (String url)
{
Texture textura = TextureManager.loadTexture(url,
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
return textura;
}
static Texture[] criaTextura (String urlTexturas[])
{
Texture texturas[] = new Texture [urlTexturas.length];
for (int i=0;i<urlTexturas.length;i++)
if (urlTexturas[i] != null)
texturas[i] = textura(urlTexturas[i]);
else
break;
return texturas;
}
error message:
08/05/2010 21:48:26 com.jme.input.joystick.DummyJoystickInput <init>
INFO: Joystick support is disabled
08/05/2010 21:48:26 com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
08/05/2010 21:48:28 com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W: 800 H: 700 Version: 2.1.0
08/05/2010 21:48:28 com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
08/05/2010 21:48:28 com.jme.scene.Node <init>
INFO: Node created.
08/05/2010 21:48:28 com.jme.scene.Node <init>
INFO: Node created.
08/05/2010 21:49:51 com.jme.util.resource.ResourceLocatorTool locateResource
WARNING: Unable to locate: D:Meus documentosNetBeansProjectsVisao3DbuildclassesModelossalasof