在 3D 文档中添加动画属性并设置目标相机

在 3D 文档中添加动画属性

Aspose.3D for Java 支持渲染动画场景。本文介绍移动对象的先决条件。

移动立方体的位置

在 Aspose.3D for Java API 中,animation实例实际上是对属性进行动画处理的关键帧动画。为了动画属性,您需要一个 CurveMapping 实例,它将属性的组件映射到不同的曲线,例如,一个 Vector3 属性可以有3个组件 X/Y/Z,这将在 CurveMapping 中设置三个频道,每个频道可以有一组 Curve

// 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);

在 3D 文件中设置目标相机

Aspose.3D for Java 提供在 3D 文件中设置目标相机。在某些文件格式中,灯光/摄像机支持目标,这允许灯光/摄像机始终面向指定节点,这在动画中很有用。

在下面的示例中,目标和相机在 3D 文件中设置:

// 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);