October 30, 2001
at 12:00 pm /
#10803
Richard,
How do I generate irregular faces without polygon overlap.
pic1: desired shape
pic2: undesired triangulated shape
pic3: undesired material shape
The script is just the 3DC supplied face script with points plugged in where the usual shape is.
[img]URL[/img]
[pre class=’ip-ubbcode-code-pre[/img]
Language = VBScript
‘*******************************************************************************
**
‘ Purpose: Creates a Face
‘*******************************************************************************
**
Option Explicit ‘require variable declarations
Sub Main (3DCApp)
Dim Scene ‘The current active scene
Dim SceneRootFrame ‘The root frame of the scene
Dim Frame ‘The frame for our object (face)
Dim Object ‘The object we are creating (face)
Dim Face ‘The face we are creating
Dim GridOriginX ‘The 3DC Grid’s Origin (x)
Dim GridOriginY ‘The 3DC Grid’s Origin (y)
Dim GridOriginZ ‘The 3DC Grid’s Origin (z)
Dim GridSize ‘The 3DC Grid’s Size
Dim GridInterval ‘The 3DC Grid’s Interval
Dim Points ‘The user’s desired # of points
Dim NumericPoints ‘Points converted to a number
Dim FirstPointX ‘First point in face
Dim FirstPointY ‘First point in face
Dim FirstPointZ ‘First point in face
Dim AxisX ‘Axis to rotate the start position around
Dim AxisY ‘Axis to rotate the start position around
Dim AxisZ ‘Axis to rotate the start position around
Dim Point ‘Point we are creating
Dim NewPointX ‘Point to add
Dim NewPointY ‘Point to add
Dim NewPointZ ‘Point to add
Dim BoxMinX ‘The Object’s Bounding Box
Dim BoxMinY ‘The Object’s Bounding Box
Dim BoxMinZ ‘The Object’s Bounding Box
Dim BoxMaxX ‘The Object’s Bounding Box
Dim BoxMaxY ‘The Object’s Bounding Box
Dim BoxMaxZ ‘The Object’s Bounding Box
Dim Material ‘The Face’s Material
‘ask the user how many points s/he wants
Do
Points = InputBox(andquot;How many points would you like in the face?andquot;,,andquot;4andquot;)
‘if they entered anything
If Points andlt;andgt; andquot;andquot; Then
‘they could have entered anything so ensure it is valid
On Error Resume Next
NumericPoints = clng(Points)
Err.Clear
On Error Goto 0
‘Let them know we had a problem
If NumericPoints andlt; 3 Then
Msgbox andquot;3 is the minimum number of pointsandquot;, vbInformation
End If
End if
Loop Until NumericPoints andgt;= 3 Or Points = andquot;andquot;
‘If they entered anything continue
If Points andlt;andgt; andquot;andquot; Then
‘get the scene
Set Scene = 3DCApp.GetActiveScene
‘get the root frame
Set SceneRootFrame = Scene.GetRootFrame
‘create a frame for the object (face)
Set Frame = Scene.CreateFrame
‘add it to the scene
SceneRootFrame.AddChild Frame
‘give the frame a name – note that we can’t do this
‘until the frame is added to the scene
Frame.SetName andquot;Face Frameandquot;
‘create an object
Set Object = Scene.CreateObject()
‘add the face to the object
Set Face = Object.CreateFace
‘add a dummy normal to the object (we need one to add the points)
Object.AddNormal 0,0,-1
Object.AddPoint 0, 0, 0
Object.AddPoint 0, 95, 0
Object.AddPoint 32, 101, 0
Object.AddPoint 32, 134, 0
Object.AddPoint 51.5, 140, 0
Object.AddPoint 70, 134, 0
Object.AddPoint 70, 69.5, 0
Object.AddPoint 96, 63.5, 0
Object.AddPoint 96, 0, 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
Face.AddPointAndNormal 4,0
Face.AddPointAndNormal 5,0
Face.AddPointAndNormal 6,0
Face.AddPointAndNormal 7,0
Face.AddPointAndNormal 8,0
‘Create an appropriate material for the face
Set Material = Scene.CreateMaterial
‘make it a nice color
Material.SetColor .894,.773,.788
‘set the default diffuse value
Material.SetDiffuse 60
‘set the default ambient value
Material.SetAmbient 20
‘apply the material to the face
Face.SetMaterial Material
‘add the object to the created frame
‘this also triggers the update to the database
Frame.AddObject Object
‘set the object name – note that we can’t do this until
‘the object is added to a frame
Object.SetName andquot;Faceandquot;
‘Now that we know the size of the object let’s set the position of the frame
‘so the face is visible
‘get the 3DC grid details
3DCApp.GetGridDetails GridOriginX, GridOriginY, GridOriginZ, GridSize, GridInterval
‘get the object’s dimensions
Object.GetBoundingBox BoxMinX, BoxMinY, BoxMinZ, BoxMaxX, BoxMaxY, BoxMaxZ
‘Center the Object’s Frame on the Scene and have the object sitting nicely
‘on the surface
Frame.SetPosition SceneRootFrame, 0, GridOriginX + GridSize / 2, GridOriginY – BoxMinY, GridOriginZ + GridSize /2
End If
End Sub
[/pre]