Home > Code > C# > How to Add Animation Property to 3D Scene Document inside .NET Application

How to Add Animation Property to 3D Scene Document inside .NET Application

by sher azam   on Jan 06, 2016   Category: C#   |  Views: 619    |  Points: 25   |  Gold 


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.


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



Overview: Aspose.3D for .NET


Aspose.3D for .NET is a feature-rich component and class library for .NET that empowers Mono and .NET application including ASP.NET, Windows Forms and Web Services to connect with prevalent 3D document formats automatically without the 3D modeling and rendering software being installed on the server. It supports FBX (ASCII, Binary) and STL (ASCII, Binary) file formats and developers can easily create, read, convert, modify and control the substance of these 3D document formats using Aspose.3D API.

- Homepage of Aspose.3D for .NET: http://www.aspose.com/.net/3d-component.aspx

- Download Aspose.3D for .NET: http://www.aspose.com/community/files/51/.net-components/aspose.3d-for-.net/default.aspx



Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts