纳金网
标题:
Flash3D学习——Sandy学习笔记 [14]
[打印本页]
作者:
.
时间:
2012-8-27 11:15
标题:
Flash3D学习——Sandy学习笔记 [14]
导入3ds格式文件,通过网络加载3DS文件。
不做什么说明了,我对3dsMAX不了解,这里只是做个了解。
代码:
package
{
import flash.display. * ;
import flash.events. * ;
import flash.ui. * ;
import flash.net.URLRequest;
import sandy.core.Scene3D;
import sandy.core.data. * ;
import sandy.core.scenegraph. * ;
import sandy.materials. * ;
import sandy.materials.attributes. * ;
import sandy.primitive. * ;
import sandy.parser. * ;
import sandy.util. * ;
import sandy.events. * ;
/**
* ...
* @author ever5u
*/
public class fuxi extends Sprite
{
private var scene:Scene3D;
private var camera:Camera3D;
private var rifle:Shape3D;
private var queue
oaderQueue;
private var parserStack
arserStack;
public function fuxi()
{
var parser:IParser = Parser.create("http://www.flashsandy.org/max/asset/mar_rifle.3ds" , Parser.MAX_3DS , 1 , "JPG");
parserStack = new ParserStack();
parserStack.add("rifle" , parser);
parserStack.addEventListener(ParserStack.COMPLETE , parserComplete );
parserStack.start();
}
private function onError( pEvt
arserEvent ):void
{
trace("there is an error in loading your stuff");
}
private function parserComplete(pEvt:Event ):void
{
rifle = parserStack.getGroupByName("rifle").children[0] as Shape3D;
var root:Group = createScene();
camera = new Camera3D( 300 , 300 );
camera.y = 5;
camera.z = - 150;
scene = new Scene3D( "scene" , this , camera , root );
addEventListener( Event.ENTER_FRAME , enterFrameHandler );
stage.addEventListener(KeyboardEvent.KEY_DOWN , keyPressedHandler);
}
private function createScene():Group
{
var g:Group = new Group();
rifle.x = 0;
rifle.y = 0;
rifle.pan = - 30;
g.addChild(rifle);
return g;
}
private function keyPressedHandler(event:flash.events.KeyboardEvent):void
{
switch(event.keyCode)
{
case Keyboard.UP:
rifle.roll += 5;
break;
case Keyboard.DOWN:
rifle.roll -= 5;
break;
case Keyboard.LEFT:
rifle.pan -= 5;
break;
case Keyboard.RIGHT:
rifle.pan += 5;
break;
}
}
private function enterFrameHandler( event : Event ) : void
{
scene.render();
}
}
}
欢迎光临 纳金网 (http://rs.narkii.com/club/)
Powered by Discuz! X2.5