sorry my bad, there was an error in my code... O_o Works great thanks!
I haven't come across sceneTransform before, what does it do? On Apr 13, 4:30 pm, colouredfunk <[email protected]> wrote: > Thanks for your reply.. > > It sort of works but it jumps around on certain spins of the cube.. > > Here is the code I'm using > > package > { > > import away3d.cameras.HoverCamera3D; > import away3d.containers.ObjectContainer3D; > import away3d.containers.Scene3D; > import away3d.containers.View3D; > import away3d.core.base.Mesh; > import away3d.core.session.SpriteSession; > import away3d.events.MouseEvent3D; > import away3d.primitives.Cube; > import away3d.primitives.Plane; > import com.thecoconutstudio.library.away3d.CameraSpin3D; > import com.thecoconutstudio.library.away3d.ObjectSpin; > import com.thecoconutstudio.library.controls.Image; > import flash.filters.GlowFilter; > //mport away3d.core.math.Number3D; > import away3d.debug.AwayStats; > import away3d.materials.BitmapMaterial; > import away3d.materials.GlassMaterial; > import away3d.primitives.Skybox6; > import away3d.primitives.Sphere; > import away3d.primitives.Torus; > import away3d.primitives.TorusKnot; > import away3d.core.utils.Cast; > import away3d.primitives.TextField3D; > import wumedia.vector.VectorText; > import away3d.materials.ColorMaterial; > import com.thecoconutstudio.library.away3d.AwayObjectControl > import flash.geom.Vector3D; > > import flash.display.Bitmap; > import flash.display.BitmapData; > import flash.display.Sprite; > import flash.events.Event; > import flash.events.MouseEvent; > import flash.text.TextField; > import com.greensock.*; > import com.greensock.easing.*; > > [SWF(width="1280", height="720", frameRate="40", > backgroundColor="0x000000")] > public class InteractiveCube extends Sprite > { > private const GLASS_COLOURS : Array = [ 0xffffff, 0x10aa20, > 0xff1020, 0xff1020 ]; > private const ENV_MAP_ALPHAS : Array = [ .25, .4, .6, .75 ]; > private const CHROMATIC_ABERRATION : Array = [ true, true, > false, > false ]; > private var _scene:Scene3D; > private var _camera:CameraSpin3D > private const CAMERA_DISTANCE : Number = 1000; > > //fonts > [Embed(source="../assets/fonts.swf", > mimeType="application/octet- > stream")] > public var FontBytes:Class; > > // source textures > [Embed(source="../assets/cube6hills.jpg")] > private const SKY_BOX : Class; > > [Embed(source="../assets/sphereMap_hills.jpg")] > private const SPHERE_MAP : Class; > > [Embed(source="../assets/sphereNormals.png")] > private const SPHERE_NORMALS : Class; > > [Embed(source="../assets/torusNormals.png")] > private const TORUS_NORMALS : Class; > > [Embed(source="../assets/knotNormals.png")] > private const KNOT_NORMALS : Class; > > [Embed(source="../assets/face.png")] > private const FACE_NORMALS : Class; > > [Embed(source="../assets/cube_sports.jpg")] > private const FACE_SPORTS : Class; > > [Embed(source="../assets/cube_evidence.jpg")] > private const FACE_EVIDENCE : Class; > > [Embed(source="../assets/cube_product.jpg")] > private const FACE_PRODUCT : Class; > > [Embed(source="../assets/cube_services.jpg")] > private const FACE_SERVICES : Class; > > [Embed(source="../assets/cube_studio.jpg")] > private const FACE_STUDIO : Class; > > [Embed(source="../assets/cube_ob.jpg")] > private const FACE_OB : Class; > > private const CAM_TARGET : Vector3D = new Vector3D(0, 0, 0); > > private var _view : View3D; > private var _sign : Bitmap; > > private var _count : int; > > private var _models : Array; > private var _materials : Array; > > private var _envMap : BitmapData; > > private var _cube:Mesh; > private var _move:Boolean > private var _currentFace:Plane > private var _cubeHolder:ObjectContainer3D; > private var _session:SpriteSession; > private var _spinner:ObjectSpin; > private var _line:Sprite; > private var _sphere:Sphere > public function InteractiveCube() > { > initData(); > initView(); > iniListeners() > } > > private function initData():void > { > _models = []; > _materials = []; > _envMap = new SPHERE_MAP().bitmapData; > _session = new SpriteSession(); > _session.screenZ = 8 > } > > private function iniListeners():void > { > addEventListener( Event.ENTER_FRAME, onEnterFrame ); > //_cube.addOnMouseDown(MouseDown); > addEventListener(MouseEvent.MOUSE_DOWN, MouseDown); > addEventListener(MouseEvent.MOUSE_UP, MouseUp); 0 > _view.render(); > } > private function MouseDown(e:MouseEvent):void > { > _spinner.register(); > _move = true; > } > > private function MouseUp(e:MouseEvent):void > { > _move = false; > } > > private function initView() : void > { > > var bg:Image = new Image() > bg.load("cube6hills.jpg") > addChild(bg) > _scene = new Scene3D(); > _camera = new CameraSpin3D(stage); > _camera.zoom = 10 > _camera.steps = 5 > _camera.yfactor = 1; > _camera.position = new Vector3D(-4.327301979064941, > 799.541259765625, 26.740442276000977) > _view = new View3D(); > _view.scene = _scene; > _view.camera = _camera; > _view.x = stage.stageWidth * .5; > _view.y = stage.stageHeight * .5; > addChild(_view); > setDemoCycle(1); > } > private function setDemoCycle(index:int):void > { > var cubeSize:Number = 220 > _cubeHolder = new ObjectContainer3D(); > _cube = new Cube( { width: cubeSize, height:cubeSize, > depth:cubeSize, segmentsH: 10, segmentsW: 15 } ); > _cube.pushback = true; > var session:SpriteSession = new SpriteSession(); > session.screenZ = 10 > var normalMap : BitmapData = new > FACE_NORMALS().bitmapData; > _cube.material = new GlassMaterial( normalMap, > _envMap, _cube, > CHROMATIC_ABERRATION[1], > > { envMapAlpha: ENV_MAP_ALPHAS[1], > > innerRefraction: 2, > > glassColor: GLASS_COLOURS[1], > > smooth: true > > } > ); > _cubeHolder.addChild(_cube); > var faceSize:Number = (cubeSize / 2) + 1; > var plane:Plane = createCubeFace(180, FACE_SPORTS); > _currentFace = plane; > plane.position = new Vector3D(0, faceSize, 0); > plane.rotationX = 0; > plane.rotationY = 0; > //// > plane = createCubeFace(180, FACE_STUDIO); > plane.position = new Vector3D(-faceSize, 0, 0); > plane.rotationX = 90; > plane.rotationY = 90; > /// > plane = createCubeFace(180, FACE_EVIDENCE); > plane.position = new Vector3D(faceSize, 0, 0); > plane.rotationX = 90; > plane.rotationY = -90; > /// > plane = createCubeFace(180, FACE_PRODUCT); > plane.position = new Vector3D(0, 0, faceSize); > plane.rotationX = 90; > plane.rotationY = 180; > /// > plane = createCubeFace(180, FACE_SERVICES); > plane.position = new Vector3D(0, 0, -faceSize); > plane.rotationX = 90; > plane.pushfront = true; > /// > plane = createCubeFace(180, FACE_OB); > plane.position = new Vector3D(0, -faceSize, 0); > plane.rotationX = 180; > _view.scene.addChild(_cubeHolder); > _camera.lookAt(_cube.position); > _sphere = new Sphere(); > _sphere.radius = 50; > _view.scene.addChild(_sphere); > _spinner = new ObjectSpin(this, _cubeHolder); > > } > > private function onEnterFrame(event : Event) : void > { > if (_move) { > _spinner.spin(); > var tl:Vector3D = new Vector3D( > -_currentFace.width*0.5, 0, - > _currentFace.height*0.5); //top > var vtxPos:Vector3D = > _currentFace.sceneTransform.transformVector(tl); > _sphere.position = vtxPos > } else { > } > _camera.hover(); > _view.render(); > _view.render(); > } > > private function createCubeFace(size:Number, > material:Class):Plane > { > var plane:Plane = new Plane( { width:size, > height:size, > material:material } ); > plane.mouseEnabled = true; > //plane.addOnRollOver(onCubeFaceOver); > //plane.addOnRollOut(onCubeFaceOut); > plane.ownCanvas = true; > plane.pushfront = true; > //plane.ownSession = _session; > _cubeHolder.addChild(plane); > return plane > } > } > > } > > On Apr 13, 3:41 pm, John Brookes <[email protected]> wrote: > > > > > > > > > Assuming "p1" is your plane then the world position of the top left > > > var tl:Vector3D = new Vector3D( -p1.width*0.5, 0, -p1.height*0.5); //top > > left > > > var vtxPos:Vector3D = p1.sceneTransform.transformVector(tl); > > > best way to check is to add a sphere to to the scene at that "vtxPos" > > position.
