Sei in: Home : Competenze : Computergrafica : VRML

VRML

vrml

Comandi di Base

 

Intestazione:

 

#VRML V2.0 utf8 


Forme:
Esempio:


Shape {
    appearance Appearance {
      material Material { emissiveColor 1 0 0 }   }
    geometry Sphere { radius 1 }
  }

Geometrie:


Sphere { radius 1 } 
Box { size 2 2 2} 
Cone { bottomRadius 2 height 4 } 
Cylinder { radius 2 height 4 }
Text { string "Ciao" fontStyle FontStyle {size 1.5} } 
#quadrato 
IndexedLineSet { coord Coordinate { point [0 0 0, 0 2.5 0, 2.5 2.5 0, 2.5 0 0, 0 0 0]}
	      coordIndex [0 1 2 3 0] }
#piramide 
IndexedFaceSet { coord Coordinate { point [-1 0 1, 1 0 1, 1 0 -1, -1 0 -1, 0 1 0]}
	      coordIndex [0, 3, 2, 1, -1
     	                     0, 1, 4, -1
 	                     1, 2, 4, -1
 	                     2, 3, 4, -1
 	                     3, 0, 4, -1]} 
#terreno accidentato 
#creaseAngle  indica l'angolo (espresso in radianti) al di sotto del quale il browser  
provvede ad effettuare uno smooth shading tra i vari poligoni #set_height serve per
modificare i valori delle altezze a run-time in modo da poter  realizzare elevationgrids 
animate 
ElevationGrid {xDimension 7 zDimension 6 xSpacing 4 zSpacing 4 height [  
	0, 2, 0, 2, 0, 2, 0,
	0, 2, 0, 2, 0, 2, 0,  
	0, 2, 0, 2, 0, 2, 0, 
	0, 2, 0, 2, 0, 2, 0,  
	0, 2, 0, 2, 0, 2, 0, 
	0, 2, 0, 2, 0, 2, 0, ] } 

image016



Trasformazioni:
si possono innestare una nell'altra
Esempio:

 

Transform {   translation 0 1.6 0   children [ 	Shape {.........}   ] } 

Tipi:


translation 0 1.6 0 
rotation 1 1 1 -1.56  
addChildren 
removeChildren 
center 
scale 
scaleOrientation 
bboxCenter 
bboxSize 


Luci:


DirectionalLight { direction 1 -1 0 } 
SpotLight {direction 1 1 0 location -2 1 2 radius 12 beamWidth 1 cutOffAngle 1 } 
PointLight {radius 5 location 0 0 0 } 

spotlight



Textures:
dentro a Appearance per le gif e jpeg

    texture ImageTexture {url "ilmondo.jpg"} 

mentre per i filmati MPEG-1

    texture MovieTexture {url "movie.mpg" loop TRUE startTime 1} 

si possono mappare a piacimento con

   textureTransform TextureTransform {scale 2 2} 

applicando:

	scale 2 2 	center .5 .5 rotation .78 	translation 0.5 0.5 


Level of Detail (LOD):
utile per non caricare texture dettagliate per oggetti lontani

LOD {range [3 6]
      level [ Shape{..........} #verrà usata tra i 0 e 3 metri 	     
Shape{..........} #verrà usata tra i 3 e 6 metri 	     
Shape{..........} #verrà usata tra i 6 e infinito 	]} 

Sfondo:

Background {backUrl [ "cielo.jpg" ] bottomUrl [ "terra.jpg" ] frontUrl [ "cielo.jpg" ]
 	    leftUrl [ "cielo.jpg" ] rightUrl [ "cielo.jpg" ] topUrl [ "terra.jpg" ]}  
Background { skyAngle [1.2 1.57 3.14] skyColor [0 0 1, 0.25 0.25 1, 0.5 0.5 1] 	    
groundAngle [1.3 1.57 ]  groundColor [0.05 0.25 0.05, 0.1 0.5 0.1, 0.25 0.75 0.25 ]} 


Navigazione:
punti di vista:

Viewpoint{ position 0 2.5 2.5 orientation -1 .5 0 .75 description "mio punto di vista" } 

modi di esplorazione

NavigationInfo {avatarSize [ 3.8, 3, 0.5 ] headlight TRUE speed 1 type "WALK" visibilityLimit 10} 

per rendere un solido non penetrabile

Collision { children [ Shape{.......}]} 

per mostrare sempre la stessa faccia (mancano dei parametri d'esempio)

Billboard { axisOfRotation 0 1 0 bboxCenter bboxSize addChildren removeChildren children [Shape{...}]} 


Link:

Anchor {url "anchor2.wrl" description "mio link" children [ Shape {....}]} 

per richiamare figure da altri file nella nostra scena (mancano valori di esempio)

Inline {url "abitazione2.wrl" bboxCenter bboxSize} 

 



Definizione di nuovi nodi:


DEF Cosamia
#la definisco  
Shape{...}
Cosamia    
#la uso 
USE Cosamia 
#per ogni successivo riutilizzo 
PROTO nome [ #per definire un mio nodo
          eventIn         tipo    nome          
		  eventOut        tipo    nome
          exposedField    tipo    nome
		  valore di default          
		  field           tipo    nome
		  valore di default  ] 
		  

Esempio di PROTO e IS:


PROTO Casa [          
exposedField SFColor colore_casa 1 .66 .25  ] { 
..... 
material Material { diffuseColor IS colore_casa } 
..... 


Animazioni:
#tempo

TimeSensor {cycleInterval 4 enabled TRUE loop TRUE startTime 1} #(fraction_canged) 

#interpolatori

ColorInterpolator, CoordinateInterpolator, NormalInterpolator,  OrientationInterpolator, 
PositionInterpolator e ScalarInterpolator  (key keyValue set_fraction value_changed) 

#collegamento tra nodi

ROUTE valore da pià TO valore da cambià 

#esempio

DEF SferaBlu Transform {
   translation 0 0 0 children [
   Shape {
   appearance Appearance {
   material Material { diffuseColor .16 .33 1 } }
   geometry Sphere { radius 1.4 }
   }]}
   DEF Tempo TimeSensor {cycleInterval 4 enabled TRUE loop TRUE startTime 1}
   DEF Posizione PositionInterpolator {key [0 .5 1] keyValue [-3 0 0, 3 0 0, -3 0 0]}
   ROUTE Tempo.fraction_changed TO Posizione.set_fraction
   ROUTE Posizione.value_changed TO SferaBlu.set_translation 

#esempi
con

OrientationInterpolator 

(keyvalue da 0 a 6.28 meno in senso orario) e

set_rotation

con

CoordinateInterpolator 

(keyvalue è la lista delle coordinate tutte di seguito) e

 coord DEF punti Coordinate { point [.....]} 

e

punti.point

con

ColorInterpolator 

(keyvalue è tra 0 e 1)e

material DEF mioMateriale Material { }

e

mioMateriale.set_diffuseColor

 



Suono:
Esempio:


Sound {
    minFront 10
    maxFront 100
    minBack 10
    maxBack 100
    spatialize FALSE
    source AudioClip {
		description "suono"
		loop TRUE
		startTime 1
		url "sound1.wav"
    }
}
	

suono



Interattività:
ci sono i nodi TouchSensor, ProximitySensor e VisibilitySensor
Esempio con TouchSensor:


DEF interruttore Shape { ...........}
 DEF interruttore TouchSensor {}
 DEF tempo TimeSensor {
	cycleInterval 1.2
	enabled FALSE
	loop  TRUE
	startTime 1 }
 ROUTE interruttore.isActive TO tempo.enabled
 ROUTE tempo.fraction_changed TO mioInterpolatore.set_fraction
 ROUTE mioInterpolatore.value_changed TO mioOggetto.set_qualcosa 
 


VRMLScript:

Script {      eventIn    eventOut    field tipo    exposedField    url  } 

Esempio:

DEF on_off Script {
    eventIn SFBool interruttorecliccato
	eventOut SFBool significatodelclick
	field SFBool statodelmissile FALSE
    url "vrmlscript:
		function interruttorecliccato(bottone) {
			if (bottone == 0) {
				if (statodelmissile == 0)
				statodelmissile = 1 ;
				else
				statodelmissile = 0 ;
				significatodelclick = statodelmissile; 
			}
		}
		" 
	}
	ROUTE tempo.fraction_changed TO mioInterpolatore.set_fraction
	ROUTE mioInterpolatore.value_changed TO mioOggetto.set_qualcosa
	ROUTE interruttore.isActive TO on_off.interruttorecliccato
	ROUTE on_off.significatodelclick TO tempo.enabled
	


Java e Script Esempio:
File WRL:

Transform {
  translation -4.8 -1 -1
  children[
  Shape {
      appearance Appearance {
      material Material { diffuseColor 1 1 1 }
    }
    geometry Text   { string "Rosso"    fontStyle FontStyle {size 1.5}
  }
  }
  DEF sensore_rosso TouchSensor {}
  ]  }
  Transform {  translation -1 -1 -1
  children[
  Shape {
    appearance Appearance {      material Material { diffuseColor 1 1 1 }    }
    geometry Text   { string "Verde"    fontStyle FontStyle {size 1.5}  }
  }
  DEF sensore_verde TouchSensor {}
  ]  }
  Transform {
  translation 3 -1 -1
  children[
  Shape {
    appearance Appearance {      material Material { diffuseColor 1 1 1 }    }
    geometry Text   { string "Blu"    fontStyle FontStyle {size 1.5}  }  }
  DEF sensore_blu TouchSensor {}
  ]  }
  # definizione del nodo cono  e creazione al suo interno del nuovo nodo conoMaterial il quale gestisce il colore del cono
    DEF cono Transform {        translation 0 2 -2
        children [
         Shape {
    appearance Appearance {      material DEF conoMaterial Material { diffuseColor 0.75 0.75    0.75}    }
    geometry Cone { bottomRadius 1.5  height 3}
  }  ]  }
  # definizione del nodo script e dichiarazione  dei suoi campi  
DEF cambio_colore Script {
        directOutput TRUE
        field SFNode      coloreMaterial USE conoMaterial
        eventIn     SFTime      set_rosso
        eventIn     SFTime      set_verde
        eventIn     SFTime      set_blu
        url "RGB.class"  }
  ROUTE sensore_rosso.touchTime TO cambio_colore.set_rosso
  ROUTE sensore_verde.touchTime TO cambio_colore.set_verde
  ROUTE sensore_blu.touchTime TO cambio_colore.set_blu   

File .JAVA (RGB.class)

import vrml.*;
  import vrml.field.*;
  import vrml.node.*;
  public class RGB extends Script {
      public void processEvent(Event e) {
      if(e.getName().equals("set_rosso")) {
        SFNode coloreMaterial = (SFNode) getField("coloreMaterial");
        Node coloreMaterialNode = (Node) coloreMaterial.getValue();
        SFColor coloreColor = (SFColor) coloreMaterialNode.getExposedField("diffuseColor");
        coloreColor.setValue(new SFColor(1,0,0));
      }
      else if(e.getName().equals("set_verde")) {
         SFNode coloreMaterial = (SFNode) getField("coloreMaterial");
        Node coloreMaterialNode = (Node) coloreMaterial.getValue();
        SFColor coloreColor = (SFColor) coloreMaterialNode.getExposedField("diffuseColor");
        coloreColor.setValue(new SFColor(0,1,0));
      }
       else if(e.getName().equals("set_blu")) {
         SFNode coloreMaterial = (SFNode) getField("coloreMaterial");
        Node coloreMaterialNode = (Node) coloreMaterial.getValue();
        SFColor coloreColor = (SFColor) coloreMaterialNode.getExposedField("diffuseColor");
        coloreColor.setValue(new SFColor(0,0,1));
      }
    }
  }