How to create a vgObject in Code from a pfNode

 

Vega Code Example

 

 

 

 

 

 

 
 

This example function illustrates how to :

  • Create your own vgObject through code using a pfNode as the source Geometry
  • How to create a new vgDataSet
  • How to set the properties for a vgDataSet
  • How to se the filename for a vgDataSet
  • How to load a 3d Model file into a vgDataSet
  • How to use vgDelete
  • How create a vgPos instance
  • How to delete a vgPos instance
  • How to set the position vpPos's position Vector suing vgPosVec
  • How to set an offset into a vgObject
  • How to optimise a vgObject by flattening and cleaning the vgObject
  • How to make a vgObject from a vgDataSet
  • How to make an vgObject Dynamic and thus positionable
  • How to to set a vgObject's Isector mask
  • How to set a vgOject's representation mask

 

 
   
 

 

 
 
 
    
 

 

#include "vg.h"          // Required for the standard Vega classes
#include "vgperf.h"      // Required for the vgGetXXXPfNode functions
#include "pf.h"          // for the standard Performer classes
#include "pfutil.h"
     // for the Performer util functions
 

 

 

 

 

vgObject*

createNewVegaObjectFromPfNode( pfNode *node, const char *name ){

// ##############################################################

// # Public  function  

// #

// #   The function shows how to create  a new vgObject using a

// #   Performer Node as as the template to create the object

// #

// #   Returns a pointer to the New vgObject if successful

// #           otherwise returns NULL  

// #

// #

// ##############################################################

vgDataSet  *dset    = NULL;

vgObject   *obj     = NULL;

vgPosition *pos     = NULL;

int         created = VG_FAILURE;

 

 

    //

    //  Sanity check we need a node

    //

    if( node == NULL ) {

         return NULL;

        }

 

    //

    // We first create a new empty Data Set

    //

    dset = vgNewDS();

    if( dset == NULL ) {

         return NULL;

        }

   

 

    //

    // Set the name for the data set

    //

    vgName( dset, name );

 

    // We want to discard any constraints of any DOF/DCS nodes

    //         

    vgProp( dset, VGDS_CREATECONSTRAINTS, VG_OFF);

 

 

    //

    // Now actually try to created the DataSet from the pfNode

    //

    created = vgMakeDS( dset, node, VGDS_GEOMETRY );

 

    if( created != VG_SUCCESS ) {

       

        //

        // We need to clean up

        //

        vgDelete ( dset );

 

        return NULL;

        }

 

 

    //

    // Now we create a new and empty vgObject

    //

    obj = vgNewObj();

 

    if( dset == NULL ) {

        

        //

        // We need to clean up

        //

        vgDelete ( dset );

 

        return NULL;

        }

 

    //

    // Name the new object

    //

    vgName( obj, name );

 

    //

    // Make the object dynamic other wise we cannot move it

    //

    vgProp( obj, VGOBJ_CS, VGOBJ_DYNAMIC );

 

    //

    // We want to make parts for named nodes etc

    //

    vgProp( obj, VGOBJ_PARTS, VG_ON );

 

 

    //

    // We want to discard any constraints of any DOF/DCS nodes

    //         

    vgProp( obj, VGOBJ_CONSTRAIN, VG_OFF );    

 

    //

    // Set the scaling factor for the new object if required

    //         

    // vgProp( obj, VGOBJ_SCALE, 1.0f );    

 

 

    

    //

    //  By default we should always clean and flatten the object

    //  this will help remove any redundant nodes and static

    //  transformations and help improve performance

    //

    //  Note that there is known bug in vega such that using

    //  Clean will  cause culling problems at the edge of the

    //  channel if the object has scaling in this case set

    //  VGOBJ_NOOPT instead of VGOBJ_CLEAN

    //

    vgProp( obj, VGOBJ_OPTIM, VGOBJ_CLEAN );

    

    vgProp( obj, VGOBJ_OPTIM, VGOBJ_FLATTEN );

        

 

    //

    // Set any object initial offset position here

    //         

    pos = vgNewPos();

    if( pos != NULL ){

 

        vgPosVec( pos, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);

 

        vgPos( obj, pos );

 

        //

        //  Free the position marker

        //

        vgDelPos( pos);

 

        }

 

 

    //

    // Set the dataset for for the new object

    //

    vgObjDS( obj, dset );

 

    

    //

    //  Now we call make object which will create the object 3d data

    //  using the tree created by the vgLoadDS         

    //

    //  Make the object using COPY mode so that we can use multiple

    //  copis of the 3d datbase if required

    //

    vgMakeObj( obj, VGOBJ_COPY);

 

 

    //

    //  Finally set the new vgObject isector and representation masks

    //     

    vgObjClass(     obj, 0xFFFFFFFF );

 

   vgObjRepresent( obj, 0xFF000000 );

 

 

return obj;

 

} // createNewVegaObject

  

  

   

 
    
 

 

 

© Copyright 2004 Gordon Tomlinson  All Rights Reserved.

All logos, trademarks and copyrights in this site are property of their respective owner.