Cast 3D.
What is Cast3D?
Cast3D is 3D animation framework library for Adobe Flash in ActionScript3. The foundation is a multi key-framed geometrical animation.
Cast3D supports:
- Geometry and texture morphing.
- Skin animation.
- 3D sound.
- Animated movie and video.
A number of animation interpolation splines is implemented to provide smooth and natural motion, like Bezier, TCB, Hermite(cubic), Cosine and Linear.
Cast3D does not have its own rendering engine.
Cast3D has it own data file. It is an XMLfile, which contains information about 3D scene, objects of a scene, materials, textures, lighting, sound, camera etc.. And motion.
Architecture.
Cast3D is designed in a way that very little or no programming required for displaying and animating 3D scene.
Typically, creation of 3D Flash animation would follow these steps:
1. Create and import 3D model file from a 3D modeling tool, for example 3dSMax.
2. Using code for one of provided samples, update URL path of the .xc3 XML file to load.
Main object class is 'Cast3d' which takes as arguments a rendering engine's 3D scene holder and Camera objects. Then it loads file and populates 3D scene graph for both. There is a way to override or add properties and interactive handles for specific geometry objects and materials during the load time.
The main class also exposes high level control over animation, like 'start', 'stop', 'resume', etc.. .
For each frame Cast3D updates position and orientation of geometrical rendering objects:
Using Cast3D .3ds file format to Cast3D XML file import command-line utility 3ds2XML (Windows, Win32) convert any .3ds model into '.xc3' file with following command.
C:\work> 3ds2XML demo.3ds demo.xc3
A new file demo.xc3 should appear in current directory.
Just be careful what are importing, some models could be too big to handle with Flash. Decent size scene that would animate well is about 3-5K polygons. If you go for more, you might expect visible slowdown in rendering. Beyond 15K polygons, animations id virtually stalls. This limitation is related to Flash rendering pipeline and rendering engine. Cast3D animation itself is quite lightweight.
How to Use:
We need to set the cast object, this recieves the scene and camera as parameters:
this.animator=new Cast3d(this.scene,this.camera);
this.animator.animationType=Cast3d.ANIMATION_TYPE_BYFRAME;
this.animator.animationStyle=Cast3d.ANIMATION_STYLE_FORWARD;
Cast3d.fps=22;
this.animator.autoRewind=true;
//---------------------------------------------------------------------------------------------------
Once the Cast3D object ( animator ) is done, we need to load the model, textures and all the xml files for each animation..
var modelpath:String=loaderInfo.parameters.model;
var rpath:String=loaderInfo.parameters.rpath;
this.loader=new Xc3Loader(modelpath?modelpath:"");
this.loader.resourcePath=rpath?rpath:"";
if (! modelpath || modelpath.length == 0) {
this.loader=new Xc3Loader("../models/walk/fig.zc3");
this.loader.resourcePath="../models/walk";
}
this.loader.preCalcMotion=false;
//---------------------------------------------------------------------------------------------------
Then let's set each animation from the modelso we can call them later:
// First lets find the root node of a character
// we know by looking at source file, its Id is 'Cube'
var nodename:String="Cube";
var node:Node3d=this.animator.source.find(nodename) as Node3d;
if (! node) {
trace("Failed to set Navigation control for node: " + nodename);
return;
}
// create navigation conrloller fo this node.
var nc:NavigationBlenderController=new NavigationBlenderController(node,"navigator");
_navigations.push(nc);
// We know that "Cube" node actually represents Skinned geometry, which means
// the motion is controlled by another skeleton node(s), in this case "lowerBack" node is
// root skeleton node( see source file)
nodename="lowerBack";
node=this.animator.source.find(nodename) as Node3d;
if (! node) {
trace("Failed to set Navigation control for node: " + nodename);
return;
}
var tarck_id:String;
var motionAlias:String;
// now we add a 'walking' motion which is represented by MotionGroup class instance with id == "lowerBack_motion"
// again, we know that by looking at source file.
// Notice that 'motion' is produced by different node that we created nvigation controlled, which in that case "cube"
tarck_id="lowerBack_motion";
motionAlias="walk";
if (! nc.addMotion(node,tarck_id,motionAlias)) {
trace("Failed to add Motion " + motionAlias + " for track: " + tarck_id);
return;
}
// another motion
motionAlias="jump";
tarck_id="lowerBack_motionjump";
if (! nc.addMotion(node,tarck_id,motionAlias)) {
trace("Failed to add Motion " + motionAlias + " for track: " + tarck_id);
return;
}
nc.position.x-= 5.0;
nc.rotation.x=0;
nc.rotation.y=0;
nc.rotation.z=1;
nc.rotation.w=30 * Math.PI / 180.0;
this.stage.addEventListener(KeyboardEvent.KEY_DOWN,this.keyDownHandler);
this.animator.play();
this.stage.addEventListener(KeyboardEvent.KEY_DOWN,this.keyDownHandler);
//-------------------------------------------------------------------------------------
In the keyDownHandler now we can call the movements of our model this way:
switch (event.keyCode) {
case 37 :// left
// start walking motion ant rotate model over 1/4 of motion cycle ( which is one step)
// in local coordinates by 30 degree rotation about Z
nc.run("walk",0.25,null,{x:0,y:0,z:1,w:30.0 * Math.PI / 180.0});
break;
case 38 :// up
// start walking motion by moving model over 1/4 of motion cycle ( which is one step)
// and propogation node forward in local coordinates by Y = -0.33
nc.run("walk",.25,{x:0,y:-1.0,z:0});
break;
case 39 :// right
// start walking motion ant rotate model over 1/4 of motion cycle ( which is one step)
// in local coordinates by 30 degree rotation about -Z
nc.run("walk",.25,null,{x:0,y:0,z:-1,w:30.0 * Math.PI / 180.0});
break;
//etc
//----------------------------------------------------------------------------------------------
As we can see, it's a little difficult to set the rotations if you are not familiar with some mathematical concepts..
This is a powerful framework that help us to blend animations smoothly, but i think that is has a high price when talking about performance and development speed, this one uses a lot of files, one per animation.
Next we will see another class that is much easier to use and implement, the DAEMC created by Pablo Bandin.
DAE MC
The DAE MC uses a diferent schema for animation and assets manipulation. this one uses the Collada .dae files.
COLLADA is a COLLAborative Design Activity for establishing an interchange file format for interactive 3D applications. COLLADA is managed by the not-for-profit technology consortium, the Khronos Group.
COLLADA defines an open standard XML schema for exchanging digital assets among various graphics software applications that might otherwise store their assets in incompatible file formats. COLLADA documents that describe digital assets are XML files, usually identified with a .dae (digital asset exchange) filename extension.
Tools and compatibility
COLLADA was intended originally as an intermediate format for transporting data from one digital content creation (DCC) tool to another. Applications exist to support that usage for several DCCs, including Maya (using ColladaMaya); 3ds Max (using ColladaMax); Poser (v.7.0); LightWave 3D (version 9.5); Cinema 4D (MAXON); Softimage|XSI; Side Effect's Houdini; MeshLab; SketchUp, Blender, modo and Strata 3D. COLLADA .dae files can be used in Adobe Photoshop software since version CS3. Game engines, such as Unreal engine, have also adopted this format.
Two open-source utility libraries are available to simplify the import and export of COLLADA documents: the COLLADA DOM and the FCollada library. The COLLADA DOM is generated at compile-time from the COLLADA schema. It provides a low-level interface that eliminates the need for hand-written parsing routines, but is limited to reading and writing only one version of COLLADA, making it difficult to upgrade as new versions are released. In contrast, Feeling Software's FCollada provides a higher-level interface and can import all versions of COLLADA. FCollada is used in ColladaMaya, ColladaMax, and several commercial game engines.
How to Use:
The fist thing we need to do is create our DAEMC object this way:
model=new DAEMC(true, "man", 30); // DAEMC(autoPlay:Boolean = true, name:String = null, fps:uint = 0)
then load the model and the texture:
model.load("modelo.DAE",new MaterialsList({scout_red:new BitmapFileMaterial("scout_flat.jpg",true)}));
scout_red is the name of the material in the 3dsMax.
then we need to add labels to the frames:
model.setFrameLabel(0,"idle");
model.setFrameLabel(11,"startWalk");
model.setFrameLabel(17,"loopWalk");
then we create loops adding code to certain frames:
model.addFrameScript(10, loopIDLE);
model.addFrameScript(40, loopWALK);
after this, we can control the animations by simply going to the frame labels (or frame number) like this:
model.gotoAndPlay("startWalk");
model.gotoAndPlay("idle");
Definitely the DAEMC class is much easier to use than Cast3D framework, and can give solid rapid solutions to most frequent problems when we need to control cool animations on papervision3D.
Frazko..
AS Developer.
Resources:
CAST3D
Cast3D Simple tutorial:
http://www.cast3d.com/interact_tutor
DAE turorial
http://pablobandin.wordpress.com/2008/12/06/control-dae-animation/
DAE API:
http://code.google.com/p/daeanim/wiki/APIDocumentation
Installing the 3ds Max COLLADA Plugin:
http://update.multiverse.net/wiki/index.php/Installing_the_3ds_Max_COLLADA_Plugin
No hay comentarios:
Publicar un comentario