Q: How can I use Sandy's class library to create a cube?
First, we need to first understand the structure of the sandy class library.
We can see the class library table released on the official website above, which is easy to understand, such as Sandy. events and flash. event Events are similar. If we want to create a cube, we use Sandy. the primitive class package contains a box class, which mainly creates some simple models. This time we only need to use box
VaR mybox: box = new box ("thebox", 50,100,150, primitivemode. TRI, 2 );
This is a process of creation. Is it very simple? In fact, official documents are not well written. Fortunately, the official website provides code training and explanations. Good nonsense novels. The above creation is just a box class, mainly to create some cube and rectangular model. Ignore the last two parameters.
VaR mybox: box = new box ("thebox", 50,100,150 );
The first name, the second name, the third name, and the fourth name respectively indicate the length, width, and height.
- 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 .*;
- Public class my3d extends Sprite
- {
- Private var scenne: scene3d;
- Private var camera: camera3d;
- Private var rAny: Number = 0.5;
- Private var box: box;
- Public Function my3d ()
- {
- Camera = new camera3d (300,300 );
- Camera. z =-400;
- VaR root: Group = createscene ();
- Scenne = new scene3d ("scene1", this, camera, root );
- Addeventlistener (event. enter_frame, run );
- }
- Private function createscene (): Group
- {
- VaR G: Group = new group ();
- Box = new box ("box", 100,100,100 );
- Box. rotatex = 30;
- Box. rotatey = 30;
- G. addchild (box );
- Return g;
- }
- Private function run (Event: Event): void
- {
- Scenne. Render ();
- Box. rotatex = mousex;
- Box. rotatey = Mousey;
- }
- }
- }
You do not need to read the code for the moment. First, we understand the creation process. We create a scenario, a camera, a box, and a stage. Let's assume that this is the right creation process, and a photographic machine is placed in the scene according to our ideas. Locate in a position and watch at a position, which is the cube we want to observe.
It will be rendered in the scene before it can be displayed on the stage ..
It is such a process.
Note:
Import Sandy. Core. scene3d; // scenario
Import Sandy. Core. scenegraph. *; // responsible for graphics
Import Sandy. Primitive. *; // Simple Model
This time, we mainly used three packages of the sandy engine. Its creation process is like shooting by a director. Create a scenario, create a role, and render a scenario.
Well, next time we will learn about the camera, scene and texture maps, and advanced 3DS Model import.