DEF rootScript Script {
eventIn SFTime addParticle
field SFNode particleShape Shape {
geometry Sphere {
radius 3
}
appearance Appearance {
material Material {
diffuseColor 0 0 . 02
specularColor . 88 . 88 . 88
emissiveColor 0 0 . 37
shininess . 24
ambientIntensity . 0633
transparency . 59
}
}
}
field SFInt32 maxParticle 150
field SFFloat gravity -.2
field SFFloat inertia . 5
field SFFloat minStrength 0
field SFFloat maxStrength . 1
field SFFloat minRotateSpeed -5
field SFFloat maxRotateSpeed 5
field SFFloat minScale . 1
field SFFloat maxScale . 15
field SFTime minDeathTime 5
field SFTime maxDeathTime 5
field SFTime initTime 0
field SFTime localTime 0
field SFTime currentTime 0
field SFTime memoryTime 0
field SFTime deathTime 0
field SFInt32 index 0
field SFInt32 particleIndex 0
field SFInt32 particleNumber 0
field SFVec3f memVec3f 0 0 0
field SFVec3f randomPosition 0 0 0
field SFVec3f currentHitPoint 0 0 0
field SFVec3f memoryHitPoint 0 0 0
field SFVec3f position 0 0 0
field SFVec3f direction 0 0 0
field SFVec3f speed 0 0 0
field SFVec3f scale 0 0 0
field MFVec3f angle []
field MFVec3f pulsation []
field SFRotation rotation 0 1 0 0
field SFNode rootTimeSensor USE rootTimeSensor
field SFNode particleTransform NULL
field SFNode particleScript NULL
eventOut MFNode children_changed
url [
"javascript:
function addParticle(currentTime){
if(initTime==0) {
initTime=currentTime;
for ( index=0;index<30;index++){
angle[index]=new
SFVec3f(Math.random()*2-1,Math.random()*2-1,Math.r
andom()*2-1);
pulsation[index]=new
SFVec3f(Math.random()*3-1.5,Math.random()*3-1.5,Ma
th.random()*2-1);
}
}
localTime=currentTime-initTime;
for ( index=0;index<30;index++){
memVec3f.x+=Math.sin(angle[index].x+pulsation[
index].x*localTime);
memVec3f.y+=Math.sin(angle[index].y+pulsation[
index].y*localTime);
memVec3f.z+=Math.sin(angle[index].z+pulsation[
index].z*localTime);
}
randomPosition=memVec3f.multiply(.8);
memVec3f.x=0;
memVec3f.y=0;
memVec3f.z=0;
if(particleIndex==0){
children_changed[0]=rootTimeSensor;
}
if(particleIndex>=maxParticle){
particleIndex--;
for(index=2;index<maxParticle;index++){
children_changed[index-1]=children_changed[in
dex];
}
children_changed[particleIndex]=new SFNode ( );
}
position=randomPosition;
speed=position.subtract(memoryHitPoint).divide(
currentTime-memoryTime);
rotation=new
SFRotation(rand(2,-1),rand(2,-1),rand(2,-1),rand(2
direction=rotation.getAxis().multiply(1/rotatio
n.getAxis().length()*rand(maxStrength-minStrength,
minStrength));
scale=new
SFVec3f(rand(maxScale-minScale,minScale),rand(maxS
cale-minScale,minScale),rand(maxScale-minScale,min
Scale));
deathTime=rand(maxDeathTime-minDeathTime,minDea
thTime);
particleTransform=new SFNode(
´DEF particleTransform´+particleNumber+´ Transform {´+
´translation ´+position.toString()+´ ´+
´rotation ´+rotation.toString()+´ ´+
´scale ´+scale.toString()+´ ´+
´}´
);
particleScript=new SFNode(
´DEF particleScript´+particleNumber+´ Script {´+
´eventIn SFTime setTime ´+
´field SFTime initTime ´+currentTime+´ ´+
´field SFTime currentTime 0´+
´field SFTime localTime 0´+
´field SFVec3f speed ´+speed.toString()+´ ´+
´field SFVec3f position ´+position.toString()+´ ´+
´field SFVec3f direction ´+direction.toString()+´ ´+
´field SFTime deathTime ´+deathTime+´ ´+
´field SFVec3f scale ´+scale.toString()+´ ´+
´eventOut SFVec3f position_changed ´+
´eventOut SFRotation rotation_changed ´+
´eventOut MFNode children_changed ´+
´eventOut SFVec3f scale_changed ´+
´url [´+
´\"javascript:´+
´function setTime(currentTime) {´+
´localTime=currentTime-initTime;´+
´position_changed=position.add(direction.mul
tiply(Math.sqrt(localTime)*5)).add(speed.multiply(
Math.sqrt(localTime)*´+(inertia/5)+´));´+
´position_changed.y-=Math.pow(localTime,2)*´
+gravity+´;´+
´rotation_changed.angle=localTime*´+rand(max
RotateSpeed-minRotateSpeed,minRotateSpeed)+´;´+
´scale_changed=scale.multiply(Math.sqrt(Math
.abs(1-(localTime/deathTime))));´+
´if(localTime>deathTime) {´+
´children_changed[1]=new SFNode();´+
´}´+
´}´+
´\"´+
´]´+
´}´
);
particleTransform.children[0]=particleShape;
particleTransform.children[1]=particleScript;
children_changed[particleIndex]=particleTransfo
rm;
Browser.addRoute(rootTimeSensor,´time´,particle
Script,´setTime´);
Browser.addRoute(particleScript,´position_chang
ed´,particleTransform,´set_translation´);
Browser.addRoute(particleScript,´rotation_chang
ed´,particleTransform,´set_rotation´);
Browser.addRoute(particleScript,´children_chang
ed´,particleTransform,´children´);
Browser.addRoute(particleScript,´scale_changed´
,particleTransform,´set_scale´);
if(currentTime-memoryTime>.1){
memoryHitPoint=position;
memoryTime=currentTime;
}
particleNumber++;
particleIndex++;
}
function rand(plage,origine) {
if ( plage==0) {
return origine;
} else
return
Math.round((Math.random()*plage*1000)+origine*1000
)/1000;
}"
]
}
ROUTE rootTimeSensor.time TO rootScript.addParticle
ROUTE rootScript.children_changed TO rootTransform.children
voila le code 