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;
}
}