Hinzufügen von Animations eigenschaft und Setup-Ziel kamera in einem 3D-Dokument
Animation-Eigenschaft in 3D-Dokument hinzufügen
Aspose.3D for Java unterstützt das Rendern animierter Szene. In diesem Artikel werden die Voraussetzungen zum Verschieben eines Objekts erläutert.
Bewegen Sie die Position des Würfels
Mesh
-Klassen objekt wird im Code verwendet. Wir können Erstellen Sie ein Mesh-Klassen objekt, wie es dort erzählt wird und es muss auch die lokale Übersetzungs eigenschaft des Knotens animieren: Hinzufügen der Transformation zum Knoten.
In Aspose.3D for Java API ist die Animations instanz eigentlich eine Key-Frame-Animation, die auf Eigenschaften animiert. Um Eigenschaften zu animieren, benötigen Sie eine CurveMapping
-Instanz, die Komponenten einer Eigenschaft verschiedenen Kurven zuordnet. Beispiels weise kann eine Vector3
-Eigenschaft 3 Komponenten X
/Y
/Z
haben. Das wird drei Kanäle in CurveMapping
einrichten, jeder Kanal kann einen Satz von Curve
haben.
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-Java | |
// Initialize scene object | |
Scene scene = new Scene(); | |
// Call Common class create mesh using polygon builder method to set mesh instance | |
Mesh mesh = Common.createMeshUsingPolygonBuilder(); | |
// Each cube node has their own translation | |
Node cube1 = scene.getRootNode().createChildNode("cube1", mesh); | |
// Find translation property on node's transform object | |
Property translation = cube1.getTransform().findProperty("Translation"); | |
// Create a bind point based on translation property | |
BindPoint bindPoint = new BindPoint(scene, translation); | |
// Create the animation curve on X component of the scale | |
KeyframeSequence kfs = new KeyframeSequence(); | |
// Move node's translation to (10, 0, 10) at 0 sec using bezier interpolation | |
kfs.add(0, 10.0f, Interpolation.BEZIER); | |
// Move node's translation to (20, 0, -10) at 3 sec | |
kfs.add(3, 20.0f, Interpolation.BEZIER); | |
// Move node's translation to (30, 0, 0) at 5 sec | |
kfs.add(5, 30.0f, Interpolation.LINEAR); | |
bindPoint.bindKeyframeSequence("X", kfs); | |
kfs = new KeyframeSequence(); | |
// Move node's translation to (10, 0, 10) at 0 sec using bezier interpolation | |
kfs.add(0, 10.0f, Interpolation.BEZIER); | |
// Move node's translation to (20, 0, -10) at 3 sec | |
kfs.add(3, -10.0f, Interpolation.BEZIER); | |
// Move node's translation to (30, 0, 0) at 5 sec | |
kfs.add(5, 0.0f, Interpolation.LINEAR); | |
bindPoint.bindKeyframeSequence("Z", kfs); | |
// The path to the documents directory. | |
String MyDir = RunExamples.getDataDir(); | |
MyDir = MyDir + RunExamples.getOutputFilePath("PropertyToDocument.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.save(MyDir, FileFormat.FBX7500ASCII); |
Richten Sie die Ziel kamera in 3D-Datei ein
Aspose.3D for Java bietet an, die Ziel kamera in 3D-Datei einzurichten. In einigen Dateiformaten unterstützt Licht/Kamera das Ziel, wodurch das Licht/die Kamera immer einem bestimmten Knoten zugewandt ist. Dies ist in der Animation nützlich.
Scene
, Camera
, Node
und Transform
werden im Code verwendet. Um eine Scene
, Scene.save
Methode zu speichern, wird ein Dateiname mit vollständigem Pfad und FileFormat
Parameter akzeptiert.
Im folgenden Beispiel wird das Ziel und die Kamera in der 3D-Datei eingerichtet:
// The path to the documents directory. | |
String MyDir = RunExamples.getDataDir(); | |
// Initialize scene object | |
Scene scene = new Scene(); | |
// Get a child node object | |
Node cameraNode = scene.getRootNode().createChildNode("camera", new Camera()); | |
// Set camera node translation | |
cameraNode.getTransform().setTranslation(new Vector3(100, 20, 0)); | |
((Camera)cameraNode.getEntity()).setTarget(scene.getRootNode().createChildNode("target")); | |
MyDir = MyDir + "camera-test.3ds"; | |
scene.save(MyDir, FileFormat.DISCREET3DS); |