spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / 3d / lesson28

Lesson 28 - VRML 97 Free Fall - Part 3

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

Just as we can use the DEF tag to define the specific values in the fields of a node, we can define completely new node types built from existing nodes. In this example, we create a simple table with four legs. The essence of this example is the use of a prototype. A table node is defined using other nodes and called TwoColorTable. This is only the definition, however. There are as yet no tables in the scene.

After the PROTO definition of the table is complete, that definition is then used to actually create two tables, using the new TwoColorTable node. Each table is in its own Transform, and each is translated one unit to the left and right, respectively, of the world transform center. Note how this differs from the DEF approach. DEF is used on nodes that actually exist in the scene so that they can be copied elsewhere. A PROTO statement defines a completely new node type, but nothing happens until the node is actually used in a scene.

Here is the code and the result.

#VRML V2.0 utf8

PROTO TwoColorTable   [  field SFColor legColor .5 1 .5
          field SFColor topColor 1 .5 1]  #end of public interface
{
  Transform {
    children [
      Transform { # table top
        translation 0 .6 0
        children [
          Shape {
            geometry Box {size 1.2 0.2 1.2}
            appearance Appearance {
              material Material {diffuseColor IS topColor}
            }
          }#end of shape
        ]
      } #end of table top
      Transform { # first leg
        translation -.5 0 -.5
        children [
          DEF Leg Shape {
            geometry Cylinder {height 1 radius 0.1}
            appearance Appearance {
              material Material {diffuseColor IS legColor}
            }
          }
        ]
      }
      Transform { #second leg
        translation .5 0 -.5
        children [
          USE Leg
        ]
      }
      Transform { #third leg
        translation -.5 0 .5
        children [
          USE Leg
        ]
      }
      Transform { #fourth leg
        translation .5 0 .5
        children [
          USE Leg
        ]
      }

    ]#End of children of root transform
  }#End of root transform
}#End of PROTO

Transform {
    children [
    Transform {
      translation -1 0 0
      children [
      TwoColorTable {
        legColor 1 0 0
        topColor 0 1 0
      }
      ]
    }
    Transform {
      translation 1 0 0
      children [
        TwoColorTable {}
      
      ]
    }
    ] #end of world children
}#end of world transform system

CLICK HERE to load example if you have a VRML browser.

There is so much to learn here.

The PROTO statement is divided into two parts. The first part, in the square brackets, defines the fields that can be changed when the new node is actually implemented. In this case, these fields are the colors of the table legs and top. Default color values are supplied. When the two tables are implemented at bottom of the file, the first node inserts new colors (red and green) and the second node uses the default colors by failing to state any values. This is typical of VRML nodes. For example, we have seen that failing to enter a size value in a geometry node (like Sphere or Box) results in a default value of 1. Notice how the IS statement is used to connect the color names at the top of the PROTO definition with the applicable Material nodes deeper in the definition. For example, the diffuseColor of the first leg is the legColor parameter (whether the default value or any new value supplied when the PROTO is implemented).

This example also repeats what we learned in the previous one. A Shape node is named Leg using the DEF statement, and thus the other three legs are easily created as instances of the first. They share both the geometry and appearance of the first. This not only makes the code more readable, but assures that any change in the geometry or appearance of the first leg will be passed to all the others. Placing each leg in a separate Transform node permits them to be separately translated into position at the corners of the table. Likewise, assigning each entire table to a Transform permits each to move, rotate and scale as a single functional unit in the scene.

To Return to Parts 1 and 2, Use Arrow Buttons

Previous Lesson / Table of Contents / Next Lesson


internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
  Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Review: Lenovo ThinkPad SL300 · OCZ PC3-10666 Gold 2x1GB Review · Apple Recommends Antivirus for Macs

Created: November 24, 1997
Revised: November 24, 1997

URL: http://webreference.com/3d/lesson28/part3.html