ExplodingPolySet - Proto

 
Post new topic   Reply to topic    VRMLWorld.net Forum Index -> ABNet::Examples
View previous topic :: View next topic  
Author Message
admin
Site Admin


Joined: 08 May 2003
Posts: 128

PostPosted: Thu Aug 24, 2006 12:45 pm    Post subject: ExplodingPolySet - Proto

As most of you know, I've been working with the Avatar Studio 2
single mesh avatars for use with ABNet 2 the X3D / VRML 3D Chat
server. I thought I'd take a fun diversion and try out some of the
great PROTOs from Peter Gertsmann's site.

I took his ExplodingPolySet PROTO and modified it so that it
would work with IndexFaceSets that have texture images.
Just click on the head once it loads to see it in action:

Example VRML: http://vrmlworld.net/forums/data/explodinghead.wrl

You should check out Peter's site. It is full of useful information
for those developing VRML.

http://accad.osu.edu/~pgerstma/protolib/BuildingGamesInVRML.pdf

-rick


Last edited by admin on Thu Aug 24, 2006 8:23 pm; edited 1 time in total
Back to top
griff
Forum Junkie


Joined: 17 May 2003
Posts: 27
Location: canada

PostPosted: Thu Aug 24, 2006 1:16 pm    Post subject:

I thought Vladamir Bulatov had an exploding IFS PROTO or code too.

Thinking of what you describe reminded me of an avatar that someone had ... not sure who. Was a kind of western character like the human in the Curious George kids books. The amusing feature was that clicking on him ... bits fell off ... which you could then drag around ... Rolling Eyes

griff Smile
Back to top
Shaba1
Forum Junkie


Joined: 09 Jun 2003
Posts: 10

PostPosted: Thu Aug 24, 2006 4:38 pm    Post subject:

What is the code for the actual PROTO. I could really use this in the sim/game I am trying to contruct. Where a missle or bullet hits an object and it explodes.


{EDIT} Never mind I found it.
Back to top
admin
Site Admin


Joined: 08 May 2003
Posts: 128

PostPosted: Thu Aug 24, 2006 5:04 pm    Post subject:

Code:
PROTO ExplodingPolySet [
   eventIn  SFTime  explodeTime       # detonation trigger
   field    SFNode  coord       NULL  # standard IFS fare
   field    MFInt32 coordIndex  []    # likewise
  field    SFNode  texCoord NULL
  field    MFInt32 texCoordIndex     []
   field    SFFloat rspeed      4     # rotation speed of fragments
   field    SFFloat cspeed      40    # escape speed of fragments
   field    SFTime  duration    1     # duration of explosion
   field    SFFloat gravitation 9.81  # gravitational acceleration (acts on y axis)
  field    SFFloat groundLevel 0     # y intercept with ground
   field    SFFloat scale       1     # poly-shrinkage (< 1 creates gaps between poly seams)
   eventOut SFBool  isActive          # whether or not the explosion is occuring
  field    SFNode  material NULL
]
{
  DEF IFS IndexedFaceSet {
    solid FALSE
    texCoord IS texCoord
    texCoordIndex IS texCoordIndex
    coord Coordinate {}
    creaseAngle 3.14
  }

  DEF TIMER TimeSensor {   
    cycleInterval IS duration
    isActive IS isActive
  }

  DEF ExplodingIFS Script {
    eventIn  SFTime     explodeTime  IS  explodeTime
    eventIn  SFTime     set_time
    field    SFNode     coord        IS  coord
    field    MFInt32    coordIndex   IS  coordIndex
    field    SFNode     ifs          USE IFS
    field    MFInt32    ci           []
    field    MFVec3f    vertex       []
    field    SFFloat    scale        IS  scale
    field    SFInt32    pcount       0
    field    MFVec3f    centers      []
    field    MFVec3f    speed        []
    field    MFInt32    faces        []
    field    MFRotation rot          []
    field    MFVec3f    vertex0      []
    field    SFBool     first_time   TRUE
    field    SFNode     timer        USE TIMER
    field    SFTime     t0           0   # time of explosion
    field    SFFloat    rspeed       IS  rspeed
    field    SFFloat    cspeed       IS  cspeed
    field    SFFloat    gravitation  IS  gravitation
    field    SFFloat    groundLevel  IS  groundLevel

    url ["javascript:

      /// public:
      function explodeTime(time) {
         if(first_time) {
           timer.set_startTime = time;
           timer.set_enabled = TRUE;
           first_time = FALSE;
           t0 = time;
         }      
      }

      function set_time(v,t) {
         var time = t - t0;
         var center = new SFVec3f(0,0,0);
         var vert = new SFVec3f(0,0,0);

         for(var p = 0; p < pcount; p++) {
           center = centers[p];      
           center.x += speed[p].x*time;
           center.y += speed[p].y*time - gravitation*time*time;
           center.z += speed[p].z*time;
           if(center.y < groundLevel) { continue; }
           for(var f = faces[2*p]; f < faces[2*p+1]; f++) {
             var r = rot[p];
             r.angle = time*rspeed;
             vert = r.multVec(vertex0[f]);   
             vertex[f] = vert.add(center);
           }
         }
         ifs.coord.set_point = vertex;      
      }


      /// private:
      function initialize() {
         var fcount = 0;
         var vcount = 0;
         var ci_count = 0;
         var fv = new MFVec3f();
         var center = new SFVec3f(0,0,0);

         for(i = 0; i < coordIndex.length; i++) {
           if(coordIndex[i] != -1) { fv[fcount++] = coord.point[coordIndex[i]]; }
          else { // new face
             center.x = center.y = center.z = 0;
             for( j = 0; j < fcount; j++) { center = center.add(fv[j]); }
            center = center.divide(fcount);

             // first index of current face                    
             faces[2*pcount] = vcount;
             for( j = 0; j < fcount; j++) {         
                vertex0[vcount] = new SFVec3f(
                    (fv[j].x - center.x) * scale,
                    (fv[j].y - center.y) * scale,
                    (fv[j].z - center.z) * scale);
                vertex[vcount] = vertex0[vcount].add(center);
                ci[ci_count++] = vcount;
                vcount++;
             }
             ci[ci_count++] = -1;
             fcount = 0;

             // center of current face
             centers[pcount] = new SFVec3f(center.x, center.y, center.z);
             speed[pcount] = centers[pcount].normalize().multiply(cspeed);
             // rotation for current face
             rot[pcount] = new SFRotation(new SFVec3f(Math.random(), Math.random(), Math.random()),0);
             // last index of current face          
             faces[2*pcount + 1] = vcount;
             pcount ++;         
           }
         }
         ifs.coord.set_point = vertex;
         ifs.set_coordIndex = ci;      
      }
      "]
  }
   
  ROUTE TIMER.time TO ExplodingIFS.set_time
}
Back to top
Shaba1
Forum Junkie


Joined: 09 Jun 2003
Posts: 10

PostPosted: Thu Aug 24, 2006 5:27 pm    Post subject:

Thanks rick. This may seem like a very stupid question. But I read the definaition of PROTO and EXTERNPROTO both at the original vrml97 that describes the ISO standard(Which I cannot seem to find anywhere on the net any longer. Lucky thing I printed it out and put it in a binder years ago) and the vrml tutorial a www.lighthouse3d.com.

One question I have. In and EXTERNPROTO you declare the interface for the proto in you own code then at the end of the interface put in the url where the actual code of the proto can be found. I ASSume that the vrml browser then pulls that code into your world. What happens if the code or url is no longer on the web. Also is the actual code for whatever EXTERNPROTO vrml browser specific? I see a lot of node extensions on both Blaxxun's and Bitmanagement's web site what give and EXTERNPROTO interface and a blaxxun or bitmanagment url. I suspect that if you use these in your code that people with Cortuna,Flux or say WorldView would not see my world correctly. Am I right?
Back to top
admin
Site Admin


Joined: 08 May 2003
Posts: 128

PostPosted: Thu Aug 24, 2006 8:18 pm    Post subject:

If the code is no longer available, that is a bad thing. Your
Extern Proto will stop working.

I tend to use PROTO defined in the world that uses it.
That way, you don't have to worry about external sites
you don't have any control over.

If you look at some of the Extern Protos for blaxxun and
bitmanangement, they use a "urn" .. that means the
capability is built-in to the browser. In fact, it doesn't
try to load a url from a remote server. It uses the internal
functions of the browser. That is a good thing, it means it
is fast and done in C++ code instead of vrmlscript.


A good example is the BspTree node built into the Contact
browser. You reference using

urn:inet:blaxxun.com:node:BspTree

That doesn't try to download anything from blaxxun.com
it just calls the C++ code in the browser. If you aren't
running the contact browser, it tries the fall back
vrmlscript in node.wrl at blaxxun.

-rick
Back to top
Shaba1
Forum Junkie


Joined: 09 Jun 2003
Posts: 10

PostPosted: Fri Aug 25, 2006 11:29 pm    Post subject:

Thanks Rick. That explains it clearly. I found the page at www.cgrg.ohio-state.edu/~pgerstma/protolib/. How would I get the code like you pubished in the previous post. I saw the interface descriptions from each of the protos but not the actual code of the protos. Interestingly I tried to click on the .wrl in the GPS description and when I did BS start up with a white screen then closed the IE window that it was in and two others that I had open. Any ideas
Back to top
fabricator
Forum Junkie


Joined: 10 Jul 2006
Posts: 49

PostPosted: Sat Aug 26, 2006 1:45 am    Post subject:

Ah nice improvement to the proto rick, untextured objects really don't look good. Maybe time to dust off loan's Combat 2 game and try making some of its objects explode.

Making a working avatar explode would be a lot of fun too, would require disabling the animation scripting though. You can't have a mass of seperate faces walking around.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    VRMLWorld.net Forum Index -> ABNet::Examples All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum