an eglantier

Scripts in 3D Canvas

Chapter 2: Making Faces

If you haven't read and understood the script called Sample-Create Face included with 3D Canvas, now would be a good time. At least make sure you can run it.

Most of the guff at the top and bottom of the script is to do with good housekeeping of your model. The comments in the script tell you how the face object fits into the model heirarchy. The part of the code we're most interested in here is:


       Dim Object           'The object we are creating (face)
       Dim Face             'The face we are creating    
       'create an object
        Set Object = Scene.CreateObject()

        'add the face to the object
        Set Face = Object.CreateFace

	 ...

       If NumericPoints = 4 Then
            'add the quad points to the object
            Object.AddPoint -.5,-.5,0
            Object.AddPoint -.5,.5,0
            Object.AddPoint .5,.5,0
            Object.AddPoint .5,-.5,0

            'add the points and the normal to the face
            Face.AddPointAndNormal 0,0
            Face.AddPointAndNormal 1,0
            Face.AddPointAndNormal 2,0
            Face.AddPointAndNormal 3,0        
        Else
            'add the points to the object

This shows how a new object is created, then a face is added to the object, then points are added to the face. I'll talk more about the structure of the object in the next chapter. If you're not used to working with objects and loosely typed programming languages (as I'm not), this code can be confusing. Here Object and Face are variable names, as well as types of objects. The following may be clearer. Assume you are using a script to make a model of a car. Here the object created first is called ModelCar, so there is no confusion.


	Dim ModelCar                          'The object we are creating 
	Dim WindscreenFace            'The face we are creating    
       'create an object
        Set ModelCar = Scene.CreateObject()

        'add the face to the object
        Set WindscreenFace = Object.CreateFace

If you don't quite understand yet, persist until the next chapter. I wan't to show you that this script is actually useful. I've modified the Sample-Create Face script to do essentially what is done by the plane command in PovRay - that is create a plane orthogonal to an axis. The difference is my planes aren't infinite. Here's a sample filled with Povray stars at the top and water at the bottom.

sample planes from script

I can't remember how I did this exactly, but you can study the script by clicking below. The code shows the only way I know to get input from a user in VBScript: by using inputbox. To get info out, say for debugging, use msgbox. You'll see examples of this throughout the scripts. Sometimes they are commented out - this shows how I used them for debugging. Once the script is running you get rid of these lines as they slow you down.


Next is Chapter 3

Introduction and Contentsan eglantier