Customize Non-PBR to PBR Materials Conversion before Saving 3D Scenes to GLTF 2.0 Format
Contents
[
Hide
]
The
Scene
class of the Aspose.3D for Java API represents a 3D scene and developers can build a 3D scene by adding various entities. GLTF 2.0 only supports PBR (Physically Based Rendering) materials, Aspose.3D API internally converts non-PBR materials into PBR materials before exporting into GLTF 2.0 (the materials in the scene will remain unchanged during the export), and the developers can provide custom convert function to override the default behavior.
Non-PBto to PBerial erial aterial erial onversion
Bu kod örneği, malzemeyi pbr malzemesine nasıl dönüştüreceğinizi gösterir ve daha sonra 3D formatında GLTF görüntüsünü kaydeder:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String MyDir = RunExamples.getDataDir(); | |
/* initialize a new 3D scene */ | |
Scene s = new Scene(); | |
Box box = new Box(); | |
PhongMaterial mat = new PhongMaterial(); | |
mat.setDiffuseColor(new Vector3(1, 0, 1)); | |
s.getRootNode().createChildNode("box1", box).setMaterial(mat); | |
GLTFSaveOptions opt = new GLTFSaveOptions(FileFormat.GLTF2); | |
//Custom material converter to convert PhongMaterial to PbrMaterial | |
opt.setMaterialConverter(new MaterialConverter() { | |
@Override | |
public Material call(Material material) { | |
PhongMaterial m = (PhongMaterial) material; | |
PbrMaterial ret = new PbrMaterial(); | |
ret.setAlbedo(m.getDiffuseColor()); | |
return ret; | |
} | |
}); | |
// save in GLTF 2.0 format | |
s.save(MyDir + "Non_PBRtoPBRMaterial_Out.gltf", opt); |