Mesh
पैकेज: com.aspose.threed (aspose-3d-foss 26.1.0)
Mesh बहुभुज ज्यामिति को नियंत्रण बिंदुओं (वर्टेक्स स्थितियों) की सूची और बहुभुज चेहरों की सूची के रूप में संग्रहीत करता है। प्रत्येक बहुभुज चेहरा नियंत्रण बिंदुओं की सरणी में शून्य‑आधारित सूचकांकों की सूची होता है। चेहरे त्रिभुज, चतुर्भुज, या उच्च‑आर्की बहुभुज हो सकते हैं। अतिरिक्त प्रति‑वर्टेक्स डेटा — नॉर्मल्स, यूवी निर्देशांक, वर्टेक्स रंग — संलग्न किया जाता है जैसा कि 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() एक स्टब है — नीचे चेतावनी देखें):
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
| Name | Type | Access | Description |
| ------------------- | ------------------------------- | ------ | ----------------------------- |
| `polygonCount` | `int` | Read | Gets the polygon count. |
| `polygons` | `List<int[]>` | Read | Gets the polygons. |
| `edges` | `List<Integer>` | Read | Gets the edges. |
| `manifold` | `boolean` | Read | Gets the manifold. |
| `visible` | `boolean` | Read | Gets the visible. |
| `castShadows` | `boolean` | Read | Gets the cast shadows. |
| `receiveShadows` | `boolean` | Read | Gets the receive shadows. |
| `controlPoints` | `java.util.List<Vector4>` | Read | Gets the control points. |
| `vertexElements` | `java.util.List<VertexElement>` | Read | Gets the vertex elements. |
| `deformers` | `java.util.List<Deformer>` | Read | Gets the deformers. |
| `deformers2` | `java.util.Collection<T>` | Read | Gets the deformers2. |
| `parentNode` | `Node` | Read | Gets the parent node. |
| `parentNodes` | `ArrayList<Node>` | Read | Gets the parent nodes. |
| `excluded` | `boolean` | Read | Gets the excluded. |
| `boundingBox` | `BoundingBox` | Read | Gets the bounding box. |
| `entityRendererKey` | `EntityRendererKey` | Read | Gets the entity renderer key. |
| `scene` | `Scene` | Read | Gets the scene. |
| `name` | `String` | Read | Gets the name. |
| `properties` | `PropertyCollection` | Read | Gets the properties. |
---
## Methods
### `createPolygon(int... indices)`
एक नया बहुभुज चेहरा परिभाषित करें, क्रम में शीर्ष बिंदु के इंडेक्स प्रदान करके। इंडेक्स उन स्थितियों को संदर्भित करते हैं जिसमें `getControlPoints()`. त्रिभुज, चतुर्भुज और n-गॉन के लिए तीन या अधिक सूचकांक स्वीकार करता है।.
| Signature | Description |
| --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| `Mesh()` | Creates an empty mesh with default name |
| `Mesh(name: String)` | Calls Mesh(name) on this Mesh instance. |
| `addControlPoint(x: double, y: double, z: double)` | Adds a weighted 4D control point |
| `addControlPoint(x: double, y: double, z: double, w: double)` | Calls addControlPoint(x, y, z, w) on this Mesh instance. |
| `createPolygon(indices: int[])` | Creates a quadrilateral polygon from four vertex indices |
| `createPolygon(indices: int[], offset: int, length: int)` | Calls createPolygon(indices, offset, length) on this Mesh instance. |
| `createPolygon(v1: int, v2: int, v3: int)` | Calls createPolygon(v1, v2, v3) on this Mesh instance. |
| `createPolygon(v1: int, v2: int, v3: int, v4: int)` | Calls createPolygon(v1, v2, v3, v4) on this Mesh instance. |
| `getPolygonCount()` → `int` | Returns the polygon count. |
| `getPolygonSize(index: int)` → `int` | Returns the number of vertices of the polygon at the given index |
| `getPolygons()` → `List<int[]>` | Returns the polygons. |
| `getEdges()` → `List<Integer>` | Returns the edges. |
| `isManifold()` → `boolean` | Returns true if manifold is set. |
| `iterator()` → `Iterator<int[]>` | Provides an iterator over polygon index arrays |
| `toMesh()` → `Mesh` | Returns a copy of this mesh as a Mesh object |
| `clone()` → `Mesh` | Creates a deep copy of the mesh |
| `triangulate()` → `Mesh` | Converts all polygons to triangles and returns the new mesh |
| `optimize(removeVertices: boolean)` → `Mesh` | Simplifies geometry considering tolerance, threshold, and angle deviation |
| `optimize(removeVertices: boolean, tolerance: float)` → `Mesh` | Calls optimize(removeVertices, tolerance) on this Mesh instance. |
| `optimize(removeVertices: boolean, tolerance: float, threshold: float)` → `Mesh` | Calls optimize(removeVertices, tolerance, threshold) on this Mesh instance. |
| `optimize(removeVertices: boolean, tolerance: float, threshold: float, angleThreshold: float)` → `Mesh` | Calls optimize(removeVertices, tolerance, threshold, angleThreshold) on this Mesh instance. |
| `optimize2(removeVertices: boolean)` → `Mesh` | Performs an alternative optimization on the mesh |
| `union(a: Mesh, b: Mesh)` → `Mesh` | Returns a mesh representing the union of two meshes |
| `difference(a: Mesh, b: Mesh)` → `Mesh` | Calls difference(a, b) on this Mesh instance. |
| `intersect(a: Mesh, b: Mesh)` → `Mesh` | Calls intersect(a, b) on this Mesh instance. |
| `doBoolean(operation: BooleanOperation, a: Mesh, ma: Matrix4, b: Mesh, mb: Matrix4)` → `Mesh` | Performs the specified Boolean operation on two transformed meshes |
| `Geometry()` | Calls Geometry on this Mesh instance. |
| `getVisible()` → `boolean` | Returns the visible. |
| `setVisible(value: boolean)` | Sets the visible value. |
| `getCastShadows()` → `boolean` | Returns the cast shadows. |
| `setCastShadows(value: boolean)` | Sets the cast shadows value. |
| `getReceiveShadows()` → `boolean` | Returns the receive shadows. |
| `setReceiveShadows(value: boolean)` | Initializes a new instance of Sphere class. |
| `getControlPoints()` → `java.util.List<Vector4>` | Returns the control points. |
| `getVertexElements()` → `java.util.List<VertexElement>` | Returns the vertex elements. |
| `getDeformers()` → `java.util.List<Deformer>` | Returns the deformers. |
| `getElement(type: VertexElementType)` → `VertexElement` | Calls getElement(type) on this Mesh instance. |
| `createElement(type: VertexElementType)` → `VertexElement` | Gets or sets the height segments. |
| `addElement(element: VertexElement)` | Calls addElement(element) on this Mesh instance. |
| `addDeformer(deformer: Deformer)` | Adds a deformer to this geometry and sets the owner reference. |
| `getVertexElementOfUV(mapping: TextureMapping)` → `VertexElementUV` | Calls getVertexElementOfUV(mapping) on this Mesh instance. |
| `createElementUV(mapping: TextureMapping)` → `VertexElementUV` | Calls createElementUV(mapping) on this Mesh instance. |
| `getDeformers2()` → `java.util.Collection<T>` | Returns the deformers2. |
| `Entity(name: String)` | Constructor of BooleanOperator. |
| `getParentNode()` → `Node` | Constructor of instance. |
| `setParentNode(value: Node)` | The Boolean operator used in the operation to create the result mesh. |
| `getParentNodes()` → `ArrayList<Node>` | Protected constructor to allow derived classes to set name. |
| `getExcluded()` → `boolean` | The Boolean operator used in the operation to create the result mesh. |
| `setExcluded(value: boolean)` | Sets the excluded value. |
| `getBoundingBox()` → `BoundingBox` | The first operand of the Boolean operator. |
| `getEntityRendererKey()` → `EntityRendererKey` | Returns the entity renderer key. |
| `SceneObject()` | Boolean operator allows you to apply Boolean operation on two IMeshConvertible instances. |
| `getScene()` → `Scene` | Constructor of BooleanOperator. |
| `A3DObject()` | Parameterized Cylinder. It can also be used to represent a cone when one of radiusTop/radiusBottom is zero. |
| `getName()` → `String` | Height of the dish. |
| `setName(name: String)` | Constructs a CircleShape profile with specified radius. |
| `getProperties()` → `PropertyCollection` | Initializes a new instance of Cylinder class. |
| `findProperty(name: String)` → `Property` | Initializes a new instance of the Bone class. |
| `getProperty(name: String)` → `Object` | Gets the transform matrix of the node in current pose. |
| `setProperty(name: String, value: Object)` | Gets the width segments. |
| `removeProperty(name: String)` → `boolean` | Gets the entity renderer key for this entity. |
**रिटर्न:** `void`
```java
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 की एक क्लोन लौटाता है। सभी polygons को fan triangulation का उपयोग करके triangles में विभाजित करने के उद्देश्य से, लेकिन वास्तविक triangulation लॉजिक अभी लागू नहीं किया गया है। मूल mesh में कोई परिवर्तन नहीं किया जाता।.
रिटर्न: Mesh – मूल 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 base class ताकि generic रेफ़रेंसेज़ के साथ काम करते समय एक समान रूपांतरण इंटरफ़ेस प्रदान किया जा सके Geometry रेफ़रेंसेज़।.
रिटर्न्स: Mesh
Mesh ensureMesh(Geometry geom) { return geom.toMesh(); }
---
### `createElement(VertexElementType elementType, MappingMode mappingMode, ReferenceMode referenceMode)`
एक नया जोड़ें `VertexElement` लेयर को निर्दिष्ट प्रकार का मेष में जोड़ें। इसका उपयोग normals, tangents, binormals, vertex colours, और smoothing groups को संलग्न करने के लिए करें।.
**वापसी:** `VertexElement`
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 कॉर्डिनेट लेयर जोड़ें। यह टेक्सचर कॉर्डिनेट डेटा संलग्न करने की पसंदीदा विधि है।.
वापसी: VertexElementUV
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)`.
---
## संबंधित देखें
- [Entity क्लास संदर्भ](/3d/java/entity/)
- [Node क्लास संदर्भ](/3d/java/node/)
- [Scene क्लास संदर्भ](/3d/java/scene/)
- [VertexElement क्लास रेफ़रेंस](/3d/java/vertex-element/)