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

Free Support Forum - aspose.com

Exception when saving scene as FBX file

Hello,

I am trying to create a box with a hole in it. For that I create a cube (got the code from the documentation) with another cube in the corner.
I am adding the hole like this:

public static void createHole(Mesh mesh){

    mesh.getControlPoints().addAll(defineControlPointsForHole());
    createPolygons(mesh);
    Boolean[] holes = new Boolean[]
            {
                    false, false, false, false, false, false,
                    true, true, true, true, true, true
            };


    VertexElementHole hole = new VertexElementHole();
    hole.setData(holes);
    mesh.addElement(hole);
}

where the createPolygons(Mesh mesh) and the defineControlPointsForHole() are the same as the methods createPolygons(Mesh mesh) and defineControlPoints() from the documentation.

When trying to save it, I get the following exception: com.aspose.threed.ExportException: Index 0 out of bounds for length 0

If I don’t call the hole creation method, everything works fine.

Can someone please tell me what I am doing wrong?

This is the whole class:

package **;

import com.aspose.threed.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class HoleCreation {

    public static void createHole() throws IOException {
        Mesh mesh = createMeshUsingCreatePolygons();
        Scene scene = new Scene();

        // Initialize Node class object
        Node cubeNode = new Node("box");


        // Point node to the Mesh geometry
        createHole(mesh);
        cubeNode.setEntity(mesh);

        // Add Node to a scene
        scene.getRootNode().addChildNode(cubeNode);
        scene.save("C:\\Users\\Niki\\Documents\\holes.fbx", FileFormat.FBX7700_BINARY);
    }


    public static void createHole(Mesh mesh){

        mesh.getControlPoints().addAll(defineControlPointsForHole());
        createPolygons(mesh);
        Boolean[] holes = new Boolean[]
                {
                        false, false, false, false, false, false,
                        true, true, true, true, true, true
                };

        VertexElementHole hole = new VertexElementHole();
        hole.setData(holes);
        mesh.addElement(hole);
    }


    private static void createPolygons(Mesh mesh) {
        // Create polygons to mesh
        // Front face (Z+)
        int i = 8;
        mesh.createPolygon(new int[] {i, i+1, i+2, i+3 });
        // Right side (X+)
        mesh.createPolygon(new int[] { i+1, i+5, i+6, i+2 });
        // Back face (Z-)
        mesh.createPolygon(new int[] { i+5, i+4, i+7, i+6 });
        // Left side (X-)
        mesh.createPolygon(new int[] { i+4, i, i+3, i+7 });
        // Bottom face (Y-)
        mesh.createPolygon(new int[] { i, i+4, i+5, i+1 });
        // Top face (Y+)
        mesh.createPolygon(new int[] { i+3, i+2, i+6, i+7 });
    }


    public static List<Vector4> defineControlPointsForHole(){
        // ExStart:DefineControlPoints
        // Initialize control points
        List<Vector4> controlPoints = new ArrayList<Vector4>();

        //Vector4List controlPoints = new Vector4List(8);
        controlPoints.add(new Vector4( -2.5, 0.0, 5.0, 1.0));
        controlPoints.add(new Vector4( 2.5, 0.0, 5.0, 1.0));
        controlPoints.add(new Vector4( 2.5, 5, 5.0, 1.0));
        controlPoints.add(new Vector4( -2.5, 5, 5.0, 1.0));
        controlPoints.add(new Vector4( -2.5, 0.0, -5.0, 1.0));
        controlPoints.add(new Vector4( 2.5, 0.0, -5.0, 1.0));
        controlPoints.add(new Vector4( 2.5, 5, -5.0, 1.0));
        controlPoints.add(new Vector4( -2.5, 5, -5.0, 1.0));
        // ExEnd:DefineControlPoints
        return controlPoints;
    }


    private static List<Vector4> defineControlPoints()
    {
        // ExStart:DefineControlPoints
        // Initialize control points
        List<Vector4> controlPoints = new ArrayList<Vector4>();

        //Vector4List controlPoints = new Vector4List(8);
        controlPoints.add(new Vector4( -5.0, 0.0, 5.0, 1.0));
        controlPoints.add(new Vector4( 5.0, 0.0, 5.0, 1.0));
        controlPoints.add(new Vector4( 5.0, 10.0, 5.0, 1.0));
        controlPoints.add(new Vector4( -5.0, 10.0, 5.0, 1.0));
        controlPoints.add(new Vector4( -5.0, 0.0, -5.0, 1.0));
        controlPoints.add(new Vector4( 5.0, 0.0, -5.0, 1.0));
        controlPoints.add(new Vector4( 5.0, 10.0, -5.0, 1.0));
        controlPoints.add(new Vector4( -5.0, 10.0, -5.0, 1.0));
        // ExEnd:DefineControlPoints
        return controlPoints;
    }
    public static Mesh createMeshUsingPolygonBuilder()
    {
        // ExStart:CreateMeshUsingPolygonBuilder
        List<Vector4> controlPoints = defineControlPoints();

        // Initialize mesh object
        Mesh mesh = new Mesh();

        // Add control points to the mesh
        mesh.getControlPoints().addAll(controlPoints);

        // Indices of the vertices per each polygon
        int[] indices = new int[]
                {
                        0,1,2,3, // Front face (Z+)
                        1,5,6,2, // Right side (X+)
                        5,4,7,6, // Back face (Z-)
                        4,0,3,7, // Left side (X-)
                        0,4,5,1, // Bottom face (Y-)
                        3,2,6,7 // Top face (Y+)
                };

        int vertexId = 0;
        PolygonBuilder builder = new PolygonBuilder(mesh);
        for (int face = 0; face < 6; face++)
        {
            // Start defining a new polygon
            builder.begin();
            for (int v = 0; v < 4; v++)
                // The indice of vertice per each polygon
                builder.addVertex(indices[vertexId++]);
            // Finished one polygon
            builder.end();
        }

        // ExEnd:CreateMeshUsingPolygonBuilder
        return mesh;
    }
    public static Mesh createMeshUsingCreatePolygons()
    {
        // ExStart:CreateMeshUsingCreatePolygons
        List<Vector4> controlPoints = defineControlPoints();

        // Initialize mesh object
        Mesh mesh = new Mesh();
        // Add control points to the mesh
        mesh.getControlPoints().addAll(controlPoints);
        // Create polygons to mesh
        // Front face (Z+)
        mesh.createPolygon(new int[] { 0, 1, 2, 3 });
        // Right side (X+)
        mesh.createPolygon(new int[] { 1, 5, 6, 2 });
        // Back face (Z-)
        mesh.createPolygon(new int[] { 5, 4, 7, 6 });
        // Left side (X-)
        mesh.createPolygon(new int[] { 4, 0, 3, 7 });
        // Bottom face (Y-)
        mesh.createPolygon(new int[] { 0, 4, 5, 1 });
        // Top face (Y+)
        mesh.createPolygon(new int[] { 3, 2, 6, 7 });
        // ExEnd:CreateMeshUsingCreatePolygons
        return mesh;
    }
}

@Hue404

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): THREEDJAVA-254

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hello, is there any news yet?

@Hue404

We are afraid that the ticket has not been yet resolved. We will surely inform you once we have some update in this regard. Please spare us some time.

We are sorry for the inconvenience.