public class PolygonModifier
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static void |
applyTransform(Node node,
Matrix4 transform)
Apply transform matrix on control points of all geometries
|
static void |
buildTangentBinormal(Mesh mesh)
This will create tangent and binormal on the mesh
Normal is required, if normal is not existing on the mesh, it will also create the normal data from position.
|
static void |
buildTangentBinormal(Scene scene)
This will create tangent and binormal on all meshes of the scene
Normal is required, if normal is not existing on the mesh, it will also create the normal data from position.
|
static VertexElementNormal |
generateNormal(Mesh mesh)
Generate normal data from Mesh definition
|
static VertexElementUV |
generateUV(Mesh mesh)
Generate UV data from the given input mesh
|
static VertexElementUV |
generateUV(Mesh mesh,
VertexElementNormal normals)
Generate UV data from the given input mesh and specified normal data.
|
static Mesh |
mergeMesh(java.util.List<Node> nodes)
Convert a whole node to a single transformed mesh
Vertex elements like normal/texture coordinates are not supported yet
|
static Mesh |
mergeMesh(Node node)
Convert a whole node to a single transformed mesh
Vertex elements like normal/texture coordinates are not supported yet
|
static Mesh |
mergeMesh(Scene scene)
Convert a whole scene to a single transformed mesh
Vertex elements like normal/texture coordinates are not supported yet
|
static void |
scale(Node node,
Vector3 scale)
Scale all geometries(Scale the control points not the transformation matrix) in this node
|
static Scene |
scale(Scene scene,
Vector3 scale)
Scale all geometries(Scale the control points not the transformation matrix) in this scene
|
static Mesh[] |
splitMesh(Mesh mesh,
SplitMeshPolicy policy)
Split mesh into sub-meshes by
VertexElementMaterial. |
static void |
splitMesh(Node node,
SplitMeshPolicy policy)
Split mesh into sub-meshes by
VertexElementMaterial. |
static void |
splitMesh(Node node,
SplitMeshPolicy policy,
boolean createChildNodes)
Split mesh into sub-meshes by
VertexElementMaterial. |
static void |
splitMesh(Node node,
SplitMeshPolicy policy,
boolean createChildNodes,
boolean removeOldMesh)
Split mesh into sub-meshes by
VertexElementMaterial. |
static void |
splitMesh(Scene scene,
SplitMeshPolicy policy)
Split mesh into sub-meshes by
VertexElementMaterial. |
static void |
splitMesh(Scene scene,
SplitMeshPolicy policy,
boolean removeOldMesh)
Split mesh into sub-meshes by
VertexElementMaterial. |
static int[][] |
triangulate(java.util.List<Vector4> controlPoints)
Convert a polygon into triangles, the order of the polygon is defined by the
controlPoints |
static int[][] |
triangulate(java.util.List<Vector4> controlPoints,
int[] polygon)
Convert a polygon into triangles
|
static int[][] |
triangulate(java.util.List<Vector4> controlPoints,
java.util.List<int[]> polygons)
Convert a polygon-based mesh into triangles
|
static int[][] |
triangulate(java.util.List<Vector4> controlPoints,
java.util.List<int[]> polygons,
boolean generateNormals,
Vector3[][] nor_out)
Convert a polygon-based mesh into full triangle mesh
|
static Mesh |
triangulate(Mesh mesh)
Convert a polygon-based mesh into full triangle mesh
|
static void |
triangulate(Scene scene)
Convert all polygon-based meshes into full triangle mesh
|
public static void triangulate(Scene scene)
scene - The scene to process
Example:
The following code shows how to merge all objects from a scene into a single mesh.
var mesh = new Cylinder().toMesh();
//Triangulate this quadrangle-based mesh to triangle-based
mesh = PolygonModifier.triangulate(mesh);
var scene = new Scene(mesh);
scene.save("test.obj");
public static Mesh triangulate(Mesh mesh)
mesh - The original non-triangle mesh
var mesh = new Cylinder().toMesh();
//Triangulate this quadrangle-based mesh to triangle-based
mesh = PolygonModifier.triangulate(mesh);
var scene = new Scene(mesh);
scene.save("test.obj");
public static int[][] triangulate(java.util.List<Vector4> controlPoints, java.util.List<int[]> polygons, boolean generateNormals, Vector3[][] nor_out)
controlPoints - Control points of the meshpolygons - Polygon facesgenerateNormals - Generate normalsnor_out - Generated Per-control point normal
var mesh = new Cylinder().toMesh();
//Triangulate this quadrangle-based mesh to triangle-based
mesh = PolygonModifier.triangulate(mesh);
var scene = new Scene(mesh);
scene.save("test.obj");
public static int[][] triangulate(java.util.List<Vector4> controlPoints, java.util.List<int[]> polygons)
controlPoints - Control points of the meshpolygons - Polygon faces
var mesh = new Cylinder().toMesh();
//Triangulate this quadrangle-based mesh to triangle-based
mesh = PolygonModifier.triangulate(mesh);
var scene = new Scene(mesh);
scene.save("test.obj");
public static int[][] triangulate(java.util.List<Vector4> controlPoints, int[] polygon)
controlPoints - Control points of the meshpolygon - Polygon face
var mesh = new Cylinder().toMesh();
//Triangulate this quadrangle-based mesh to triangle-based
mesh = PolygonModifier.triangulate(mesh);
var scene = new Scene(mesh);
scene.save("test.obj");
public static int[][] triangulate(java.util.List<Vector4> controlPoints)
controlPointscontrolPoints - Control points of the mesh
var mesh = new Cylinder().toMesh();
//Triangulate this quadrangle-based mesh to triangle-based
mesh = PolygonModifier.triangulate(mesh);
var scene = new Scene(mesh);
scene.save("test.obj");
public static Mesh mergeMesh(Scene scene)
scene - The scene to merge
//Input file may contains multiple objects
var scene = Scene.fromFile("input.fbx");
//now merge them into a single mesh
Mesh merged = PolygonModifier.mergeMesh(scene);
//then we save it to a file with only one mesh
var newScene = new Scene(merged);
newScene.save("test.obj");
public static Mesh mergeMesh(java.util.List<Node> nodes)
nodes - The nodes to merge
//Input file may contains multiple objects
var scene = Scene.fromFile("input.fbx");
//now merge them into a single mesh
Mesh merged = PolygonModifier.mergeMesh(scene.getRootNode().getChildNodes());
//then we save it to a file with only one mesh
var newScene = new Scene(merged);
newScene.save("test.obj");
public static Mesh mergeMesh(Node node)
node - The node to merge
//Input file may contains multiple objects
var scene = Scene.fromFile("input.fbx");
//now merge them into a single mesh
Mesh merged = PolygonModifier.mergeMesh(scene.getRootNode());
//then we save it to a file with only one mesh
var newScene = new Scene(merged);
newScene.save("test.obj");
public static Scene scale(Scene scene, Vector3 scale)
scene - The scene to scalescale - The scale factor
Example:
The following code shows how to scale all geometries in scene by 10 times.
//Load a test file for scaling
var scene = Scene.fromFile("input.fbx");
//scale all geometries 10 times.
PolygonModifier.scale(scene, new Vector3(10, 10, 10));
scene.save("test.obj");
public static void scale(Node node, Vector3 scale)
node - The node to scalescale - The scale factor
Example:
The following code shows how to scale all geometries in scene by 10 times.
//Load a test file for scaling
var scene = Scene.fromFile("input.fbx");
//scale all geometries 10 times.
PolygonModifier.scale(scene.getRootNode(), new Vector3(10, 10, 10));
scene.save("test.obj");
public static void applyTransform(Node node, Matrix4 transform)
node - Which node's geometries will be applied with given transformtransform - The transformation matrix that will be applied to control points.public static VertexElementNormal generateNormal(Mesh mesh)
VertexElementNormal instance with normal data.public static VertexElementUV generateUV(Mesh mesh, VertexElementNormal normals)
mesh - The input meshnormals - The normal datapublic static VertexElementUV generateUV(Mesh mesh)
mesh - The input meshpublic static void splitMesh(Node node, SplitMeshPolicy policy, boolean createChildNodes, boolean removeOldMesh)
VertexElementMaterial.
Each sub-mesh will use only one material.
Perform mesh splitting on a nodecreateChildNodes - Create child nodes for each sub-mesh.removeOldMesh - Remove the old mesh after split, if this parameter is false, the old and new meshes will co-exists.
Example:
The following code shows how to split a box into sub meshes using material indices.
// Create a mesh of box(A box is composed by 6 planes)
Mesh box = (new Box()).toMesh();
// Create a material element on this mesh
VertexElementMaterial mat = (VertexElementMaterial)box.createElement(VertexElementType.MATERIAL, MappingMode.POLYGON, ReferenceMode.INDEX);
// And specify different material index for each plane
mat.setIndices(new int[] { 0, 1, 2, 3, 4, 5 });
// Now split it into 6 sub meshes, we specified 6 different materials on each plane, each plane will become a sub mesh.
// We used the CloneData policy, each plane will has the same control point information or control point-based vertex element information.
Mesh[] planes = PolygonModifier.splitMesh(box, SplitMeshPolicy.CLONE_DATA);
// Now split it into 2 sub meshes, first mesh will contains 0/1/2 planes, and second mesh will contains the 3/4/5th planes.
mat.setIndices(new int[] { 0, 0, 0, 1, 1, 1 });
// We used the CompactData policy, each plane will has its own control point information or control point-based vertex element information.
planes = PolygonModifier.splitMesh(box, SplitMeshPolicy.COMPACT_DATA);
public static void splitMesh(Node node, SplitMeshPolicy policy)
VertexElementMaterial.
Each sub-mesh will use only one material.
Perform mesh splitting on a node
Example:
The following code shows how to split a box into sub meshes using material indices.
// Create a mesh of box(A box is composed by 6 planes)
Mesh box = (new Box()).toMesh();
// Create a material element on this mesh
VertexElementMaterial mat = (VertexElementMaterial)box.createElement(VertexElementType.MATERIAL, MappingMode.POLYGON, ReferenceMode.INDEX);
// And specify different material index for each plane
mat.setIndices(new int[] { 0, 1, 2, 3, 4, 5 });
// Now split it into 6 sub meshes, we specified 6 different materials on each plane, each plane will become a sub mesh.
// We used the CloneData policy, each plane will has the same control point information or control point-based vertex element information.
Mesh[] planes = PolygonModifier.splitMesh(box, SplitMeshPolicy.CLONE_DATA);
// Now split it into 2 sub meshes, first mesh will contains 0/1/2 planes, and second mesh will contains the 3/4/5th planes.
mat.setIndices(new int[] { 0, 0, 0, 1, 1, 1 });
// We used the CompactData policy, each plane will has its own control point information or control point-based vertex element information.
planes = PolygonModifier.splitMesh(box, SplitMeshPolicy.COMPACT_DATA);
public static void splitMesh(Node node, SplitMeshPolicy policy, boolean createChildNodes)
VertexElementMaterial.
Each sub-mesh will use only one material.
Perform mesh splitting on a nodecreateChildNodes - Create child nodes for each sub-mesh.
Example:
The following code shows how to split a box into sub meshes using material indices.
// Create a mesh of box(A box is composed by 6 planes)
Mesh box = (new Box()).toMesh();
// Create a material element on this mesh
VertexElementMaterial mat = (VertexElementMaterial)box.createElement(VertexElementType.MATERIAL, MappingMode.POLYGON, ReferenceMode.INDEX);
// And specify different material index for each plane
mat.setIndices(new int[] { 0, 1, 2, 3, 4, 5 });
// Now split it into 6 sub meshes, we specified 6 different materials on each plane, each plane will become a sub mesh.
// We used the CloneData policy, each plane will has the same control point information or control point-based vertex element information.
Mesh[] planes = PolygonModifier.splitMesh(box, SplitMeshPolicy.CLONE_DATA);
// Now split it into 2 sub meshes, first mesh will contains 0/1/2 planes, and second mesh will contains the 3/4/5th planes.
mat.setIndices(new int[] { 0, 0, 0, 1, 1, 1 });
// We used the CompactData policy, each plane will has its own control point information or control point-based vertex element information.
planes = PolygonModifier.splitMesh(box, SplitMeshPolicy.COMPACT_DATA);
public static void splitMesh(Scene scene, SplitMeshPolicy policy, boolean removeOldMesh)
VertexElementMaterial.
Each sub-mesh will use only one material.
Perform mesh splitting on all nodes of the scene.
Example:
The following code shows how to split a box into sub meshes using material indices.
// Create a mesh of box(A box is composed by 6 planes)
Mesh box = (new Box()).toMesh();
// Create a material element on this mesh
VertexElementMaterial mat = (VertexElementMaterial)box.createElement(VertexElementType.MATERIAL, MappingMode.POLYGON, ReferenceMode.INDEX);
// And specify different material index for each plane
mat.setIndices(new int[] { 0, 1, 2, 3, 4, 5 });
// Now split it into 6 sub meshes, we specified 6 different materials on each plane, each plane will become a sub mesh.
// We used the CloneData policy, each plane will has the same control point information or control point-based vertex element information.
Mesh[] planes = PolygonModifier.splitMesh(box, SplitMeshPolicy.CLONE_DATA);
// Now split it into 2 sub meshes, first mesh will contains 0/1/2 planes, and second mesh will contains the 3/4/5th planes.
mat.setIndices(new int[] { 0, 0, 0, 1, 1, 1 });
// We used the CompactData policy, each plane will has its own control point information or control point-based vertex element information.
planes = PolygonModifier.splitMesh(box, SplitMeshPolicy.COMPACT_DATA);
public static void splitMesh(Scene scene, SplitMeshPolicy policy)
VertexElementMaterial.
Each sub-mesh will use only one material.
Perform mesh splitting on all nodes of the scene.
Example:
The following code shows how to split a box into sub meshes using material indices.
// Create a mesh of box(A box is composed by 6 planes)
Mesh box = (new Box()).toMesh();
// Create a material element on this mesh
VertexElementMaterial mat = (VertexElementMaterial)box.createElement(VertexElementType.MATERIAL, MappingMode.POLYGON, ReferenceMode.INDEX);
// And specify different material index for each plane
mat.setIndices(new int[] { 0, 1, 2, 3, 4, 5 });
// Now split it into 6 sub meshes, we specified 6 different materials on each plane, each plane will become a sub mesh.
// We used the CloneData policy, each plane will has the same control point information or control point-based vertex element information.
Mesh[] planes = PolygonModifier.splitMesh(box, SplitMeshPolicy.CLONE_DATA);
// Now split it into 2 sub meshes, first mesh will contains 0/1/2 planes, and second mesh will contains the 3/4/5th planes.
mat.setIndices(new int[] { 0, 0, 0, 1, 1, 1 });
// We used the CompactData policy, each plane will has its own control point information or control point-based vertex element information.
planes = PolygonModifier.splitMesh(box, SplitMeshPolicy.COMPACT_DATA);
public static Mesh[] splitMesh(Mesh mesh, SplitMeshPolicy policy)
VertexElementMaterial.
Each sub-mesh will use only one material.
The original mesh will not get changed.
// Create a mesh of box(A box is composed by 6 planes)
Mesh box = (new Box()).toMesh();
// Create a material element on this mesh
VertexElementMaterial mat = (VertexElementMaterial)box.createElement(VertexElementType.MATERIAL, MappingMode.POLYGON, ReferenceMode.INDEX);
// And specify different material index for each plane
mat.setIndices(new int[] { 0, 1, 2, 3, 4, 5 });
// Now split it into 6 sub meshes, we specified 6 different materials on each plane, each plane will become a sub mesh.
// We used the CloneData policy, each plane will has the same control point information or control point-based vertex element information.
Mesh[] planes = PolygonModifier.splitMesh(box, SplitMeshPolicy.CLONE_DATA);
// Now split it into 2 sub meshes, first mesh will contains 0/1/2 planes, and second mesh will contains the 3/4/5th planes.
mat.setIndices(new int[] { 0, 0, 0, 1, 1, 1 });
// We used the CompactData policy, each plane will has its own control point information or control point-based vertex element information.
planes = PolygonModifier.splitMesh(box, SplitMeshPolicy.COMPACT_DATA);
public static void buildTangentBinormal(Scene scene)
public static void buildTangentBinormal(Mesh mesh)