Sandy engine learning notes: import the md2 Model

Source: Internet
Author: User
Tags addchild

After Sandy upgraded to version 3.1, she added a model that supports importing md2, and finally made some progress. About the md2 model, I guess it is an animated model format. After Sandy upgrades version 3.1, it supports importing this format. The 3DS model can be imported before, but the efficiency is relatively poor, rendering is difficult if the calculation is larger. In terms of import, Sandy actually has a file class specifically responsible for external import, that is, the loaderqueue class.

 

In 3.0, loaderqueue can support IMG bin encoding import. Now we use it to import our md2 file. When using the loaderqueue class, we only need to create an instantiated object, as shown below:

 

Queue = new loaderqueue ();
Queue. Add ("man", new URLRequest ("bauul. md2"), "bin ");
Queue. Add ("manskin", new URLRequest ("bauul.jpg"), "IMG ");

 

...............

Queue. Start (); // start loading

Loading is a queue that can add more files.

 

Step 2: complete the listening. The listening process is actually listening for the event complete event. After loading is complete, an event is dispatched.

Queue. addeventlistener (sandyevent. queue_complete, loadmd2complete );

 

Sandyevent. queue_complete is the task of loading the listener.

 

 

To accomplish this, we need to prepare the md2 model. Import the data through the above method.

Package <br/> {<br/> Import flash. display. *; <br/> Import flash. events. *; <br/> Import flash. geom. point; <br/> Import flash. media. camera; <br/> Import flash.net. *; <br/> Import flash. utils. *; <br/> Import Sandy. util. *; <br/> Import Sandy. core. scene3d; <br/> Import Sandy. core. data. *; <br/> Import Sandy. core. scenegraph. *; <br/> Import Sandy. materials. *; <br/> Import Sandy. materials. attributes. *; <br/> Import sand Y. primitive. *; <br/> Import Sandy. events. *; <br/> Import mousedrager; </P> <p> public class example extends sprite <br/>{< br/> private var scene: scene3d; <br/> private var queue: loaderqueue; <br/> private var queueskin: loaderqueue; <br/> private var imp: md2; <br/> private var imp2: md2; <br/> private var num: Number = 3; <br/> private var point: point; <br/> private var camera: camera3d; <br/> private var MD: mousedr Ager; <br/> private var sprite: SPRITE; <br/> private var cotain: SPRITE; <br/> private var mybackground: bitmapdata = new background (0, 0 ); </P> <p> Public Function example () <br/>{< br/> cotain = new sprite (); <br/> addchild (cotain ); <br/> var bit: bitmap = new Bitmap (mybackground); <br/> sprite = new sprite; <br/> Sprite. addchild (BIT); <br/> addchild (sprite); <br/> queue = new loaderqueue (); <br/> queue. add ("man", new urlr Equest ("bauul. md2 ")," bin "); <br/> queue. add ("manskin", new URLRequest ("bauul.jpg"), "IMG"); <br/> queue. addeventlistener (sandyevent. queue_complete, loadmd2complete); <br/> queue. start (); <br/> camera = new camera3d (500,370); <br/> camera. lookat (0, 0, 0); </P> <p >}</P> <p> private function loadmd2complete (Event: Event ): void <br/> {<br/> var G: Group = new group; <br/> scene = new scene3d ("scene", cotain, camera, G ); <br/> im P = new md2 ("Imp", queue. data ["man"], 2); <br/> imp. X = 20; <br/> imp. y =-20; <br/> imp. z = 10; <br/> imp. rotatey =-90; <br/> // MD = new mousedrager (camera, IMP); <br/> // addeventlistener (mouseevent. mouse_down, MD. onmouseclick); <br/> // addeventlistener (mouseevent. mouse_up, MD. onmouseclick); <br/> // addeventlistener (mouseevent. mouse_move, MD. onmouseclick); <br/> // addeventlistener (mouseevent. mouse_out, MD. onmouseclick); <br /> Imp. appearance = new appearance (New bitmapmaterial (queue. data ["manskin"]. bitmapdata); <br/> G. addchild (IMP); <br/> addeventlistener (event. enter_frame, enterframehandler); <br/> This. swapchildrenat (0, 1); <br/>}< br/> private function enterframehandler (Event: Event): void <br/>{< br/> scene. render (); <br/> If (imp! = NULL) <br/>{< br/> imp. frame ++ = 0.3; <br/>}< br/> // Md. process (); <br/>}< br/>}

 

 

 

 

Remember that in the first program of sandy, when we create a model and perform rendering instantiation, the key is to convert the sandy object to the Flash displayobject class object, in this way, we can render the object to the Flash Player.

 

 

In general, when creating a sandy program, we need to create a scene3d object and create a camera camera3d (or another camera ),

You can add an object to a container as a Sprite object.

Like scene = new scene3d ("scene", cotain, camera, G), where cotain is the container we created. If you create a class that inherits the sprite object, cotain can be changed to this.

Scene = new scene3d ("scene", this, camera, G );

 

It is actually advantageous to add the model to the container. The key is that we map the background. If we use this to point to it, it is easy to make errors when switching the depth.

Add a statement to the program to display the interaction depth. You can make a background texture.

This. swapchildrenat (0, 1 );

 

Parse the program:

IMP = new md2 ("Imp", queue. data ["man"], 2); // a common model is introduced in analyticdb 3.1 with three parameters, the first name, the second binary data, and the third zoom.

Md2 (p_sname: String, data: bytearray, scale: Number = 1) creates md2 primitive.

 

It is very easy to create an md2 model. It is one of the common models under the Sandy. Primitive package. It can be easily created like box.

 

 

Map the md2 model:

Imp. Appearance = new appearance (New bitmapmaterial (queue. Data ["manskin"]. bitmapdata ));

If the following md2 model has a texture, You can map it. After loading the queue object, you can obtain the relevant information and map it.

 

Finally, you can play the md2 model during rendering.

Private function enterframehandler (Event: Event): void
{
Scene. Render ();
If (imp! = NULL)
{
Imp. Frame + = 0.3;
}
// Md. Process ();
}

 

It's cool to use its frmae attribute to play an animation? Haha

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.