TriMesh

Inheritance: java.lang.Object, com.aspose.threed.A3DObject, com.aspose.threed.SceneObject, com.aspose.threed.Entity

All Implemented Interfaces: java.lang.Iterable

public class TriMesh extends Entity implements Iterable<Vertex>

A TriMesh contains raw data that can be used by GPU directly. This class is a utility to help to construct a mesh that only contains per-vertex data.

Constructors

ConstructorDescription
TriMesh(String name, VertexDeclaration declaration)Initialize an instance of TriMesh

Methods

MethodDescription
addTriangle(int a, int b, int c)Add a new triangle
beginVertex()Begin adding vertex
copyFrom(TriMesh input, VertexDeclaration vd)Copy the TriMesh from input with new vertex layout
endVertex()End adding vertex
equals(Object arg0)
findProperty(String propertyName)Finds the property.
fromMesh(Mesh mesh)Create a TriMesh from given mesh object, the vertex declaration are based on the input mesh’s structure.
fromMesh(Mesh mesh, boolean useFloat)Create a TriMesh from given mesh object, the vertex declaration are based on the input mesh’s structure.
fromMesh(VertexDeclaration declaration, Mesh mesh)Create a TriMesh from given mesh object with given vertex layout.
fromRawData(VertexDeclaration vd, byte[] vertices, int[] indices, boolean generateVertexMapping)Create TriMesh from raw data
getBoundingBox()Gets the bounding box of current entity in its object space coordinate system.
getCapacity()The capacity of pre-allocated vertices.
getClass()
getEntityRendererKey()Gets the key of the entity renderer registered in the renderer
getExcluded()Gets whether to exclude this entity during exporting.
getIndicesCount()The count of indices in this TriMesh
getIntIndices()Convert the indices to 32bit integer array
getName()Gets the name.
getParentNode()Gets the first parent node, if set the first parent node, this entity will be detached from other parent nodes.
getParentNodes()Gets all parent nodes, an entity can be attached to multiple parent nodes for geometry instancing
getProperties()Gets the collection of all properties.
getProperty(String property)Get the value of specified property
getScene()Gets the scene that this object belongs to
getShortIndices()Convert the indices to 16bit integer array
getUnmergedVerticesCount()The count of unmerged vertices that passed in by beginVertex and endVertex.
getVertexDeclaration()The vertex layout of the TriMesh.
getVerticesCount()The count of vertices in this TriMesh
getVerticesSizeInBytes()The total size of all vertices in bytes
hashCode()
indicesToArray(int[][] result)Convert the indices to 32bit integer array
indicesToArray(short[][] result)Convert the indices to 16bit integer array
iterator()Get the enumerator to enumerate Vertex
loadVerticesFromBytes(byte[] verticesInBytes)Load vertices from bytes, the length of bytes must be an integer multiple of vertex size.
notify()
notifyAll()
readDouble(int idx, VertexField field)Read the double field
readFVector2(int idx, VertexField field)Read the vector2 field
readFVector3(int idx, VertexField field)Read the vector3 field
readFVector4(int idx, VertexField field)Read the vector4 field
readFloat(int idx, VertexField field)Read the float field
readVector2(int idx, VertexField field)Read the vector2 field
readVector3(int idx, VertexField field)Read the vector3 field
readVector4(int idx, VertexField field)Read the vector4 field
removeProperty(Property property)Removes a dynamic property.
removeProperty(String property)Remove the specified property identified by name
setExcluded(boolean value)Sets whether to exclude this entity during exporting.
setName(String value)Sets the name.
setParentNode(Node value)Sets the first parent node, if set the first parent node, this entity will be detached from other parent nodes.
setProperty(String property, Object value)Sets the value of specified property
toString()Gets the string representation of TriMesh
verticesToArray()Convert the vertices data to byte array
wait()
wait(long arg0)
wait(long arg0, int arg1)
write16bIndicesTo(Stream stream)Write the indices data as 16bit integer to the stream
write16bIndicesTo(OutputStream stream)Write the indices data as 16bit integer to the stream
write32bIndicesTo(Stream stream)Write the indices data as 32bit integer to the stream
write32bIndicesTo(OutputStream stream)Write the indices data as 32bit integer to the stream
writeVerticesTo(Stream stream)Write vertices data to the specified stream
writeVerticesTo(OutputStream stream)Write vertices data to the specified stream

TriMesh(String name, VertexDeclaration declaration)

public TriMesh(String name, VertexDeclaration declaration)

Initialize an instance of TriMesh

Parameters:

ParameterTypeDescription
namejava.lang.StringThe name of this TriMesh
declarationVertexDeclarationThe vertex’s declaration

addTriangle(int a, int b, int c)

public void addTriangle(int a, int b, int c)

Add a new triangle

Parameters:

ParameterTypeDescription
aintThe index of first vertex
bintThe index of second vertex
cintThe index of third vertex

beginVertex()

public Vertex beginVertex()

Begin adding vertex

Returns: Vertex - The reference of internal vertex object in type Vertex

copyFrom(TriMesh input, VertexDeclaration vd)

public static TriMesh copyFrom(TriMesh input, VertexDeclaration vd)

Copy the TriMesh from input with new vertex layout

Parameters:

ParameterTypeDescription
inputTriMeshThe input TriMesh for copying
vdVertexDeclarationThe new vertex declaration of the output TriMesh

Returns: TriMesh - A new TriMesh instance with new vertex declaration. Example:

//Define a vertex declaration as {FVector3 Position; FVector3 Normal; FVector2 UV}
  VertexDeclaration vd = new VertexDeclaration();
  vd.addField(VertexFieldDataType.F_VECTOR3, VertexFieldSemantic.POSITION);
  vd.addField(VertexFieldDataType.F_VECTOR3, VertexFieldSemantic.NORMAL);
  vd.addField(VertexFieldDataType.F_VECTOR2, VertexFieldSemantic.UV);
  //convert a mesh to TriMesh, the layout is automatically inferred from input mesh
  var oldTriMesh = TriMesh.fromMesh((new Sphere()).toMesh());
  //now create a new TriMesh from old TriMesh, using explicit memory layout defined by vd
  var newTriMesh = TriMesh.copyFrom(oldTriMesh, vd);

endVertex()

public void endVertex()

End adding vertex

equals(Object arg0)

public boolean equals(Object arg0)

Parameters:

ParameterTypeDescription
arg0java.lang.Object

Returns: boolean

findProperty(String propertyName)

public Property findProperty(String propertyName)

Finds the property. It can be a dynamic property (Created by CreateDynamicProperty/SetProperty) or native property(Identified by its name)

Parameters:

ParameterTypeDescription
propertyNamejava.lang.StringProperty name.

Returns: Property - The property.

fromMesh(Mesh mesh)

public static TriMesh fromMesh(Mesh mesh)

Create a TriMesh from given mesh object, the vertex declaration are based on the input mesh’s structure.

Parameters:

ParameterTypeDescription
meshMesh

Returns: TriMesh - The TriMesh generated from given Mesh Example:

//convert a mesh to TriMesh, the layout is automatically inferred from input mesh
      var mesh = (new Sphere()).toMesh();
      var triMesh = TriMesh.fromMesh(mesh);
      //save it to a stream, 115 vertices * 32bytes per vertex
      var stream = new ByteArrayOutputStream();
      try(var s = Stream.wrap(stream)) {
          triMesh.writeVerticesTo(s);
          //save indices as ushort to stream, 504 indices * 2 bytes per index
          triMesh.write16bIndicesTo(s);
      }

fromMesh(Mesh mesh, boolean useFloat)

public static TriMesh fromMesh(Mesh mesh, boolean useFloat)

Create a TriMesh from given mesh object, the vertex declaration are based on the input mesh’s structure.

Parameters:

ParameterTypeDescription
meshMesh
useFloatbooleanUse float type instead of double type for each vertex element component.

Returns: TriMesh - The TriMesh generated from given Mesh Example:

//convert a mesh to TriMesh, the layout is automatically inferred from input mesh
      var mesh = (new Sphere()).toMesh();
      var triMesh = TriMesh.fromMesh(mesh);
      //save it to a stream, 115 vertices * 32bytes per vertex
      var stream = new ByteArrayOutputStream();
      try(var s = Stream.wrap(stream)) {
          triMesh.writeVerticesTo(s);
          //save indices as ushort to stream, 504 indices * 2 bytes per index
          triMesh.write16bIndicesTo(s);
      }

fromMesh(VertexDeclaration declaration, Mesh mesh)

public static TriMesh fromMesh(VertexDeclaration declaration, Mesh mesh)

Create a TriMesh from given mesh object with given vertex layout.

Parameters:

ParameterTypeDescription
declarationVertexDeclarationVertex’s type definition, or memory layout
meshMeshSource mesh

Returns: TriMesh - Instance of TriMesh converted from input mesh with specified vertex’s memory layout Example:

//Define a vertex declaration as {FVector3 Position; FVector3 Normal; FVector2 UV}
      VertexDeclaration vd = new VertexDeclaration();
      vd.addField(VertexFieldDataType.F_VECTOR3, VertexFieldSemantic.POSITION);
      vd.addField(VertexFieldDataType.F_VECTOR3, VertexFieldSemantic.NORMAL);
      vd.addField(VertexFieldDataType.F_VECTOR2, VertexFieldSemantic.UV);
      //convert a mesh to tri-mesh using specified memory layout
      var mesh = (new Sphere()).toMesh();
      var triMesh = TriMesh.fromMesh(vd, mesh);
      //save it to a stream, 115 vertices * 32bytes per vertex
      var stream = new ByteArrayOutputStream();
      try(var s = Stream.wrap(stream)) {
          triMesh.writeVerticesTo(s);
          //save indices as ushort to stream, 504 indices * 2 bytes per index
          triMesh.write16bIndicesTo(s);
      }

fromRawData(VertexDeclaration vd, byte[] vertices, int[] indices, boolean generateVertexMapping)

public static TriMesh fromRawData(VertexDeclaration vd, byte[] vertices, int[] indices, boolean generateVertexMapping)

Create TriMesh from raw data

Parameters:

ParameterTypeDescription
vdVertexDeclarationVertex declaration, must contains at least one field.
verticesbyte[]The input vertex data, the minimum length of the vertices must be greater or equal to vertex declaration’s size
indicesint[]The triangle indices
generateVertexMappingbooleanGenerate Vertex for each vertex, which is not necessary for just serialization/deserialization.

Returns: TriMesh - The TriMesh instance that encapsulated the input byte array. Remarks: The returned TriMesh will not copy the input byte array for performance, external changes on the array will be reflected to this instance. Example: The following code shows how to construct a TriMesh from raw bytes, this is useful when build your own 3D format

var indices = new int[] { 0,  1,  2 };
  var vertices = new byte[]{
      0, 0, 0, 191,
      0, 0, 0, 0,
      0, 0, 0, 191,
      0, 0, 0, 191,
      0, 0, 0, 0,
      0, 0, 0, 63,
      0, 0, 0, 63,
      0, 0, 0, 0,
      0, 0, 0, 63
  };
  VertexDeclaration vd = new VertexDeclaration();
  vd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Position);
  var triMesh = TriMesh.FromRawData(vd, vertices, indices, true);

getBoundingBox()

public BoundingBox getBoundingBox()

Gets the bounding box of current entity in its object space coordinate system. Example: The following code shows how to calculate the bounding box of a shape

Entity entity = new Sphere();
     entity.setRadius(10);
     var bbox = entity.getBoundingBox();
     System.out.printf("The bounding box of the entity is %s ~ %s", bbox.getMinimum(), bbox.getMaximum());

Returns: BoundingBox

getCapacity()

public int getCapacity()

The capacity of pre-allocated vertices.

Returns: int

getClass()

public final native Class<?> getClass()

Returns: java.lang.Class

getEntityRendererKey()

public EntityRendererKey getEntityRendererKey()

Gets the key of the entity renderer registered in the renderer

Returns: EntityRendererKey

getExcluded()

public boolean getExcluded()

Gets whether to exclude this entity during exporting.

Returns: boolean

getIndicesCount()

public int getIndicesCount()

The count of indices in this TriMesh

Returns: int

getIntIndices()

public int[] getIntIndices()

Convert the indices to 32bit integer array

Returns: int[]

getName()

public String getName()

Gets the name.

Returns: java.lang.String

getParentNode()

public Node getParentNode()

Gets the first parent node, if set the first parent node, this entity will be detached from other parent nodes.

Returns: Node

getParentNodes()

public ArrayList<Node> getParentNodes()

Gets all parent nodes, an entity can be attached to multiple parent nodes for geometry instancing

Returns: java.util.ArrayList<com.aspose.threed.Node>

getProperties()

public PropertyCollection getProperties()

Gets the collection of all properties.

Returns: PropertyCollection

getProperty(String property)

public Object getProperty(String property)

Get the value of specified property

Parameters:

ParameterTypeDescription
propertyjava.lang.StringProperty name

Returns: java.lang.Object - The value of the found property

getScene()

public Scene getScene()

Gets the scene that this object belongs to

Returns: Scene

getShortIndices()

public short[] getShortIndices()

Convert the indices to 16bit integer array

Returns: short[]

getUnmergedVerticesCount()

public int getUnmergedVerticesCount()

The count of unmerged vertices that passed in by beginVertex and endVertex.

Returns: int

getVertexDeclaration()

public VertexDeclaration getVertexDeclaration()

The vertex layout of the TriMesh.

Returns: VertexDeclaration

getVerticesCount()

public int getVerticesCount()

The count of vertices in this TriMesh

Returns: int

getVerticesSizeInBytes()

public int getVerticesSizeInBytes()

The total size of all vertices in bytes

Returns: int

hashCode()

public native int hashCode()

Returns: int

indicesToArray(int[][] result)

public void indicesToArray(int[][] result)

Convert the indices to 32bit integer array

Parameters:

ParameterTypeDescription
resultint[][]

indicesToArray(short[][] result)

public void indicesToArray(short[][] result)

Convert the indices to 16bit integer array

Parameters:

ParameterTypeDescription
resultshort[][]

iterator()

public Iterator<Vertex> iterator()

Get the enumerator to enumerate Vertex

Returns: java.util.Iterator<com.aspose.threed.Vertex>

loadVerticesFromBytes(byte[] verticesInBytes)

public void loadVerticesFromBytes(byte[] verticesInBytes)

Load vertices from bytes, the length of bytes must be an integer multiple of vertex size.

Parameters:

ParameterTypeDescription
verticesInBytesbyte[]

notify()

public final native void notify()

notifyAll()

public final native void notifyAll()

readDouble(int idx, VertexField field)

public double readDouble(int idx, VertexField field)

Read the double field

Parameters:

ParameterTypeDescription
idxintThe index of vertex to read
fieldVertexFieldThe field with a float/double compatible data type

Returns: double

readFVector2(int idx, VertexField field)

public FVector2 readFVector2(int idx, VertexField field)

Read the vector2 field

Parameters:

ParameterTypeDescription
idxintThe index of vertex to read
fieldVertexFieldThe field with a Vector2/FVector2 data type

Returns: FVector2

readFVector3(int idx, VertexField field)

public FVector3 readFVector3(int idx, VertexField field)

Read the vector3 field

Parameters:

ParameterTypeDescription
idxintThe index of vertex to read
fieldVertexFieldThe field with a Vector3/FVector3 data type

Returns: FVector3

readFVector4(int idx, VertexField field)

public FVector4 readFVector4(int idx, VertexField field)

Read the vector4 field

Parameters:

ParameterTypeDescription
idxintThe index of vertex to read
fieldVertexFieldThe field with a Vector4/FVector4 data type

Returns: FVector4

readFloat(int idx, VertexField field)

public float readFloat(int idx, VertexField field)

Read the float field

Parameters:

ParameterTypeDescription
idxintThe index of vertex to read
fieldVertexFieldThe field with a float/double compatible data type

Returns: float

readVector2(int idx, VertexField field)

public Vector2 readVector2(int idx, VertexField field)

Read the vector2 field

Parameters:

ParameterTypeDescription
idxintThe index of vertex to read
fieldVertexFieldThe field with a Vector2/FVector2 data type

Returns: Vector2

readVector3(int idx, VertexField field)

public Vector3 readVector3(int idx, VertexField field)

Read the vector3 field

Parameters:

ParameterTypeDescription
idxintThe index of vertex to read
fieldVertexFieldThe field with a Vector3/FVector3 data type

Returns: Vector3

readVector4(int idx, VertexField field)

public Vector4 readVector4(int idx, VertexField field)

Read the vector4 field

Parameters:

ParameterTypeDescription
idxintThe index of vertex to read
fieldVertexFieldThe field with a Vector4/FVector4 data type

Returns: Vector4

removeProperty(Property property)

public boolean removeProperty(Property property)

Removes a dynamic property.

Parameters:

ParameterTypeDescription
propertyPropertyWhich property to remove

Returns: boolean - true if the property is successfully removed

removeProperty(String property)

public boolean removeProperty(String property)

Remove the specified property identified by name

Parameters:

ParameterTypeDescription
propertyjava.lang.String

Returns: boolean

setExcluded(boolean value)

public void setExcluded(boolean value)

Sets whether to exclude this entity during exporting.

Parameters:

ParameterTypeDescription
valuebooleanNew value

setName(String value)

public void setName(String value)

Sets the name.

Parameters:

ParameterTypeDescription
valuejava.lang.StringNew value

setParentNode(Node value)

public void setParentNode(Node value)

Sets the first parent node, if set the first parent node, this entity will be detached from other parent nodes.

Parameters:

ParameterTypeDescription
valueNodeNew value

setProperty(String property, Object value)

public void setProperty(String property, Object value)

Sets the value of specified property

Parameters:

ParameterTypeDescription
propertyjava.lang.StringProperty name
valuejava.lang.ObjectThe value of the property

toString()

public String toString()

Gets the string representation of TriMesh

Returns: java.lang.String

verticesToArray()

public byte[] verticesToArray()

Convert the vertices data to byte array

Returns: byte[]

wait()

public final void wait()

wait(long arg0)

public final void wait(long arg0)

Parameters:

ParameterTypeDescription
arg0long

wait(long arg0, int arg1)

public final void wait(long arg0, int arg1)

Parameters:

ParameterTypeDescription
arg0long
arg1int

write16bIndicesTo(Stream stream)

public void write16bIndicesTo(Stream stream)

Write the indices data as 16bit integer to the stream

Parameters:

ParameterTypeDescription
streamcom.aspose.csporter.helpers.StreamExample:
//convert a mesh to TriMesh, the layout is automatically inferred from input mesh
      var mesh = (new Sphere()).toMesh();
      var triMesh = TriMesh.fromMesh(mesh);
      //save it to a stream, 115 vertices * 32bytes per vertex
      var stream = new ByteArrayOutputStream();
      try(var s = Stream.wrap(stream)) {
          triMesh.writeVerticesTo(s);
          //save indices as ushort to stream, 504 indices * 2 bytes per index
          triMesh.write16bIndicesTo(s);
      }
``` |

### write16bIndicesTo(OutputStream stream) {#write16bIndicesTo-java.io.OutputStream-}

public void write16bIndicesTo(OutputStream stream)



Write the indices data as 16bit integer to the stream

**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| stream | java.io.OutputStream | **Example:**

//convert a mesh to TriMesh, the layout is automatically inferred from input mesh
var mesh = (new Sphere()).toMesh();
var triMesh = TriMesh.fromMesh(mesh);
//save it to a stream, 115 vertices * 32bytes per vertex
var stream = new ByteArrayOutputStream();
triMesh.writeVerticesTo(stream);
//save indices as ushort to stream, 504 indices * 2 bytes per index
triMesh.write16bIndicesTo(stream);


### write32bIndicesTo(Stream stream) {#write32bIndicesTo-com.aspose.csporter.helpers.Stream-}

public void write32bIndicesTo(Stream stream)



Write the indices data as 32bit integer to the stream

**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| stream | com.aspose.csporter.helpers.Stream | **Example:**

//convert a mesh to TriMesh, the layout is automatically inferred from input mesh var mesh = (new Sphere()).toMesh(); var triMesh = TriMesh.fromMesh(mesh); //save it to a stream, 115 vertices * 32bytes per vertex var stream = new ByteArrayOutputStream(); try(var s = Stream.wrap(stream)) { triMesh.writeVerticesTo(s); //save indices as ushort to stream, 504 indices * 2 bytes per index triMesh.write32bIndicesTo(s); }


### write32bIndicesTo(OutputStream stream) {#write32bIndicesTo-java.io.OutputStream-}

public void write32bIndicesTo(OutputStream stream)



Write the indices data as 32bit integer to the stream

**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| stream | java.io.OutputStream | **Example:**

//convert a mesh to TriMesh, the layout is automatically inferred from input mesh
var mesh = (new Sphere()).toMesh();
var triMesh = TriMesh.fromMesh(mesh);
//save it to a stream, 115 vertices * 32bytes per vertex
var stream = new ByteArrayOutputStream();
triMesh.writeVerticesTo(stream);
//save indices as ushort to stream, 504 indices * 2 bytes per index
triMesh.write32bIndicesTo(stream);


### writeVerticesTo(Stream stream) {#writeVerticesTo-com.aspose.csporter.helpers.Stream-}

public void writeVerticesTo(Stream stream)



Write vertices data to the specified stream

**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| stream | com.aspose.csporter.helpers.Stream | The stream that the vertices data will be written to **Example:**

//convert a mesh to TriMesh, the layout is automatically inferred from input mesh var mesh = (new Sphere()).toMesh(); var triMesh = TriMesh.fromMesh(mesh); //save it to a stream, 115 vertices * 32bytes per vertex var stream = new ByteArrayOutputStream(); try(var s = Stream.wrap(stream)) { triMesh.writeVerticesTo(s); //save indices as ushort to stream, 504 indices * 2 bytes per index triMesh.write16bIndicesTo(s); }


### writeVerticesTo(OutputStream stream) {#writeVerticesTo-java.io.OutputStream-}

public void writeVerticesTo(OutputStream stream)



Write vertices data to the specified stream

**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| stream | java.io.OutputStream | The stream that the vertices data will be written to **Example:**

//convert a mesh to TriMesh, the layout is automatically inferred from input mesh
var mesh = (new Sphere()).toMesh();
var triMesh = TriMesh.fromMesh(mesh);
//save it to a stream, 115 vertices * 32bytes per vertex
var stream = new ByteArrayOutputStream();
triMesh.writeVerticesTo(stream);
//save indices as ushort to stream, 504 indices * 2 bytes per index
triMesh.write16bIndicesTo(stream);