Support - Forum aa
« Back to Support» MouseCollision don't work for ColladaLoader!!
Posted on 10.12.2011 by xfzhang, xfzhang
I loaded a dae file using scene.addChildFromFile function with ColladaLoader. Later when I want to process the mouse collision, FP11 gives me an error message:
TypeError: Error #1009: ????????????????
at flare.core::Mesh3D/get bounds()[Z:\projects\flare3d 2\src\flare\core\Mesh3D.as:195]
at flare.collisions::RayCollision/update()[Z:\projects\flare3d 2\src\flare\collisions\RayCollision.as:101]
at flare.collisions::RayCollision/test()[Z:\projects\flare3d 2\src\flare\collisions\RayCollision.as:74]
at flare.collisions::MouseCollision/test()[Z:\projects\flare3d 2\src\flare\collisions\MouseCollision.as:55]
at Flare3DTest/renderEvent()[C:\Users\admin\Adobe Flash Builder 4.5\Flare3DTest\src\Flare3DTest.as:103]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flare.basic::Scene3D/render()[Z:\projects\flare3d 2\src\flare\basic\Scene3D.as:585]
at flare.basic::Scene3D/enterFrameEvent()[Z:\projects\flare3d 2\src\flare\basic\Scene3D.as:489]
(Sorry if you dont understand chinese. The chinese characters above says:Can't access property or function of empty object reference)
If I use MouseEvent3D, no error message occurred but it just doesn't work and my callback function was never called!
But everything goes OK if I use f3d file.
I think this is a bug in ColladaLoader class , many thanks if you don't mind my poor English and can help me !!!!
TypeError: Error #1009: ????????????????
at flare.core::Mesh3D/get bounds()[Z:\projects\flare3d 2\src\flare\core\Mesh3D.as:195]
at flare.collisions::RayCollision/update()[Z:\projects\flare3d 2\src\flare\collisions\RayCollision.as:101]
at flare.collisions::RayCollision/test()[Z:\projects\flare3d 2\src\flare\collisions\RayCollision.as:74]
at flare.collisions::MouseCollision/test()[Z:\projects\flare3d 2\src\flare\collisions\MouseCollision.as:55]
at Flare3DTest/renderEvent()[C:\Users\admin\Adobe Flash Builder 4.5\Flare3DTest\src\Flare3DTest.as:103]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flare.basic::Scene3D/render()[Z:\projects\flare3d 2\src\flare\basic\Scene3D.as:585]
at flare.basic::Scene3D/enterFrameEvent()[Z:\projects\flare3d 2\src\flare\basic\Scene3D.as:489]
(Sorry if you dont understand chinese. The chinese characters above says:Can't access property or function of empty object reference)
If I use MouseEvent3D, no error message occurred but it just doesn't work and my callback function was never called!
But everything goes OK if I use f3d file.
I think this is a bug in ColladaLoader class , many thanks if you don't mind my poor English and can help me !!!!
Reply By xfzhang, xfzhang 10.12.2011
Here's my code snipet:
In construtor:
blablabla ....
gym = scene.addChildFromFile( "../resources/lhy_stadium/stadium.dae" , contentLayer ,ColladaLoader );
In loadCompleteEvent:
mouse = new MouseCollision();
mouse.addCollisionWith( gym );
In renderEvent:
if( mouse.test( Input3D.mouseX , Input3D.mouseY ) )
{
var info:CollisionInfo = mouse.data[0];
do something
}
In construtor:
blablabla ....
gym = scene.addChildFromFile( "../resources/lhy_stadium/stadium.dae" , contentLayer ,ColladaLoader );
In loadCompleteEvent:
mouse = new MouseCollision();
mouse.addCollisionWith( gym );
In renderEvent:
if( mouse.test( Input3D.mouseX , Input3D.mouseY ) )
{
var info:CollisionInfo = mouse.data[0];
do something
}
Reply By xfzhang, xfzhang 10.12.2011
I finally find a solution to this problem.
The cause of the problem is that the Bounding3D of all the Mesh3D objects and Surface3D of the ColladaLoader are empty! (I think this is a bug , hope you can fix it in later versions. Thanks!)
So I added following function, the function postorder travering all the children of all the Mesh3D objects:
private function updateBoundsForAllChildren( inPivot:Pivot3D ):void
{
// update leaf node
if( inPivot.children.length == 0 )
{
if( inPivot is Mesh3D )
{
var inMesh3D:Mesh3D = inPivot as Mesh3D;
for each( var surf:Surface3D in inMesh3D.surfaces )
{
surf.bounds = new Boundings3D();
surf.updateBoundings();
}
inMesh3D.bounds = new Boundings3D();
inMesh3D.updateBoundings();
}
return;
}
for each( var child:Pivot3D in inPivot.children )
{
updateBoundsForAllChildren( child );
}
// update none leaf node
if( inPivot is Mesh3D )
{
var inMesh3D2:Mesh3D = inPivot as Mesh3D;
for each( var surf2:Surface3D in inMesh3D2.surfaces )
{
surf2.bounds = new Boundings3D();
surf2.updateBoundings();
}
inMesh3D2.bounds = new Boundings3D();
inMesh3D2.updateBoundings();
}
}
Then after completely loaded the ColladaLoader, I added the following code:
updateBoundsForAllChildren( gym ); //gym is an object of ColladaLoader
Then every works perfect!!
Hope this helps , Many Thanks !
The cause of the problem is that the Bounding3D of all the Mesh3D objects and Surface3D of the ColladaLoader are empty! (I think this is a bug , hope you can fix it in later versions. Thanks!)
So I added following function, the function postorder travering all the children of all the Mesh3D objects:
private function updateBoundsForAllChildren( inPivot:Pivot3D ):void
{
// update leaf node
if( inPivot.children.length == 0 )
{
if( inPivot is Mesh3D )
{
var inMesh3D:Mesh3D = inPivot as Mesh3D;
for each( var surf:Surface3D in inMesh3D.surfaces )
{
surf.bounds = new Boundings3D();
surf.updateBoundings();
}
inMesh3D.bounds = new Boundings3D();
inMesh3D.updateBoundings();
}
return;
}
for each( var child:Pivot3D in inPivot.children )
{
updateBoundsForAllChildren( child );
}
// update none leaf node
if( inPivot is Mesh3D )
{
var inMesh3D2:Mesh3D = inPivot as Mesh3D;
for each( var surf2:Surface3D in inMesh3D2.surfaces )
{
surf2.bounds = new Boundings3D();
surf2.updateBoundings();
}
inMesh3D2.bounds = new Boundings3D();
inMesh3D2.updateBoundings();
}
}
Then after completely loaded the ColladaLoader, I added the following code:
updateBoundsForAllChildren( gym ); //gym is an object of ColladaLoader
Then every works perfect!!
Hope this helps , Many Thanks !
Reply By Nehmad, Ariel 10.14.2011
Hi xfzhang, thanks for share this!
which version are you suing? we changed some things related to that...it should work fine in the next release.
thanks again!.
which version are you suing? we changed some things related to that...it should work fine in the next release.
thanks again!.
Reply By Davey, Jon 10.20.2011
Thanks zfzhang. I was having the same problem with boundings returning null on collada models and found that looping through the objects children updating their boundings fixed the problem.
Popular
- 1. Question of Alpha sorting system
- 2. Rndering issue on AIR Mobile build
- 3. Problems with bone position?
- 4. Is it possible to make a primitive...
- 5. Messed up textures in Flare 3d Studio
- 6. Moving "by hand" the corners of a Plane
- 7. Shapes, splines and knots
- 8. Diferencia entre Flare3D Studio y...
- 9. Transform between two states
- 10. ReferenceError: Error #1074
