We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Texture not visible

Hello,

I was trying to add a texture to a .fbx file and save the fbx file again. However, when I open the file, no textures are visible. When I debug, I do see that all the nodes do contain materials…

Here is my code:

private void ApplyTexture() throws IOException {
    Scene scene = new Scene();
    scene.open("pathTo\\output.fbx");
    PolygonModifier.triangulate(scene);
    PhongMaterial mat = new PhongMaterial();
    mat.setName("Wood");
    Texture diffuse = new Texture();
    mat.setTexture(Material.MAP_SPECULAR, diffuse);
    diffuse.setFileName("pathTo\\wood.jpg");
    diffuse.setContent(Files.readAllBytes(Paths.get("pathTo\\wood.jpg")));
    mat.setSpecularColor(new Vector3(1, 0, 0));
    mat.setShininess(100);
    Node n = scene.getRootNode();
    if(n.getChildNodes() != null){
        for (Node child : n.getChildNodes()){
            child.setMaterial(mat);
        }
    }
    scene.getRootNode().setMaterial(mat);
    scene.save("outputWithTexture.fbx");
}

Help is highly appreciated :smiley:

@Hue404

Would you please also share the sample source FBX file so that we can further proceed to assist you accordingly.

Here is the fbx file and the texture file:

fbxFile.zip (5.6 MB)

@Hue404

An investigation ticket as THREEDNET-1217 has been logged in our issue tracking system for the sake of further analysis. We will look into its details and let you know once it is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

@Hue404

The problems we have found:

  1. This code maps the wood.jpg to specular, which should be Material.MAP_DIFFUSE.
  2. The model does not have a texture coordinate, so it’s unable for a renderer to render it with texture.

Solution for issue 1:

Use Material.MAP_DIFFUSE to replace Material.MAP_SPECULAR

Solution for issue 2:

Use tools like 3ds max, blender to unwrap texture coordinate, Aspose.3D provided a utility method to generate UV, it’s mainly used for testing purpose, the result may not be promising:

BTW the 22.9 (which will be releasing soon) for Java fixed a bug that exported Node does not show mesh sometimes.

private void ApplyTexture() throws IOException {
    Scene scene = new Scene();
    scene.open("pathTo\\output.fbx");
    PolygonModifier.triangulate(scene);

    //CREATE UV
    Mesh mesh = (Mesh) scene.getRootNode().getChild(0).getEntity();
    VertexElementUV uv = PolygonModifier.generateUV(mesh);
    mesh.addElement(uv);
    ////

    PhongMaterial mat = new PhongMaterial();
    mat.setName("Wood");
    Texture diffuse = new Texture();
    mat.setTexture(Material.MAP_DIFFUSE, diffuse);
    diffuse.setFileName("pathTo\\wood.jpg");
    diffuse.setContent(Files.readAllBytes(Paths.get("pathTo\\wood.jpg")));
    mat.setSpecularColor(new Vector3(1, 0, 0));
    mat.setShininess(100);
    Node n = scene.getRootNode();
    if(n.getChildNodes() != null){
        for (Node child : n.getChildNodes()){
            child.setMaterial(mat);
        }
    }
    scene.getRootNode().setMaterial(mat);
    scene.save("outputWithTexture.fbx");
}
1 Like

thanks a lot, this really helped me out :smiley:

1 Like