lunes, 23 de abril de 2012

PROTOTIPOS CON DEF & USE


Estas herramientas sirven en caso de que quieras utilizar figuras similares o iguales repetidas iguales, esto para evitarnos el estar haciendo una por una y tener un código ENORME.
Se utilizan de una manera muy sencilla. Primero se hace la figura que queramos utilizar (ésta se incluirá en el mundo virtual), y se agrupa con Group como ya vimos anteriormente.
Ejemplo de cuatro cajas agrupadas (utilizar el botón de examinar para poder ver bien el sillón):

#VRML V2.0 utf8

Group{
children[
#Respaldo
Transform{
          translation 0 0 0
          rotation 0.0 0.0 0.0 0.0    
              children [
Shape{
appearance Appearance {
           
       texture ImageTexture{url ["Asiento.jpg"]}  
             }

geometry Box{
      size 2 3 0.5
}
}
]
}


#Asiento
Transform{
          translation 0 -1.75 -0.75
          rotation 0.0 0.0 0.0 0.0    
              children [
Shape{
appearance Appearance {
           
       texture ImageTexture{url ["Asiento.jpg"]}  
             }

geometry Box{
      size 2 0.5 2
}
}
]
}

#Recargadera izquierda
Transform{
          translation -0.75 -1.25 -1
          rotation 0.0 0.0 0.0 0.0    
              children [
Shape{
appearance Appearance {
           
       texture ImageTexture{url ["Asiento.jpg"]}  
             }

geometry Box{
      size 0.5 0.5 1.5
}
}
]
}
#Recargadera derecha
Transform{
          translation 0.75 -1.25 -1
          rotation 0.0 0.0 0.0 0.0    
              children [
Shape{
appearance Appearance {
           
       texture ImageTexture{url ["Asiento.jpg"]}  
             }
geometry Box{
      size 0.5 0.5 1.5
}
}
]
}
]
}



Vamos a empezar, lo que debemos hacer después de este paso es lo siguiente:
 ♥ Antes de Group se escribe DEF N, sustituyendo “N” por el nombre de la  agrupación que se desea utilizar.

Ya que hicimos este sencillo paso si se desea podemos poner un Transform antes de DEF.
Ejemplo desarrollado:

#VRML V2.0 utf8
Transform{
          translation -23 -8 0
          rotation 0 0 0 0
          children [
DEF asientocompleto Group{
children[
#Respaldo
Transform{
          translation 0 0 0
          rotation 0.0 0.0 0.0 0.0    
              children [
Shape{
appearance Appearance {
           
       texture ImageTexture{url ["Asiento.jpg"]}  
             }

geometry Box{
      size 2 3 0.5
}
}
]
}


#Asiento
Transform{
          translation 0 -1.75 -0.75
          rotation 0.0 0.0 0.0 0.0    
              children [
Shape{
appearance Appearance {
           
       texture ImageTexture{url ["Asiento.jpg"]}  
             }

geometry Box{
      size 2 0.5 2
}
}
]
}
#Recargadera izquierda


Transform{
          translation -0.75 -1.25 -1
          rotation 0.0 0.0 0.0 0.0    
              children [
Shape{
appearance Appearance {
           
       texture ImageTexture{url ["Asiento.jpg"]}  
             }

geometry Box{
      size 0.5 0.5 1.5
}
}
]
}
#Recargadera derecha
Transform{
          translation 0.75 -1.25 -1
          rotation 0.0 0.0 0.0 0.0    
              children [
Shape{
appearance Appearance {
           
       texture ImageTexture{url ["Asiento.jpg"]}  
             }
geometry Box{
      size 0.5 0.5 1.5
}
}
]
}
]
}
]
}



Ahora lo que sigue es el ¿Cómo se va a volver a utilizar? Pues muy sencillo.
♥       Se escribe USE N, sustituyendo la N por el nombre de la agrupación, debe de ser  el mismo que pusiste antes de Group.
USE asientocompleto
♥       Si se desea pudes utilizar un Transform antes de USE.

Transform {
            translation 4.3 0 0
        rotation 0 0 0 0
            children [
USE asientocompleto
]
}

Ejemplo (Utilizar el botón examinar para ver mejor el ejemplo):

#VRML V2.0 utf8


DEF asientocompleto Group{
children[
#Respaldo
Transform{
          translation 0 0 0
          rotation 0.0 0.0 0.0 0.0    
              children [
Shape{
appearance Appearance {
           
       texture ImageTexture{url ["Asiento.jpg"]}  
             }

geometry Box{
      size 2 3 0.5
}
}
]
}


#Asiento
Transform{
          translation 0 -1.75 -0.75
          rotation 0.0 0.0 0.0 0.0    
              children [
Shape{
appearance Appearance {
           
       texture ImageTexture{url ["Asiento.jpg"]}  
             }

geometry Box{
      size 2 0.5 2
}
}
]
}

#Recargadera izquierda


Transform{
          translation -0.75 -1.25 -1
          rotation 0.0 0.0 0.0 0.0    
              children [
Shape{
appearance Appearance {
           
       texture ImageTexture{url ["Asiento.jpg"]}  
             }

geometry Box{
      size 0.5 0.5 1.5
}
}
]
}


#Recargadera derecha


Transform{
          translation 0.75 -1.25 -1
          rotation 0.0 0.0 0.0 0.0    
              children [
Shape{
appearance Appearance {
           
       texture ImageTexture{url ["Asiento.jpg"]}  
             }

geometry Box{
      size 0.5 0.5 1.5
}
}
]
}
]
}

Transform {
            translation 4.3 0 0
        rotation 0 0 0 0
            children [
USE asientocompleto
]
}

Transform {
            translation 6.5 0 0
        rotation 0 0 0 0
            children [
USE asientocompleto
]
}

Transform {
            translation 8.7 0 0
        rotation 0 0 0 0
            children [
USE asientocompleto
]
}



domingo, 22 de abril de 2012

NODO IMAGETEXTURE & MOVIETEXTURE


´
La textura es la posibilidad que tenemos de envolver un objeto con una imagen o video determinado que se encuentra almacenado en la misma carpeta que el fichero wrl, al cual accedemos mediante su URL.
 
Hasta ahora, para definir un objeto visible se ha utilizado el nodo Shape de la siguiente forma: 
 
               Shape {   
                           appearance Appearance {   
                            material ...   
                          }   
                       geometry ...   
                       }
En donde el nodo Appearance tiene un solo campo, material, con el que se definen el color y la transparencia, según se ha visto en temas anteriores. 
 
Pero en realidad puede tener también otros dos campos: texture (cuyo valor suele ser un nodo de tipo ImageTexture o de tipo MovieTexture) y textureTransform, con los que se define la textura de los objetos:  


Shape {   
    appearance Appearance {   
         material ...   
         texture ImageTexture{...}   
        
textureTransform {...}   
    }   
    geometry ...   
}

 
Nodo ImageTexture: 
 
Sintaxis: 
Shape {
        appearance Appearance{
ImageTexture{  
    url            "direccion_URL"  
} 

} 
}

El campo url contiene la dirección URL del fichero gráfico que se va a usar como textura.

Los formatos gráficos que admite VRML son jpeg, gif y png.  



Nodo MovieTexture
En lugar de usar imágenes estáticas como textura de los objetos, se pueden utilizar videos (películas), en formato MPEG, haciendo uso del nodo MovieTexture, en vez de ImageTexture. 
 
 
Sintaxis: 
Shape {
        appearance Appearance{
MovieTexture {    
    url            "dirección_URL"    
    speed       valor_real    
    loop          valor_lógico 
}
}
}

El campo url contiene la dirección URL del fichero que contiene el video. 
 
El campo speed controla la velocidad (1, velocidad normal; 2 doble velocidad, etc.). Con valores negativos el video se ejecutaría hacia atrás. 
 
El campo loop controla si el video funciona ininterrumpidamente (TRUE) o una sola vez (FALSE). 

Ejemplo:

#VRML V2.0 utf8

#Cajita de madera
Transform {
            translation 0 -5 -5
           
            children[
Shape {
        appearance Appearance{
                               texture ImageTexture { url "mesa.jpg" }
                               textureTransform TextureTransform {
                               rotation 3.14
                               scale 1  1
                              }
                               
                              }
                           
        geometry Box{
           size 5 .3 3
                       }
}
                    ]
      }

  

 

Transform {
            translation 0 0 -9.8 
        rotation 0.0 0.0 1.0 0.0    
            children [
Shape{
appearance Appearance {
         texture MovieTexture{
url "kill.mpg"
speed 1
loop TRUE}
         }   
      geometry Box{
      size 40 18 0.1
}
}
]
}