Irregular Faces

I don’t think this is a problem if you are applying the texture outside the script. andnbsp;if you create the faces as part of one 3D C object, the use the texture tool (the bucket one) it will apply the texture andnbsp;as specified in the material editor.

If you want to apply the texture in the script, however, I think you have to work out the UV stuff separately for each face.

George

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]

Thanks.
Sounds like a bit much for me. andnbsp;I was hoping there was something simple function call I could exercise.

This is pretty tricky actually. As you figured out, a simple tesselation won’t work. Direct3D is only capable of properly rendering planar, convex polygons. You have a concave polygon. There are algorithms available to turn a concave polygon into equivalent convex polygons. A search of the ‘net should find one.

Richard

Thanks. andnbsp;I was hoping to texture the irregular face as one face. I did not want to texture each subface separately. andnbsp;

perhaps you could try this?

Instead of creating a poly with many points and then triangulating, why not use your script to create many faces. andnbsp;As you have already added points to the object, you could also add faces to the object. andnbsp;For the shape you’ve shown you would only need four or five faces to make it ok.

But it depends on what you ultimately intend. andnbsp;If you’re only doing it once, this method is ok. andnbsp;Depends on what the ultimate goal of the scipt is.

George

Thanks for the feedback. andnbsp;I think my polygons are simple enough that all I have to do is start at another point in the polygon such that the interior faces don’t cross a border. andnbsp;I always wanted to start the polygons at the origin so that when I looked at my data later I would understand the dimensions I used.

You must be logged in to reply in this thread.