3DC 7.2 / 8.0 scripting : object creation by adding faces

I did a quick test and didn’t find anything wrong.

Hello,

I’m writing a script which builds an object by computing points and then adding faces made with these points.

If I just add one face (for example, the 1st face alone or the Nth face alone), the face shows up properly. If I let the script work to add all the faces, only the first face is displayed.

Thanks in advance for your help.

Here is the code executed each time a face is to be added to the shape with new points:
[pre class=’ip-ubbcode-code-pre’]
Sub AddFaceToShape(Scene, Shape, Xp, Yp, Zp)
Dim Point, Face, Material, Xn, Yn, Zn, Ln

‘ Add the face to the shape
Set Face = Shape.CreateFace

‘ Compute normal to the face
Xn = (Yp(1)-Yp(0))*(Zp(2)-Zp(0)) – (Zp(1)-Zp(0))*(Yp(2)-Yp(0))
Yn = (Zp(1)-Zp(0))*(Xp(2)-Xp(0)) – (Xp(1)-Xp(0))*(Zp(2)-Zp(0))
Zn = (Xp(1)-Xp(0))*(Yp(2)-Yp(0)) – (Yp(1)-Yp(0))*(Xp(2)-Xp(0))
Ln = Sqr(Xn^2+Yn^2+Zn^2)
‘ Add the normal to the shape
Shape.AddOptimizedNormalXYZ Xn/Ln, Yn/Ln, Zn/Ln

‘add a dummy uv to the shape (we need one to add the points)
Shape.AddOptimizedTextureCoordinateUV 0,0

For Point = 0 To 3
‘ Add the NewPoint to the shape
Shape.AddOptimizedPointXYZ Xp(Point), Yp(Point), Zp(Point)

‘ Add the point to the face
Face.AddPointID Point, 0, 0
Next

‘Create an appropriate material for the face
Set Material = Scene.CreateMaterial

‘ Set color
Material.SetColor 0.894, 0.773, 0.788

‘ Set default diffuse value
Material.SetDiffuse 60

‘ Set default ambient value
Material.SetAmbient 20

‘ Apply the material to the face
Face.SetMaterial Material
End Sub
[/pre]

[BLOCKQUOTE class=’ip-ubbcode-quote’][div class=’ip-ubbcode-quote-title’]quote:[/div][div class=’ip-ubbcode-quote-content’]If I let the script work to add all the faces, only the first face is displayed [/div][/BLOCKQUOTE]

I have a little VBA experience writing macros in TurboCAD in bygone versions, and have not made much time to learn the 3DC scripting interface yet, but that was one of the reasons why I bought it.

I think that the compute normal expressions should be inside the For/Next loop since the xp()etc. variables changes with each pass.

I did not test this, but do you agree?

**Edit**
You may to assign Yp(Var) to Yp(Point) etc.

The above piece of code is extremly close to the create face script (plugin actually) provided with 3DC 7.2 alpha4 (which I’m using now for testing). It works if I create one face (any one but only one) for the new object.
But when trying to create all the faces, only the 1st face is there and all the object points.

There may be a problem when executing the above code several times.

so does that mean I can select 4 points and create a face out of themandgt;?
Even to make 1 face be a damn help at times.

[BLOCKQUOTE class=’ip-ubbcode-quote’][div class=’ip-ubbcode-quote-title’]quote:[/div][div class=’ip-ubbcode-quote-content’]Originally posted by BigPeter:
so does that mean I can select 4 points and create a face out of themandgt;?
[/div][/BLOCKQUOTE]
Yes. From my little experience the points must be in a given order. I use the same order as you would be drawing the lines of the face.

[BLOCKQUOTE class=’ip-ubbcode-quote’][div class=’ip-ubbcode-quote-title’]quote:[/div][div class=’ip-ubbcode-quote-content’]when trying to create all the faces, only the 1st face is there [/div][/BLOCKQUOTE]

maybe the Set Face(i) = Shape.CreateFace needs to be in another loop so it becomes

Face(i).AddPointID Point, 0, 0

Face(i).SetMaterial Material

[BLOCKQUOTE class=’ip-ubbcode-quote’][div class=’ip-ubbcode-quote-title’]quote:[/div][div class=’ip-ubbcode-quote-content’]Originally posted by DOM107:

But when trying to create all the faces, only the 1st face is there and all the object points.
[/div][/BLOCKQUOTE]
Actually, all the faces are present but they are all stacked upon each other.
Maybe a 7.2 alpha4 bug ?

I know why it didn’t work: The point id’s are not at the face level but at the shape level.

I just tried running my DoubleSide plugin for V8.0 beta and have an almost identical bug.

I only get the first triangle on square faces.

Possible bug in the Face.AddPointID when the index andgt; 2 ????

I completed a script and, within my testing scope so far, I was able to create an object with 12 points and 8 faces.

I first create the points then I create the faces so that 4 ‘Face.AddPointID’ are in the same order as I would draw the face with a pencil.
The only problem I have is that the face is visible inward. I hadn’t time so far to test the reverse order when calling a set of 4 ‘Face.AddPointID’.

So, to sum it up, I found no bug so far once I understood how points and faces can be built (there is not that much documentation on this matter <!– s:) –><img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile" /><!– s:) –> ).

You must be logged in to reply in this thread.