|
MattIT, Newbie
Posted: 17 October 2012 05:12 PM Total Posts: 6
Hi everyone!!
I tried to load a model that I’ve made with Sketchup and then converted with prefab 3D.
I found online a simple (maybe) code to load the model but when I try by myself ( Flash CS4 Away3.6 ) it gave me those errors:
"TypeError: Error #1009: Impossibile accedere a una proprietà o a un metodo di un riferimento oggetto null. at away3d.loaders::Loader3D/notifySuccess() at away3d.loaders::Loader3D/notifyMaterialLibrary() at away3d.loaders::Loader3D/onParserComplete() at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at away3d.loaders::AbstractParser/notifySuccess() at away3d.loaders::AbstractParser/parseNext() at away3d.loaders::AbstractParser/parseGeometry() at away3d.loaders::Loader3D/loadTextures() at away3d.loaders::Loader3D$/parse() at away3d.loaders::AWData$/parse() at MyBSPProject/initAway3D() at MyBSPProject/init() TypeError: Error #1034: Assegnazione di tipo forzata non riuscita: impossibile convertire away3d.loaders::LoaderCube@54a8f331 in away3d.graphs.bsp.BSPTree. at MyBSPProject/initAway3D() at MyBSPProject/init()"
My model is a little bit heavy (11 MB model, 121 MB images)
Anyone can help me???
Thank you in advice!
|
MattIT, Newbie
Posted: 17 October 2012 05:13 PM Total Posts: 6
[ # 1 ]
Here’s the code!!!
package { // Class generated by Prefab3D. David Lenaerts & Fabrice Closier, 2011. import away3d.arcane; import away3d.cameras.lenses.PerspectiveLens; import away3d.containers.View3D; import away3d.core.base.Object3D; import away3d.core.clip.NearfieldClipping; import away3d.graphs.ITreeNode; import away3d.graphs.TreeIterator; import away3d.graphs.bsp.BSPNode; import away3d.graphs.bsp.BSPTree; import away3d.loaders.AWData; import away3d.physics.BSPCollider;
import flash.display.*; import flash.events.Event; import flash.events.KeyboardEvent; import flash.events.MouseEvent; import flash.geom.Vector3D; import flash.ui.Keyboard;
use namespace arcane;
//[SWF(frameRate="60", backgroundColor="0x000000", width="800", height="600")] public class MyBSPProject extends Sprite { [Embed(source="/Users/ASE/Desktop/MyClass/MyBSPTree/PrimaPart2/PrimaPart2.awd", mimeType="application/octet-stream")] private var BSPFile:Class;
private static const MOVE_SPEED:Number = 250; private static const JUMP_STRENGTH:Number = 300; private static const ACCELERATION:Number = 70; private static const RUN_MULTIPLIER:Number = 2; private static const GRAVITY:Number = 30; private static const FRICTION:Number = .3; private var _lastMouseX:Number; private var _lastMouseY:Number; private var _lastRotX:Number; private var _lastRotY:Number; private var _rotX:Number; private var _rotY:Number; private var _right:Boolean; private var _left:Boolean; private var _rotaccel:Number = 0.0; private var _tree:BSPTree; private var _view:View3D; private var _xDir:Number = 0.0; private var _zDir:Number = 0.0; private var _mouseDown:Boolean; private var _dragX:Number = 0; private var _dragY:Number = 0; private var _bspCollider:BSPCollider; private var _force:Vector3D = new Vector3D(); private var _flightMode:Boolean = false; private var _speedMultiplier:Number = 1.0; private var _noClip:Boolean = false;
public function MyBSPProject() { addEventListener(Event.ADDED_TO_STAGE, init); }
private function init(e:Event):void { initStage(); initAway3D(); } private function initStage():void { stage.scaleMode = StageScaleMode.NO_SCALE; stage.quality = StageQuality.LOW; stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyIsDown); stage.addEventListener(KeyboardEvent.KEY_UP, KeyIsUP); stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseIsDown); stage.addEventListener(MouseEvent.MOUSE_UP, onMouseIsUp); }
private function initAway3D():void { _view = new View3D({x: stage.stageWidth*.5, y: stage.stageHeight*.5, clipping: new NearfieldClipping()}); _view.camera.lens = new PerspectiveLens(); _view.camera.zoom = 10; _view.camera.x = 0; _view.camera.y = 0; _view.camera.z = 0; _view.camera.rotationX = 0; _view.camera.rotationY = 0; _view.camera.rotationZ = 0;
_tree = BSPTree(AWData.parse(new BSPFile(), {customPath:"./images/"})); _view.scene.addChild(_tree); _tree.usePVS = true;
_bspCollider = new BSPCollider(_view.camera, _tree); _bspCollider.testMethod = BSPTree.TEST_METHOD_ELLIPSOID; _bspCollider.flyMode = _flightMode; _bspCollider.maxClimbHeight = 50; _bspCollider.maxIterations = 4;
_bspCollider.minBounds = new Vector3D(-80,-145,-80); _bspCollider.maxBounds = new Vector3D(77,41,72);
addChild(_view); addEventListener(Event.ENTER_FRAME, onEnterFrame); }
private function KeyIsDown(event:KeyboardEvent):void { switch(event.keyCode) { case 90: case 87: case Keyboard.UP: _zDir = 1; break; case 83: case Keyboard.DOWN: _zDir = -1; break; case 81: case 65: case Keyboard.LEFT: _xDir = -1; break; case 68: case Keyboard.RIGHT: _xDir = 1; break; case Keyboard.SPACE: if(_bspCollider && _bspCollider.onSolidGround) _force.y = JUMP_STRENGTH; break; case Keyboard.SHIFT: _speedMultiplier = RUN_MULTIPLIER; break } }
private function KeyIsUP(event:KeyboardEvent):void { switch(event.keyCode) { case 90: case 87: case 83: case Keyboard.UP: case Keyboard.DOWN: _zDir = 0; break; case 65: case 81: case Keyboard.LEFT: case 68: case Keyboard.RIGHT: _xDir = 0; break; case Keyboard.ENTER: _tree.usePVS = !_tree.usePVS; break; case Keyboard.SHIFT: _speedMultiplier = 1; break; case Keyboard.F1: _noClip = !_noClip; break } }
private function onEnterFrame(event:Event):void { var maxSpeed:Number = MOVE_SPEED*_speedMultiplier; if(_mouseDown){ _rotX = _lastMouseX - (mouseY - _lastRotY)*0.7; _rotY = _lastMouseY + (mouseX - _lastRotX)*0.7;
if(_rotX > 90) _rotX = 70; if(_rotX < -90) _rotX = -70; _view.camera.rotationX += (_rotX - _view.camera.rotationX)/4; _view.camera.rotationY += (_rotY - _view.camera.rotationY)/4; }
if(_noClip || !_bspCollider) { _view.camera.moveForward(_zDir*maxSpeed); } else { var dx:Number = _xDir*ACCELERATION; var dz:Number = _zDir*ACCELERATION;
_force.x += dx; _force.z += dz; if(_force.x > maxSpeed || _force.x < -maxSpeed) _force.x -= dx; if(_force.z > maxSpeed || _force.z < -maxSpeed) _force.z -= dz;
if(_flightMode) { _bspCollider.move(_xDir * maxSpeed, 0, _zDir * maxSpeed); } else { _force.y = _bspCollider.move(_force.x, _force.y, _force.z).y; _force.x /= (1+FRICTION); _force.z /= (1+FRICTION); _force.y -= GRAVITY; } } _view.render(); }
private function onMouseIsDown(event:MouseEvent):void { _lastMouseX = _view.camera.rotationX; _lastMouseY = _view.camera.rotationY; _lastRotX = mouseX; _lastRotY = mouseY; _mouseDown = true; _dragX = mouseX; _dragY = mouseY; }
private function onMouseIsUp(event:MouseEvent):void { _mouseDown = false; } } }
|
Fabrice Closier, Administrator
Posted: 18 October 2012 08:42 AM Total Posts: 1265
[ # 2 ]
If you set preview option on into the BSP generator panel, render with zero errors and once files are saved wait bits. Does the preview starts and display correctly?
|
MattIT, Newbie
Posted: 18 October 2012 09:50 AM Total Posts: 6
[ # 3 ]
Thank you Fabrice!
Well, actually I just exported the file awd with Prefab Version 2, didn’t try the BSP generator…also because I didn’t have something like these in my Prefab version! Sorry I’m a newbie in Prefab!
I will try to load my model in Prefab version 1 and I will report!
|
MattIT, Newbie
Posted: 18 October 2012 12:11 PM Total Posts: 6
[ # 4 ]
Famous last words!
Prefab version 1 don’t let me load my original obj model then crashes on 3ds and collada when I try to load big files.
But I’ve tried (for the first time) to load my file.awd that I’ve exported from prefab (v2) again into prefab (v2)...and It says that there’s a issues with all my meshes, like the uv are out of bounds.
I’m wondering if is that the problem?
I can solve the problem by changing the code that loads model??
And a little bit OT: if I want to use Away 3.6 (cause of Flash 10) I can’t use prefab v2?
Thanks in advice!
|
Fabrice Closier, Administrator
Posted: 18 October 2012 01:00 PM Total Posts: 1265
[ # 5 ]
Ok, lets rewind a bit:
The above class is the output class from Prefab1 BSP/PVS generator.
The compagnon awd1 file that comes with this export is special.
It holds a complex description of the original scenery and is dedicated to the bsp reader classes in 3.5 and 3.6.
The class will run perfectly with any valid awd1 files with the same expected description, “regular” ones will not! by regular I mean any exported awd1 that was not generated by the BSP generator.
It looks to me that you have found somewhere some bsp example sources, and that the plan was to change the awd1 with your file and that all would run as in the example that you found. It won’t.
If you want to generate a bsp file (awd1) that loads you need to go thru the generator. This can only be done in Prefab 1.
To load your files into prefab, if they are correctly triangulated, you can use any of the 3.6 supported formats. Tho, it’s is more friendly to use Prefab2 and export as awd1. This file will load in Prefab1.
But, to generate a BSP file you have to feed the generator with a BSP suitable geometry. This is a very strict process modeling wize. One single vertex misplaced and you hang. Prefab will warn you or cancel if the errors are too big. Depending on geometry definition, precalculating everything can take few seconds up to hours.
|
Fabrice Closier, Administrator
Posted: 18 October 2012 01:03 PM Total Posts: 1265
[ # 6 ]
Forgot to add: the uvs out bounds warning means that some meshes have uv values either lower than 0 or greater than 1. To render propperly repeat must be set to true. Prefab does this for you and tells you who was affected. No changes are made to the uvs.
|