Tutorial para VRML


Prof. Antônio José Berutti Vieira - Departamento de Geomática – UFPR

Formas geométricas básicas: [Box, Cone, Cylinder, Sphere]

Programa

Visualização

Shape {

geometry Box{}

}




Shape {

geometry Cone{}

}



Shape {

geometry Cylinder{}

}



Shape {

geometry Sphere{}

}



Obs.: Para mudar a cor de fundo clicar o botão direito do mouse, selecionar: Preference > background



Mudando o tamanho das formas básicas e a cor para cinza

Shape {

geometry Box {size 1 2 3}

appearance Appearance {

material Material{}

}

}



Shape {

geometry Cone {

bottomRadius 1

heigh 3

}

appearance Appearance {

material Material{}

}

}



Shape {

geometry Cylinder {

radius 1

heigh 3

}

appearance Appearance {

material Material{}

}

}



Shape {

geometry Sphere {

radius 2.5

}

appearance Appearance {

material Material{}

}

}





Introduzindo uma cor específica

Existe uma faixa do espectro eletromagnético que pode ser percebida pelo olho humano. Esta é chamada de faixa de luz visível. Esta faixa está compreendida entre 400nanometros e 700nanometros.





Cor é a forma como o cérebro humano responde a um certo estímulo eletromagnético dentro da faixa de luz visível. O triângulo de cores é utilizado para derivar a cor que resulta da combinação de duas cores primárias.





Cada uma das cores do espectro-eletromagnético fica caracterizada em função dos três comprimentos de onda primários que são: vermelho (Red), verde (Green) e o violeta (Blue). Se considerarmos valores reais entre zero e 1, podemos quantizar cada cor como uma combinação das três componentes primárias.




R G B

Especificação da Cor

Efeito visual

preta

0 0 0


branca

1 1 1


vermelho

1 0 0


verde

0 1 0


violeta (azul escuro)

0 0 1


amarelo

1 1 0


ciano

0 1 1


magenta

1 0 1




Shape {

geometry Box {size 1 2 3}

appearance Appearance {

material Material {diffuseColor 1 0 0}

}

}



Shape {

geometry Cone {

bottomRadius 1

height 3

}

appearance Appearance {

material Material {diffuseColor 0 1 0}

}

}



Shape {

geometry Cylinder {

radius 1

height 2

}

appearance Appearance {

material Material {diffuseColor 0 0 1}

}

}



Shape {

geometry Sphere { radius 1}

appearance Appearance {

material Material {diffuseColor 1 1 0}

}

}





Formas textuais: Text

Shape {

geometry Text { string "Experimento 1"}

}

# Para visualizar alterar a cor de fundo para amarela



Shape { # pular linha

geometry Text { string ["VRML", "UFPR"]}

}



Shape {

geometry Text {

string "VRML"

fontStyle FontStyle {

size 2.5

family "SANS"

}

}

}



Shape {

geometry Text {

string "VRML"

fontStyle FontStyle {

size 3

family "TYPEWRITER" #"SERIF" ou “SANS"

} } }



Shape {

geometry Text {

string "Experimento 1"

fontStyle FontStyle {

size 2

style "BOLD" # "PLAIN" "ITALIC" "BOLDITALIC"

} } }



Shape {

geometry Text {

string "Experimento 1"

fontStyle FontStyle {

size 1

style "BOLD" # "PLAIN" "ITALIC" "BOLDITALIC"

} }

appearance Appearance {

material Material {diffuseColor 0 0 1}

} }





Agrupando objetos

Group {

children [

Shape {

geometry Box {size 3 0.06 3}

appearance Appearance {

material Material {diffuseColor 0.250 0.125 0 } } },

Shape {

geometry Sphere{ radius 2}

appearance Appearance {material Material {

diffuseColor 0 1 0

transparency 0.4

} } },

Shape {

geometry Cylinder {

height 4.6

radius 0.4

}

appearance Appearance {

material Material {diffuseColor 0.666 0.333 0}

} } ] } # ver transformação geométrica a seguir





Aplicando transformação: translation

Shape {

appearance Appearance{

material Material {diffuseColor 1 0 0}

}

geometry Sphere {radius 0.20}

}

Transform {

translation 1 0 0

children Shape {

geometry Sphere {radius 0.20}

appearance Appearance {

material Material { diffuseColor 0 0 1}

} } }

Transform {

translation 2 0 0

children Shape {

geometry Sphere {radius 0.20}

appearance Appearance {

material Material { diffuseColor 0 1 0}

} } }



Shape {

appearance Appearance{material Material{diffuseColor 1 1 1}}

geometry Sphere {radius 0.20}

}

Transform {

translation 1 0 0

children Shape {

appearance Appearance{

material Material {diffuseColor 1 0 0}}

geometry Sphere {radius 0.1}

}

}

Transform {

translation 0 1 0

children Shape {

geometry Sphere {radius 0.1}

appearance Appearance {

material Material {diffuseColor 0 0 1}

}

}

}

Transform {

translation 0 0 1

children Shape {

geometry Sphere {radius 0.1}

appearance Appearance {

material Material {diffuseColor 0 1 0}

}

}

}



Group {

children [

Transform {

translation 0 –2.33 0

children Shape {

geometry Box {size 3 0.06 3}

appearance Appearance {

material Material {diffuseColor 0.250 0.125 0 }

} } },

Transform {

translation 0 4.2 0

children Shape {

geometry Sphere{ radius 2}

appearance Appearance {

material Material {

diffuseColor 0 1 0

transparency 0.4

} } } },

Shape {

geometry Cylinder {

height 4.6

radius 0.4

}

appearance Appearance {

material Material {diffuseColor 0.666 0.333 0}

} } ] }





Aplicando transformação: rotation

Transform {

rotation 1 0 0 1.57 # rotacao sobre X de 90 graus

children Shape {

geometry Text {

string "VRML"

fontStyle FontStyle {size 2.5}

}

appearance Appearance {

material Material {diffuseColor 1 0 0 }

}

}

}


# rotacionar o texto para visualizar



Transform {

rotation 0 1 0 1.57 # rotacao sobre Y de 90 graus

children Shape {

geometry Text {

string "VRML"

fontStyle FontStyle {size 2.5}

}

appearance Appearance {

material Material { diffuseColor 1 0 0 }

} } }

# rotacionar o texto para visualizar



Transform {

rotation 0 0 1 1.57 # rotacao sobre Z de 90 graus

children Shape {

geometry Text {

string "VRML"

fontStyle FontStyle {size 2.5}

}

appearance Appearance {

material Material { diffuseColor 1 0 0 }

} } }





Formas arbitrárias: ponto, segmento de reta e face

Shape {

    geometry PointSet{

        coord Coordinate{

             point [0 0 0, 1 0 0, 0 1 0, 0 0 1]

        }

    }

}



Shape {

appearance Appearance {

material Material {emissiveColor 1 0 0}

} # emissiveColor - cor emitida pelo objeto

geometry IndexedLineSet {

coord Coordinate {

point [0 0 0, 4 0 0]

}

coordIndex [0, 1]

}

}



Shape {

    appearance Appearance {

        material Material {emissiveColor 1 0 0}

    }

    geometry IndexedLineSet {

        coord Coordinate {

            point [0 0 0, 4 0 0,0 4 0]

        }                 #-1 indica o ultimo ponto do segmento

        coordIndex [

                            0, 1,-1

                            0, 2

         ]  } }         # -1 para ultimo segmento não é necessário




Shape {

    appearance Appearance {

        material Material {emissiveColor 1 1 0}

    }

    geometry IndexedLineSet {

         coord Coordinate {

             point [0 0 0, 4 0 0,0 4 0, 0 0 4]

         }

         coordIndex [

                             0, 1,-1

                             0, 2,-1

                             0, 3

         ]

    }

} # use a tecla FIT para visualizar






Criando faces: IndexedFaceSet

Shape {

   geometry IndexedFaceSet {

      coord Coordinate {

          point [1 0 1, 3 0 -1, 2 2 0]

      }

      coordIndex [0 1 2]   #sequencia formando face

                       

      colorPerVertex  TRUE

      solid FALSE         

   }

}



Shape {

   geometry IndexedFaceSet {

      coord Coordinate { point [1 0 1, 3 0 -1, 2 2 0] }

      coordIndex [0 1 2]   #sequencia formando face

      color Color { color[1 0 0] }#indice  0

      colorIndex [0]

                       

      colorPerVertex  FALSE

      solid FALSE         

   }}



Shape {

    geometry IndexedFaceSet {

        coord Coordinate { point [1 0 0, 4 0 0, 4 2 0, 1 2 0] }

        coordIndex [0 1 2 3]   #sequencia formando face

        color Color { color[1 1 0] }#indice  0

        colorIndex [0]

           

        colorPerVertex  FALSE

        solid FALSE       

    } }




Shape {

    geometry IndexedFaceSet {

        coord Coordinate {

            point [2 0 2, 1 1 1, 0 2 0, -1.5 1.5 0, -2 0 1]

        }

        coordIndex [0 1 2 3 4]   #sequencia formando face

        color Color {

            color[0 1 0]

        }#indice  0

        colorIndex [0]

                       

        colorPerVertex  FALSE

        solid FALSE       

    } }





Criando sólidos pela combinação de faces

Shape {

    geometry IndexedFaceSet {

         coord Coordinate {

             point [ 1 0 1, 1 0 -1, -1 0 -1, -1 0 1, 0 1.5 0 ]

         }

         coordIndex [

                              0 1 2 3 0 -1,

                              0 1 4 0 -1,

                              1 2 4 1 -1,

                              2 3 4 2 -1,

                              3 0 4 3

         ]  } }        # Girar a figura para melhor visualizar



Shape {

   geometry IndexedFaceSet {

     coord Coordinate {

        point [

           1 0 1, 1 0 -1, -1 0 -1, -1 0 1, 0 1.5 0

        ]

     }

     coordIndex [

                          0 1 2 3 -1,

                          0 1 4 -1,

                          1 2 4 -1,

                          2 3 4 -1,

                          3 0 4

     ]

     color Color {    # definição de 5 cores

       color[1 0 1, 1 0 0, 0 1 0, 0 0 1, .5 .5 .5]

     }

     colorIndex [0, 1, 2, 3, 4]

     # lê-se: coloque cor [0] na face[0]; cor [1] na face[1] etc;

     colorPerVertex FALSE

      #se false: implica cor/face

     solid FALSE #fundo invisivel

   }

} # Girar a imagem para melhor visualizar

# Como execício: coloque na face[0] magenta; na face[1] preta;

# na face[2] amarelo; na face[3] branca e na face[4] ciano





As palavras chave DEF e USE

Em VRML existe uma alternativa interessante que permite reutilizarmos algum objeto que tenha sido descrito numa cena VRML. Para isto, utilizamos a palavra chave DEF e quando quisermos descrever um novo objeto com as mesmas características, utilizamos a palavra chave USE. No exemplo a seguir são colocados: três cilindros, um sobre cada um dos eixos coordenados, e uma esfera .

Shape {

   geometry Sphere { radius 0.10}

   appearance Appearance {material Material {}}

}

 

Transform {

  translation      0 1.5 0

  children [

     Shape{

         geometry Cylinder {

            radius   0.02

            height   3

         }

         appearance Appearance { material Material {}

} } ] }

 

Transform {

  translation      1.5 0 0

  rotation 0 0 1 -1.57

  children [

     Shape {

         geometry Cylinder {

             radius 0.02

             height 3

         }

         appearance Appearance {material Material {}

 } } ] }

 

Transform {

  translation 0 0 1.5

  rotation 1 0 0 1.57

  children [

     Shape {

        geometry Cylinder {

            radius 0.02

            height 3

        }

        appearance Appearance {material Material {}

} } ]  }

roup {

children [

Shape {

appearance DEF Magenta Appearance {

material Material {

diffuseColor 1 0 1

} }

geometry Cylinder {

height 3.0

radius 0.5

} },

Transform {

translation 0.0 2.0 0.0

children Shape {

appearance USE Magenta

geometry Sphere {radius 2.}

} } ] }

Usando as palavras chave DEF e USE, podemos ter:

Shape {

   geometry Sphere { radius 0.10}

   appearance Appearance {material Material {}}

}

DEF eixo Transform {

  translation      0 1.5 0

  children Shape {

     geometry Cylinder {

         radius      0.02

         height      3

     }

     appearance Appearance {material Material {}}

 }  }

 

Transform {

  rotation 0 0 1 -1.57

  children USE eixo

}

Transform {

  rotation 1 0 0 1.57

  children USE  eixo

}