How to Add Animation Property to 3D Scene Document inside .NET Application
This Technical tip explains how .NET developers can add animation property to 3D scene document inside their .NET applications. Aspose.3D for .NET supports rendering animated scene. This article explains prerequisites to move an object. The Mesh class object is being used in the code. We can create a Mesh class object as narrated there and it's must animate the local translation property of the node too: Adding the Transformation to the Node. In Aspose.3D, object animation is actually key-frame animation that animates on properties. To animate properties, you need a CurveMapping instance which maps components of a property to different curves, for example, a Vector3 property can have 3 components X/Y/Z, which will set up three channels in CurveMapping, every channel can have a set of Curves.
//your code here...// [C# Code Sample]
// For complete examples and data files, please go to https://github.com/aspose3d/Aspose_3D_NET
// 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.RootNode.CreateChildNode("cube1", mesh);
// Find translation property on node's transform object
Property translation = cube1.Transform.FindProperty("Translation");
// Create a curve mapping based on translation property
CurveMapping mapping = new CurveMapping(scene, translation);
// Create curve on channel X and Z
Curve curveX = mapping.CreateCurve("X");
Curve curveZ = mapping.CreateCurve("Z");
// Move node's translation to (10, 0, 10) at 0 sec using bezier interpolation
curveX.CreateKeyFrame(0, 10.0f, Interpolation.Bezier);
curveZ.CreateKeyFrame(0, 10.0f, Interpolation.Bezier);
// Move node's translation to (20, 0, -10) at 3 sec
curveX.CreateKeyFrame(3, 20.0f, Interpolation.Bezier);
curveZ.CreateKeyFrame(3, -10.0f, Interpolation.Bezier);
// Move node's translation to (30, 0, 0) at 5 sec
curveX.CreateKeyFrame(5, 30.0f, Interpolation.Linear);
curveZ.CreateKeyFrame(5, 0.0f, Interpolation.Bezier);
// 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.FBX7400ASCII);
//[VB.NET Code Sample]
' For complete examples and data files, please go to https://github.com/aspose3d/Aspose_3D_NET
' Initialize scene object
Dim scene As New Scene()
' Call Common class create mesh using polygon builder method to set mesh instance
Dim mesh As Mesh = Common.CreateMeshUsingPolygonBuilder()
' Each cube node has their own translation
Dim cube1 As Node = scene.RootNode.CreateChildNode("cube1", mesh)
' Find translation property on node's transform object
Dim translation As [Property] = cube1.Transform.FindProperty("Translation")
' Create a curve mapping based on translation property
Dim mapping As New CurveMapping(scene, translation)
' Create curve on channel X and Z
Dim curveX As Curve = mapping.CreateCurve("X")
Dim curveZ As Curve = mapping.CreateCurve("Z")
' Move node's translation to (10, 0, 10) at 0 sec using bezier interpolation
curveX.CreateKeyFrame(0, 10.0F, Interpolation.Bezier)
curveZ.CreateKeyFrame(0, 10.0F, Interpolation.Bezier)
' Move node's translation to (20, 0, -10) at 3 sec
curveX.CreateKeyFrame(3, 20.0F, Interpolation.Bezier)
curveZ.CreateKeyFrame(3, -10.0F, Interpolation.Bezier)
' Move node's translation to (30, 0, 0) at 5 sec
curveX.CreateKeyFrame(5, 30.0F, Interpolation.Linear)
curveZ.CreateKeyFrame(5, 0.0F, Interpolation.Bezier)
' The path to the documents directory.
Dim MyDir As String = RunExamples.GetDataDir()
MyDir = MyDir & RunExamples.GetOutputFilePath("PropertyToDocument.fbx")
' Save 3D scene in the supported file formats
scene.Save(MyDir, FileFormat.FBX7400ASCII)
Url: http://www.aspose.com/.net/3d-component.aspx
Language: C# | User: Sheraz Khan | Created: Jan 6, 2016 | Tags: Render animated scene Add Animation Property to 3D Scene create a Mesh class object .NET 3D Component work with 3D File Formats ASP.NET 3D API