Mesh — Aspose.3D FOSS for Java
パッケージ: com.aspose.threed (aspose-3d-foss 26.1.0)
Mesh ポリゴンジオメトリは、制御点(頂点位置)のリストとポリゴン面のリストとして格納されます。各ポリゴン面は、制御点配列へのゼロベースインデックスのリストです。面は三角形、四角形、またはそれ以上の多角形になる可能性があります。追加の頂点ごとのデータ――法線、UV座標、頂点カラー――は VertexElement レイヤーとして。.
public class Mesh extends GeometryMethods
A3DObject -> SceneObject -> Entity -> Geometry -> Mesh
Methods
最初から単一の三角形メッシュを構築する:
import com.aspose.threed.Scene;
import com.aspose.threed.*;
// Create the mesh and add three vertex positions
Mesh mesh = new Mesh();
mesh.getControlPoints().add(new Vector4(0.0, 0.0, 0.0, 1.0)); // vertex 0
mesh.getControlPoints().add(new Vector4(1.0, 0.0, 0.0, 1.0)); // vertex 1
mesh.getControlPoints().add(new Vector4(0.5, 1.0, 0.0, 1.0)); // vertex 2
// Define one triangle face using vertex indices
mesh.createPolygon(0, 1, 2);
// Attach to a scene and save
Scene scene = new Scene();
scene.getRootNode().createChildNode("triangle", mesh);
scene.save("triangle.stl");四角形メッシュを構築する(注:triangulate() はスタブです — 以下の警告を参照してください):
import com.aspose.threed.Scene;
import com.aspose.threed.*;
Mesh mesh = new Mesh();
// Four corners of a unit square in the XZ plane
mesh.getControlPoints().add(new Vector4(0, 0, 0, 1.0));
mesh.getControlPoints().add(new Vector4(1, 0, 0, 1.0));
mesh.getControlPoints().add(new Vector4(1, 0, 1, 1.0));
mesh.getControlPoints().add(new Vector4(0, 0, 1, 1.0));
// One quad face
mesh.createPolygon(0, 1, 2, 3);
System.out.println("Polygons before triangulate: " + mesh.getPolygonCount()); // 1
// WARNING: triangulate() is a stub — it returns a clone, NOT a triangulated mesh.
// The polygon count will remain 1 (not 2).
Mesh triangulated = mesh.triangulate();
System.out.println("Polygons after triangulate: " + triangulated.getPolygonCount()); // still 1
Scene scene = new Scene();
scene.getRootNode().createChildNode("quad", triangulated);
// When saving to STL, pass triangle-only meshes to avoid vertex loss or malformed output.
scene.save("quad.glb");Methods
| Methods | Methods | Methods | Methods | Methods |
|---|---|---|---|---|
controlPoints | List<Vector4> | getControlPoints() | – | 頂点位置配列。各エントリは Vector4(x, y, z, w) ここで w は 1.0 位置データ用です。頂点は次を呼び出すことで追加します add() 返されたリスト上で。. |
polygonCount | int | getPolygonCount() | – | このメッシュで定義されたポリゴン面の数。. |
polygons | List<int[]> | getPolygons() | – | すべての面定義はインデックス配列のリストとして表されます。各内部配列は頂点インデックス( controlPoints) 1つの面に対して。. |
edges | List<Integer> | getEdges() | – | 生のエッジインデックスデータ。主に内部使用および高度なトポロジークエリ向けです。. |
vertexElements | List<VertexElement> | getVertexElements() | – | このメッシュに現在アタッチされているすべての頂点要素レイヤー(法線、UV、カラーなど)。. |
visible | boolean | getVisible() | setVisible(boolean) | Methods false,、このメッシュは可視性を尊重するビューアでは非表示になります。. |
castShadows | boolean | getCastShadows() | setCastShadows(boolean) | このメッシュがシャドウマップに対応したレンダラで影をキャストするかどうか。. |
receiveShadows | boolean | getReceiveShadows() | setReceiveShadows(boolean) | このメッシュが他の影を投げるジオメトリから影を受け取るかどうか。. |
Methods
createPolygon(int... indices)
頂点インデックスを順番に指定して新しいポリゴン面を定義します。インデックスは以下の位置を参照します。 getControlPoints(). 三角形、四角形、n-gon の場合、3 つ以上のインデックスを受け付けます。.
| Methods | Methods | Methods |
|---|---|---|
indices | int... | 頂点インデックス引数は winding order(通常は外側から見て反時計回り)で指定します。. |
戻り値: void
Mesh mesh = new Mesh();
// ... populate control points ...
mesh.createPolygon(0, 1, 2); // triangle
mesh.createPolygon(0, 1, 2, 3); // quad
System.out.println(mesh.getPolygonCount()); // 2triangulate()
スタブ: 元のメッシュのクローンを返します。すべてのポリゴンをファン三角形分割で三角形に分割することを意図していますが、実際の三角形分割ロジックはまだ実装されていません。元のメッシュは変更されません。.
返り値: Mesh – 元のメッシュのクローン(スタブ動作)。.
import com.aspose.threed.*;
Mesh mesh = new Mesh();
mesh.getControlPoints().add(new Vector4(0, 0, 0, 1.0));
mesh.getControlPoints().add(new Vector4(1, 0, 0, 1.0));
mesh.getControlPoints().add(new Vector4(1, 1, 0, 1.0));
mesh.getControlPoints().add(new Vector4(0, 1, 0, 1.0));
mesh.createPolygon(0, 1, 2, 3); // one quad
Mesh triMesh = mesh.triangulate();
// Note: currently returns a clone, not a triangulated mesh
System.out.println(triMesh.getPolygonCount());toMesh()
これを返す Mesh として Mesh インスタンス。対象は Mesh オブジェクトの場合、これは同一操作です(返す this) Geometry ベースクラスで、汎用的に作業する際に統一された変換インターフェースを提供するために Geometry 参照。.
戻り値: Mesh
import com.aspose.threed.*;
Mesh ensureMesh(Geometry geom) {
return geom.toMesh();
}createElement(VertexElementType elementType, MappingMode mappingMode, ReferenceMode referenceMode)
新しいものを追加 VertexElement 指定されたタイプのレイヤーをメッシュに追加します。これを使用して法線、接線、バイノーマル、頂点カラー、スムージンググループを付加します。.
| Methods | Methods | Methods |
|---|---|---|
elementType | VertexElementType | このレイヤーが保持するデータの種類(例、., VertexElementType.NORMAL). |
mappingMode | MappingMode | データがジオメトリにマッピングされる方法: CONTROL_POINT, POLYGON_VERTEX, POLYGON, など。. |
referenceMode | ReferenceMode | インデックスの使用方法: DIRECT または INDEX_TO_DIRECT. |
戻り値: VertexElement
import com.aspose.threed.*;
Mesh mesh = new Mesh();
mesh.getControlPoints().add(new Vector4(0, 0, 0, 1));
mesh.getControlPoints().add(new Vector4(1, 0, 0, 1));
mesh.getControlPoints().add(new Vector4(0.5, 1, 0, 1));
mesh.createPolygon(0, 1, 2);
VertexElement normalElement = mesh.createElement(
VertexElementType.NORMAL,
MappingMode.CONTROL_POINT,
ReferenceMode.DIRECT
);createElementUV(TextureMapping uvMapping, MappingMode mappingMode, ReferenceMode referenceMode)
メッシュに UV 座標レイヤーを追加します。テクスチャ座標データを付加するための推奨方法です。.
| Methods | Methods | Methods |
|---|---|---|
uvMapping | TextureMapping | UVチャンネルの目的:: DIFFUSE, SPECULAR, NORMAL, AMBIENT,、など。. |
mappingMode | MappingMode | UVがジオメトリ要素にどのようにマッピングされるか。. |
referenceMode | ReferenceMode | インデックスモード:: DIRECT または INDEX_TO_DIRECT. |
戻り値:: VertexElementUV
import com.aspose.threed.*;
Mesh mesh = new Mesh();
// ... define control points and polygons ...
VertexElementUV uvElement = mesh.createElementUV(
TextureMapping.DIFFUSE,
MappingMode.POLYGON_VERTEX,
ReferenceMode.INDEX_TO_DIRECT
);ブール演算および最適化メソッド(スタブ)
次のメソッドが存在します: Mesh しかし、 スタブ 元のメッシュのクローンを返すが、意図した操作は実行しない。.
重要:: union, difference, intersect, および doBoolean は 静的メソッド, インスタンスメソッドではありません。これらは次のように呼び出します Mesh.union(a, b), ではなく a.union(b).
| Methods | 戻り値の型 | Methods |
|---|---|---|
static Mesh.union(Mesh a, Mesh b) | Mesh | スタブ:: のクローンを返す a. CSG ユニオン用。. |
static Mesh.difference(Mesh a, Mesh b) | Mesh | スタブ: クローンを返す a. CSG 減算用。. |
static Mesh.intersect(Mesh a, Mesh b) | Mesh | スタブ: クローンを返す a. CSG 交差用。. |
static Mesh.doBoolean(BooleanOperation op, Mesh a, Matrix4 ma, Mesh b, Matrix4 mb) | Mesh | スタブ: クローンを返す a. 変換付きの一般的な CSG 用。. |
optimize(boolean removeVertices) | Mesh | スタブ: クローンを返します。4つのパラメータオーバーロード: optimize(boolean), optimize(boolean, float), optimize(boolean, float, float), optimize(boolean, float, float, float). |
optimize2(boolean removeVertices) | Mesh | スタブ: クローンを返します。代替最適化エントリーポイント。. |