Papervision3D: understanding Plane object – part 5
2009-10-21 00:00:00 来源:WEB开发网 闂傚倸鍊搁崐鎼佸磹閹间礁纾归柟闂寸绾惧綊鏌熼梻瀵割槮缁炬儳缍婇弻鐔兼⒒鐎靛壊妲紒鐐劤缂嶅﹪寮婚悢鍏尖拻閻庨潧澹婂Σ顔剧磼閹冣挃闁硅櫕鎹囬垾鏃堝礃椤忎礁浜鹃柨婵嗙凹缁ㄧ粯銇勯幒瀣仾闁靛洤瀚伴獮鍥敍濮f寧鎹囬弻鐔哥瑹閸喖顬堝銈庡亝缁挸鐣烽崡鐐嶆棃鍩€椤掑嫮宓佸┑鐘插绾句粙鏌涚仦鎹愬闁逞屽墰閹虫捇锝炲┑瀣╅柍杞拌兌閻ゅ懐绱撴担鍓插剱妞ゆ垶鐟╁畷銉р偓锝庡枟閻撴洘銇勯幇闈涗簼缂佽埖姘ㄧ槐鎾诲礃閳哄倻顦板┑顔硷工椤嘲鐣烽幒鎴旀瀻闁规惌鍘借ⅵ濠电姷鏁告慨顓㈠磻閹剧粯鈷戞い鎺嗗亾缂佸鏁婚獮鍡涙倷閸濆嫮顔愬┑鐑囩秵閸撴瑦淇婇懖鈺冪<闁归偊鍙庡▓婊堟煛鐏炵硶鍋撻幇浣告倯闁硅偐琛ラ埀顒冨皺閺佹牕鈹戦悙鏉戠仸闁圭ǹ鎽滅划鏃堟偨缁嬭锕傛煕閺囥劌鐏犻柛鎰ㄥ亾婵$偑鍊栭崝锕€顭块埀顒佺箾瀹€濠侀偗婵﹨娅g槐鎺懳熺拠鑼舵暱闂備胶枪濞寸兘寮拠宸殨濠电姵纰嶉弲鎻掝熆鐠虹尨宸ョ€规挸妫濆铏圭磼濡搫顫嶇紓浣风劍閹稿啿鐣烽幋锕€绠婚悹鍥у级瀹撳秴顪冮妶鍡樺鞍缂佸鍨剁粋宥夋倷椤掍礁寮垮┑鈽嗗灣閸樠勭妤e啯鍊垫慨妯煎亾鐎氾拷

This is the time to add textures to our plane from a movieclip.
Since I am making a card game, I want to store all cards in a single movieclip and assign each frame to a different plane.
At the moment I have only two frames, one with the front and one with the back of the card, because the creation of the “perfect card” is not over yet…
I am attaching the commented code, and please notice I NEVER add the card clip on the stage using addChild
All the uncommented code has been explained from part 1 to 4
package {
import flash.display.Sprite;
import flash.events.Event;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.events.InteractiveScene3DEvent;
public class papervision extends Sprite {
// this is the movieclip with the cards... currently it holds
// only two cards... the back and the 10 of hearts
public var my_card:card = new card();
public var viewport:Viewport3D=new Viewport3D(500,400,false,true);
public var scene:Scene3D = new Scene3D();
public var camera:Camera3D = new Camera3D();
public var renderer:BasicRenderEngine = new BasicRenderEngine();
// now it's time to use Movie Materials... we can use a movieclip as a material
public var front_material:MovieMaterial;
public var back_material:MovieMaterial;
public var front_plane:Plane;
public var back_plane:Plane;
public var rotation_speed=0;
public var steps=0;
public function papervision() {
// going to frame 2
my_card.gotoAndStop(2);
// assigning the 2nd frame to front_material material
front_material=new MovieMaterial(my_card);
// going to frame 1...
my_card.gotoAndStop(1);
// and assign the 1st frame as material of the back_material material
back_material=new MovieMaterial(my_card);
front_plane=new Plane(front_material,200,250,4,5);
back_plane=new Plane(back_material,200,250,4,5);
addChild(viewport);
camera.focus=100;
camera.zoom=10;
back_plane.rotationY=180;
front_material.interactive=true;
back_material.interactive=true;
scene.addChild(front_plane);
scene.addChild(back_plane);
back_plane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,on_plane_clicked);
front_plane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,on_plane_clicked);
addEventListener(Event.ENTER_FRAME, render);
}
public function render(e:Event) {
if (rotation_speed) {
steps++;
front_plane.yaw(rotation_speed);
back_plane.yaw(rotation_speed);
}
if (steps==180/rotation_speed) {
steps=0;
rotation_speed=0;
}
renderer.renderScene(scene, camera, viewport);
}
public function on_plane_clicked(e:InteractiveScene3DEvent) {
if (steps==0) {
rotation_speed=4;
}
}
}
}
And this is the result:
Click on the card to flip it.
Tags:PapervisionD understanding Plane
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接