article

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

Email
Submitted on: 1/6/2016 11:13:04 AM
By: Sherazam  
Level: Intermediate
User Rating: Unrated
Compatibility: C#, VB.NET
Views: 2899
 
     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.

 
				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
 


Other 44 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.