Добавление преобразования к узлу
Contents
[
Hide
]
Aspose.3D for Java API поддерживает поворот объектов в пространстве 3D. Существует три способа определения вращения объекта в пространстве 3D, углы Эйлер-пула, Кватернион и Пользовательская матрица, все они поддерживаются классом
Transform
.
TSR (трансляция/масштабирование/вращение) чаще всего используются в сценарии 3D, мы предоставили класс Transform
для доступа к ним в Aspose. Аффинные преобразования 3D включают:
- Перевод
- Масштабирование
- Вращение
- Отображение сдвига
- Отжать картографирование
В коде используется объект класса
Mesh
. Мы можем Создать объект класса Mesh, как там рассказано.
Вращать от Quaternion
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
// Initialize scene object | |
Scene scene = new Scene(); | |
// Initialize Node class object | |
Node cubeNode = new Node("cube"); | |
// Call Common class create mesh using polygon builder method to set mesh instance | |
Mesh mesh = Common.createMeshUsingPolygonBuilder(); | |
// Point node to the Mesh geometry | |
cubeNode.setEntity(mesh); | |
// Set rotation | |
cubeNode.getTransform().setRotation(Quaternion.fromRotation(new Vector3(0, 1, 0), new Vector3(0.3, 0.5, 0.1))); | |
// Set translation | |
cubeNode.getTransform().setTranslation(new Vector3(0, 0, 20)); | |
// Add cube to the scene | |
scene.getRootNode().getChildNodes().add(cubeNode); | |
// The path to the documents directory. | |
String MyDir = RunExamples.getDataDir(); | |
MyDir = MyDir + RunExamples.getOutputFilePath("TransformationToNode.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.save(MyDir, FileFormat.FBX7500ASCII); |
Поворот от углов Эйлера
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
// Initialize scene object | |
Scene scene = new Scene(); | |
// Initialize Node class object | |
Node cubeNode = new Node("cube"); | |
// Call Common class create mesh using polygon builder method to set mesh instance | |
Mesh mesh = Common.createMeshUsingPolygonBuilder(); | |
// Point node to the Mesh geometry | |
cubeNode.setEntity(mesh); | |
// Euler angles | |
cubeNode.getTransform().setEulerAngles(new Vector3(0.3, 0.1, -0.5)); | |
// Set translation | |
cubeNode.getTransform().setTranslation(new Vector3(0, 0, 20)); | |
// Add cube to the scene | |
scene.getRootNode().getChildNodes().add(cubeNode); | |
// The path to the documents directory. | |
String MyDir = RunExamples.getDataDir(); | |
MyDir = MyDir + RunExamples.getOutputFilePath("TransformationToNode.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.save(MyDir, FileFormat.FBX7500ASCII); |
Пользовательская матрица трансформации
Мы также можем использовать Matrix напрямую:
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
// Initialize scene object | |
Scene scene = new Scene(); | |
// Initialize Node class object | |
Node cubeNode = new Node("cube"); | |
// Call Common class create mesh using polygon builder method to set mesh instance | |
Mesh mesh = Common.createMeshUsingPolygonBuilder(); | |
// Point node to the Mesh geometry | |
cubeNode.setEntity(mesh); | |
// Set custom translation matrix | |
cubeNode.getTransform().setTransformMatrix(new Matrix4( | |
1, -0.3, 0, 0, | |
0.4, 1, 0.3, 0, | |
0, 0, 1, 0, | |
0, 20, 0, 1 | |
)); | |
// Add cube to the scene | |
scene.getRootNode().addChildNode(cubeNode); | |
// The path to the documents directory. | |
String MyDir = RunExamples.getDataDir(); | |
MyDir = MyDir + RunExamples.getOutputFilePath("TransformationToNode.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.save(MyDir, FileFormat.FBX7500ASCII); |