Material
Properties: com.aspose.threed.shading (aspose-3d-foss)
Aspose.3D FOSS for Java 提供两种材质类::
Material: 所有材质类型的抽象基类。提供名称以及用于数值和颜色参数的属性集合。.PbrMaterial: 具有金属度、粗糙度、反照率和自发光属性的基于物理的渲染材质。用于 glTF 2.0 以及其他支持 PBR 的格式。.
材质被分配给 a Node 通过 node.setMaterial(material).
Properties
public abstract class Material extends A3DObjectProperties
A3DObject -> Material
Material 是所有 material 类型的抽象基类。它提供 name 属性和一个 Properties 用于用户自定义 metadata 的集合。您不能实例化 Material 直接;使用 PbrMaterial 而不是。.
PbrMaterial
public class PbrMaterial extends MaterialProperties
A3DObject -> Material -> PbrMaterial
PBR(Physically Based Rendering)材质。由 glTF 2.0 和其他支持 PBR 的格式使用。分配给 a Node 通过 node.setMaterial(material).
Properties
PbrMaterial()
PbrMaterial(String name)
PbrMaterial(String name, Vector4 albedo)Properties
| Name | Type | Access | Description |
|---|---|---|---|
MAP_SPECULAR | String | Read | Used in setTexture(java.lang.String, com.aspose.threed.TextureBase) to assign a specular texture mapping. |
MAP_DIFFUSE | String | Read | Used in setTexture(java.lang.String, com.aspose.threed.TextureBase) to assign a diffuse texture mapping. |
MAP_EMISSIVE | String | Read | Used in setTexture(java.lang.String, com.aspose.threed.TextureBase) to assign a emissive texture mapping. |
MAP_AMBIENT | String | Read | Used in setTexture(java.lang.String, com.aspose.threed.TextureBase) to assign a ambient texture mapping. |
MAP_NORMAL | String | Read | Used in setTexture(java.lang.String, com.aspose.threed.TextureBase) to assign a normal texture mapping. |
name | String | Read | Gets the name. |
properties | PropertyCollection | Read | Gets the properties. |
| Signature | Description |
|---|---|
getTexture(slotName: String) → TextureBase | Gets the texture from the specified slot, it can be material’s property name or shader’s parameter name. |
setTexture(slotName: String, texture: TextureBase) | Sets the texture to specified slot. |
toString() → String | Formats object to string. |
iterator() → Iterator<TextureSlot> | Gets the enumerator to enumerate internal texture slots. |
A3DObject() | Parameterized Cylinder. It can also be used to represent a cone when one of radiusTop/radiusBottom is zero. |
getName() → String | The segments of the curve. |
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 flip coordinate system of control points/normal during importing/exporting. |
使用示例
import com.aspose.threed.*;
import com.aspose.threed.shading.PbrMaterial;
Scene scene = new Scene();
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);
PbrMaterial mat = new PbrMaterial("pbr-metal");
mat.setAlbedo(new Vector4(0.8, 0.6, 0.2, 1.0)); // gold-ish base color
mat.setMetallicFactor(0.9);
mat.setRoughnessFactor(0.2);
Node node = scene.getRootNode().createChildNode("mesh", mesh);
node.setMaterial(mat);
scene.save("pbr.glb");半透明 PBR 材质
import com.aspose.threed.shading.PbrMaterial;
PbrMaterial mat = new PbrMaterial("glass");
mat.setAlbedo(new Vector4(0.7, 0.9, 1.0, 1.0));
mat.setTransparency(0.7); // 70% transparent
mat.setRoughnessFactor(0.1);从导入的场景读取材质
import com.aspose.threed.*;
import com.aspose.threed.shading.PbrMaterial;
Scene scene = new Scene();
scene.open("model.gltf");
inspectNode(scene.getRootNode());
static void inspectNode(Node node) {
if (node.getMaterial() != null) {
Material m = node.getMaterial();
if (m instanceof PbrMaterial) {
PbrMaterial pbr = (PbrMaterial) m;
System.out.println("Node '" + node.getName() + "': PbrMaterial");
System.out.println(" albedo=" + pbr.getAlbedo());
System.out.println(" metallic=" + pbr.getMetallicFactor());
System.out.println(" roughness=" + pbr.getRoughnessFactor());
} else {
System.out.println("Node '" + node.getName() + "': " + m.getClass().getSimpleName());
}
}
for (Node child : node.getChildNodes()) {
inspectNode(child);
}
}