在Sandy引擎里面,我们可以对其进行多维贴图,Box类就是一个典型的例子。它可以进行多面的贴图,对六个面进行不同的贴图效果,做法很简单,仅仅在呈现表面的时候,选择不同的面,赋予不同的表面这样一个简单的效果就出来了。
在Box类里面有getFace这样的方法,他可以返回PrimitiveFace的类型,这个类型里面有一个appearance 的属性,使用这个属性我们就可以赋予不同面的方式。
getFace(p_nFace:uint): PrimitiveFace
Returns a PrimitiveFace object ( an array of polygons ) defining the specified face.
简单的流程:
在flash里面内嵌几张图片,把位图作为链接处理
这里仅仅作为演示的使用,改名为Face1---Face5
对于不同的面,我们首先要做一些简单处理,准备多张的贴图如下
private var skin1:BitmapData=new Face1(0,0);
var material1:BitmapMaterial=new BitmapMaterial(skin1);
var app1:Appearance = new Appearance( material1);//为物体创建材质表面
box.getFace(0).appearance = app1;//指定材质表面
...................方法一样。
这样我们就可以为Box创建不同的贴图,
演示地址: http://blog.5d.cn/user45/hero82748274/Category/148744.html
代码清单:
<textarea cols="50" rows="15" name="code" class="c-sharp">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 sandy.core.scenegraph.mode7.*; import flash.ui.Keyboard; import flash.display.Bitmap; import flash.display.BitmapData; public class My3D2 extends Sprite { private var scenne:Scene3D; private var camera:CameraMode7; private var ranY:Number=0.5; private var box:Box; private var skin1:BitmapData=new Face1(0,0); private var skin2:BitmapData=new Face2(0,0); private var skin3:BitmapData=new Face3(0,0); private var skin4:BitmapData=new Face4(0,0); private var skin5:BitmapData=new Face5(0,0); private var skin6:BitmapData=new Face6(0,0); private var _leftPush:Number=0; private var _rightPush:Number=0; private var _upPush:int=0; private var _downPush:int=0; public function My3D2() { camera=new CameraMode7(400,400);//设定摄影机大小和位置 camera.x = 0; camera.y = 100; camera.z = -200; camera.tilt = 20; 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); var material1:BitmapMaterial=new BitmapMaterial(skin1); var material2:BitmapMaterial=new BitmapMaterial(skin2); var material3:BitmapMaterial=new BitmapMaterial(skin3); var material4:BitmapMaterial=new BitmapMaterial(skin4); var material5:BitmapMaterial=new BitmapMaterial(skin5); var material6:BitmapMaterial=new BitmapMaterial(skin6); material1.lightingEnable = true; material2.lightingEnable = true; material3.lightingEnable = true; material4.lightingEnable = true; material5.lightingEnable = true; material6.lightingEnable = true; var app1:Appearance = new Appearance( material1);//为物体创建材质表面 var app2:Appearance = new Appearance( material2 );//为物体创建材质表面 var app3:Appearance = new Appearance( material3);//为物体创建材质表面 var app4:Appearance = new Appearance( material4 );//为物体创建材质表面 var app5:Appearance = new Appearance( material5);//为物体创建材质表面 var app6:Appearance = new Appearance( material6 );//为物体创建材质表面 box.rotateX=10; box.rotateY=0; box.getFace(0).appearance = app1;//指定材质表面 box.getFace(1).appearance = app2;//指定材质表面 box.getFace(2).appearance = app3;//指定材质表面 box.getFace(3).appearance = app4;//指定材质表面 box.getFace(4).appearance = app5;//指定材质表面 box.getFace(5).appearance = app6;//指定材质表面 camera.lookAt(box.x,box.y,box.z); g.addChild(box); return g; } private function Run(event:Event):void { scenne.render(); box.rotateX+=1;//让立方体会在x轴上旋转 box.rotateY+=1;//让立方体会在y轴上旋转 // keyPress(); } } }</textarea>