因为好多人说不会用引擎,而我也较忙,只能暂时先给demo补充一些中文说明供大家参考。我争取尽快补充文档。感谢大家对本引擎的支持。svn上面已经更新。
/**
* NewX3D
*
* AUTHOR: Ma Chao
* EMAIL: machaoii@263.net
* MSN: machaoii@hotmail.com
* QQ: 68552233
* _____________________________________________________________
* http://newx3d.cn/blog http://code.google.com/p/newx3d/
*
* Copyright 2008 Ma Chao
Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
{
import cn.newx.camera.Camera3D;
//import cn.newx.data.Vector4D;
import cn.newx.data.ZBuffer;
import cn.newx.geometry.DAE;
import cn.newx.materials.MaterialManager;
import cn.newx.render.NXZBufferRender;
import cn.newx.utils.FPS;
import flash.display.Sprite;
import flash.events.*;
import flash.geom.Vector3D;
//[SWF (width='400',height='400',backgroundColor='0x000000',frameRate='120')]
public class DAETest extends Sprite
{
//声明dae模型
private var dae:DAE;
//声明相机
private var cam:Camera3D;
//定义相机坐标x,y,z
private var cam_pos:Vector3D=new Vector3D(0,0,-50);
//定义相机朝向x,y,z
private var cam_dir:Vector3D=new Vector3D(0,0,20);
//声明显示模型的容器
private var sprite:Sprite;
//声明z缓冲
private var zbuffer:ZBuffer;
//声明材质管理器
private var mm:MaterialManager;
//声明渲染引擎
private var render:NXZBufferRender;
//下面几个都是让球按不同速度转的数据
private var r:int=0;
private var xsignal:int=1;
private var ysignal:int=1;
private var zsignal:int=1;
public function DAETest()
{
sprite=new Sprite();
this.addChild(sprite);
//初始化相机,参数分别为位置,朝向,视口宽度,视口高度
cam=new Camera3D(cam_pos, cam_dir, 400, 400);
//初始化z缓冲,参数为视口宽度,视口高度
zbuffer=new ZBuffer(400,400);
//初始化材质管理器
mm=new MaterialManager();
//初始化dae模型,参数为模型的路径
dae=new DAE(”texture/shuilei.dae”);
//设置材质文件路径(引擎自动识别材质文件名,只需要提供路径即可),默认为和swf在同一目录下。
dae.setMaterialFolder(”texture/”);
//连接相机(必须要有)
dae.attachCam(cam);
//连接材质管理器(必须要有)
dae.attachMaterialManager(mm);
//dae.singnal()是模型的事件发生器,这里表示模型加载完毕的事件。
dae.signal().addEventListener(Event.COMPLETE,doRender)
//载入模型
dae.load();
var fps:FPS=new FPS();
this.addChild(fps);
}
public function doRender(ev:Event):void{
//初始化渲染引擎,参数为dae模型,显示模型的容器,材质管理器,z缓冲,是否平滑处理。
render=new NXZBufferRender(dae,sprite,mm,zbuffer,cam,true);
this.addEventListener(Event.ENTER_FRAME,xxx);
}
private function xxx(ev:Event):void{
//var speed:int=Math.round(Math.random()*10);
//dae.getChildByName(”objpolySurface31″)。如果一个dae文件里面有多个模型,系统会把它们自动加载为dae的child。其中的name就是你在3dmax里面设置的几何体的name.
//这样可以让你轻松操作单个几何体。
dae.getChildByName(”objpolySurface31″).rotationY(5);
dae.getChildByName(”objpolySurface31″).rotationX(5);
dae.getChildByName(”objpolySurface31″).rotationZ(5);
if(dae.getChildByName(”objpolySurface31″).x>50){
xsignal=-1;
}
else if(dae.getChildByName(”objpolySurface31″).x<-50){
xsignal=1;
}
if(dae.getChildByName(”objpolySurface31″).y>50){
ysignal=-1;
}
else if(dae.getChildByName(”objpolySurface31″).y<-40){
ysignal=1;
}
if(dae.getChildByName(”objpolySurface31″).z>80){
zsignal=-1;
}
else if(dae.getChildByName(”objpolySurface31″).z<10){
zsignal=1;
}
dae.getChildByName(”objpolySurface31″).x+=xsignal;
dae.getChildByName(”objpolySurface31″).y+=ysignal;
dae.getChildByName(”objpolySurface31″).z+=zsignal;
//执行渲染
render.render();
}
}
}