ParallelGraphics Forums
Cortona VRML Client
You are here: [Forums]::[Browsers]::[Cortona VRML Client]

Registration 
Registration
Forgot your password?

Help 
Help
Support

Quick search 

Subscribe to newsletters 

Install Cortona VRML Client for FREE!
Outline 3D
Try RobinZone!
email:  password:
   Browsers - Cortona VRML Client

Subject: Re: bounding box
Sender: steve@geostudio3d.co.uk 28.02.07 14:09
I am trying to find a way to retreive the dimensions of the bounding box for a given geometry so i can display it if a geometry is clicked.

I have done this using the Collision extension.
I create 3 planes and collide them with the shape.
In the example below, click on the shape and its bounding box is returned.

The box orientation is relative to the world (not the object's local coordinate system). It could be tweeked to be relative to local.

Steve Smith
Aberystwyth

#VRML V2.0 utf8
# first create an object to get the bounds of
DEF object Transform{children[
    DEF tch TouchSensor {}
    DEF shp Shape {geometry
     IndexedFaceSet{
        solid FALSE convex TRUE
     coord Coordinate{point[-2 -2.5 -2.7 , -2 0 2 , 2.8 3.2 2],}
        coordIndex[0,1,2,-1]}
    }
]}

# create 3 planes for colliding with the shape
DEF SX Switch {whichChoice -1 choice[
    DEF PX Transform{children[
        Shape{appearance Appearance{material Material{transparency 0}}
            geometry IndexedFaceSet{solid FALSE convex TRUE
         coord Coordinate{point[0 -9999 -9999,0 -9999 9999,0 9999 9999,0 9999 -9999]}
            coordIndex[0,1,2,3,-1]}
        }
    ]}
]}

DEF SY Switch {whichChoice -1 choice[
    DEF PY Transform{translation 0 0 0 children[
        Shape{appearance Appearance{material Material{transparency 0}}
            geometry IndexedFaceSet{solid FALSE convex TRUE
         coord Coordinate{point[-9999 0 -9999, -9999 0 9999, 9999 0 9999, 9999 0 -9999]}
            coordIndex[0,1,2,3,-1]}
        }
    ]}
]}

DEF SZ Switch {whichChoice -1 choice[
    DEF PZ Transform{translation 0 0 0 children[
        Shape{appearance Appearance{material Material{transparency 0}}
            geometry IndexedFaceSet{solid FALSE convex TRUE
            coord Coordinate{point[-9999 -9999 0,-9999 9999 0,9999 9999 0,9999 -9999 0]}
            coordIndex[0,1,2,3,-1]}
        }
    ]}
]}

DEF    E Script{
    directOutput TRUE
    mustEvaluate TRUE
    field SFNode object USE object
    field SFNode px USE PX
    field SFNode sx USE SX
    field SFNode py USE PY
    field SFNode sy USE SY
    field SFNode pz USE PZ
    field SFNode sz USE SZ

    eventIn SFTime    tchTime

    url    "vrmlscript:

    function tchTime(){
        print(getBoundingBox(object));
    }

    function getBoundingBox(ob){

        ub=9999;lb=-9999;
        res=new SFVec3f();
        colid1=new Collidee();
        colid2=new Collidee();
        colid1.body=ob;
        colid2.body=py;
        colid1.scenary=colid2;

        sx.whichChoice=0;
        colid1.position=new SFVec3f(lb,0,0); colid1.moveTo(new SFVec3f(ub,0,0)); pa=colid1.collision.point.x;
        colid1.position=new SFVec3f(ub,0,0); colid1.moveTo(new SFVec3f(lb,0,0)); pb=colid1.collision.point.x;
        res.x=round3(ub*2+pa-pb);
        sx.whichChoice=-1;

        sy.whichChoice=0;
        colid1.position=new SFVec3f(0,lb,0); colid1.moveTo(new SFVec3f(0,ub,0)); pa=colid1.collision.point.y;
        colid1.position=new SFVec3f(0,ub,0); colid1.moveTo(new SFVec3f(0,lb,0)); pb=colid1.collision.point.y;
        res.y=round3(ub*2+pa-pb);
        sy.whichChoice=-1;

        sz.whichChoice=0;
        colid1.position=new SFVec3f(0,0,lb); colid1.moveTo(new SFVec3f(0,0,ub)); pa=colid1.collision.point.z;
        colid1.position=new SFVec3f(0,0,ub); colid1.moveTo(new SFVec3f(0,0,lb)); pb=colid1.collision.point.z;
        res.z=round3(ub*2+pa-pb);
        sz.whichChoice=-1;

        return res;
    }

    function round3(a){return Math.round(a*1000)/1000;}
"}
ROUTE tch.touchTime TO E.tchTime

 


bounding box / dan.vera@gmail.com / 27.02.07 19:07
     Re: bounding box / steve@geostudio3d.co.uk / 28.02.07 14:09

Messages in thread: 2


© 1998-2007 ParallelGraphics. All rights reserved. Terms of use.