After one morning's study, I felt that the as3.0 released by Sandy was really powerful. I read some official introductions and made it available.
- Package
- {
- Import flash. display. Sprite;
- Import flash. Events .*;
- Import Sandy. Core. scene3d;
- Import Sandy. Core. scenegraph .*;
- Import Sandy. Primitive .*;
- Import Sandy. Core. Data .*;
- Import Sandy. Materials .*;
- Import Sandy. Materials. Attributes .*;
- Import flash. display. bitmapdata;
- Import flash. display. Bitmap;
- Import flash. UI. keyboard;
- Public class dd extends Sprite
- {
- Private var scence: scene3d;
- Private var camera: camera3d;
- Private var box: box;
- Private var rot: Int = 45;
- Private var IMG: mypic;
- Private var bitmap: bitmap;
- Private var up: Boolean;
- Private var down: Boolean;
- Private var left: Boolean;
- Private var right: Boolean;
- Public Function dd ()
- {
- IMG = new mypic (0, 0 );
- Bitmap = new Bitmap (IMG );
- Camera = new camera3d (500,400); // create a camera
- Camera. z =-400;
- VaR Group: Group = createscence ();
- Scence = new scene3d ("scene1", this, camera, group); // create a scenario
- Scence. Root. addchild (CAMERA );
- Addeventlistener (event. enter_frame, run );
- Stage. addeventlistener (keyboardevent. key_down, keydown );
- Stage. addeventlistener (keyboardevent. key_up, keyup );
- Stage. addeventlistener (event. enter_frame, runing );
- }
- Private function createscence (): Group
- {
- // Add Material
- // Step 1: Set material attributes
- VaR materia: materialattributes = new materialattributes (
- New lightattributes (true, 0.3 ),
- New lineattributes (1, 0x2111bb, 1)
- );
- // Step 2: Set material attributes
- VaR material: Material = new colormaterial (0xffcc33, 1, materia); // display color material attributes
- VaR material: Material = new bitmapmaterial (bitmap. bitmapdata); // display color material attributes
- Material. lightingenable = true;
- Material. lightingenable = true;
- VaR app: appearance = new appearance (material); // specify the material to the visual object.
- VaR app2: appearance = new appearance (material); // specifies the texture of a visible object.
- VaR G: Group = new group ();
- Box = new box ("mybox", 100,100,100 );
- Box. Appearance = app;
- Box. Appearance = app2;
- G. addchild (box );
- Return g;
- }
- Private function run (Event: Event): void
- {
- Box. rotatex = rot;
- Box. rotatey = 45;
- Rot + = 1;
- Scence. Render (); // Rendering scenario
- }
- Private function keydown (Event: keyboardevent): void
- {
- Switch (event. keycode)
- {
- Case keyboard. Up:
- Up = true;
- Break;
- Case keyboard. down:
- Down = true;
- Break;
- Case keyboard. left:
- Left = true;
- Break;
- Case keyboard. Right:
- Right = true;
- Break;
- }
- }
- Private function keyup (Event: keyboardevent): void
- {
- If (event. keycode = keyboard. UP)
- {
- Up = false;
- } Else if (event. keycode = keyboard. down)
- {
- Down = false;
- } Else if (event. keycode = keyboard. Left)
- {
- Left = false;
- } Else if (event. keycode = keyboard. Right)
- {
- Right = false;
- } Else
- {
- }
- }
- Private function runing (Event: Event): void
- {
- If (up)
- {
- Camera. Z + = 8;
- // Camera. scaley + = 4;
- } Else if (down)
- {
- Camera. Z-= 8;
- } Else if (left)
- {
- Camera. Pan + = 2;
- } Else if (right)
- {
- Camera. Pan-= 2;
- } Else
- {
- }
- }
- }
- }
I feel pretty good. I have Paster this image, and the 3D effect has come out. With the camera added, the effect is good.
However, I feel that 3D computing is huge. When I scale up this item, the CPU usage is much higher. If you are interested, you can download the class library from the official website and help documentation.
This is not a toy, but flash lovers will remember it.