3D Canvas Community
3D Canvas Discussion Forums
Plug-In Development and Scripting
make face from selected points|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
|
Member |
has anyone done this?
I want a script that takes the selected points on an object and makes a face from them. ( have i missed this new function of 3dc?) i just wrote the script in 5 minutes to do it, but, as i knew would happen, the active points aren't in the right order toi make a proper curve (concave?) - i just loop through the active points and take them from the active object. so i need an algorithm to sort an array of points so i can add them to the face in the right order. i think i once saw it on the net, but now i cant even think what to look for. ta 4 your ideas george |
||
|
Member![]() |
What a great idea, Geo,
I doubt if you missed it, Les_Patterson and I talked about an easier way of making the window on models. It was awhile back and no one mentioned a function. Sure like it, though. KB |
|||
|
Member![]() |
The sample create triangle plugin does this with 3 points - an expansion of this to more points would be useful.
|
|||
|
|
Member |
That so true
|
|||
|
|
Member |
shoulda made myself clear. I didn't say "wouldnt this be a good idea?' I said 'someone do this for me' :-)
anyway her is some code that seems to work. lazy stream of conscious programming. one hand typing so no comments snd shrt var nms. hell to debug. debug code still in if you want to uncomment. try. let me know. hand hurts freom one hand typing so now got no good hands. just save as somethinf.cs in scripts dir. then select some vaguely coplanar points and run script. george ---next line must be first in script------------------ Language = VBScript '********************************************************************************* ' Purpose: Creates a Face from selectedc points '********************************************************************************* 'Option Explicit 'require variable declarations Dim fso,db const Pi= 3.14159265358979 'a greek delicacy Dim PiOn2 PiOn2=Pi/2 Dim apc 'ActivePointCount Dim info() Sub Main (CanvasApp) Dim Scene 'The current active scene Dim SceneRootGroup 'The root Group of the scene Dim Group 'The Group for our object (face) Dim CopyGroup 'where the face comes from Dim Object 'The object we are creating (face) Dim CopyObject Dim Face 'The face we are creating Dim ii 'for looping Dim GridOriginX 'The 3D Canvas Grid's Origin (x) Dim GridOriginY 'The 3D Canvas Grid's Origin (y) Dim GridOriginZ 'The 3D Canvas Grid's Origin (z) Dim GridSize 'The 3D Canvas Grid's Size Dim GridInterval 'The 3D Canvas 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 gx 'Group position Dim gy ' Dim gz ' 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 MaterialConst 'variables for file handling ' Set fso = CreateObject("Scripting.FileSystemObject" ' Set db = fso.CreateTextFile("c:\Program Files\Amabilis\Scripts\db.txt",true) 'get the scene Set Scene = CanvasApp.GetActiveScene 'get the active object count apc = Scene.GetActivePointCount ' msgbox ("apc " & apc) If apc > 2 Then redim info(apc,3) 'x,y,z,angle 'get the root Group Set SceneRootGroup = Scene.GetRootGroup 'create a Group for the object (face) Set Group = Scene.CreateGroup 'add it to the scene SceneRootGroup.AddChild Group 'give the Group a name - note that we can't do this 'until the Group is added to the scene Group.SetName "FaceFromPoints Group" '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 Set CopyObject = Scene.GetActiveObject(0) Set CopyGroup = CopyObject.GetParentGroup CopyGroup.GetPosition nothing,gx,gy,gz Group.SetPosition nothing,0,gx,gy,gz mx=0 'means my=0 mz=0 sdx=0 'standard devs sdy=0 sdz=0 for ii=0 to apc-1 Point = Scene.GetActivePoint(ii) CopyObject.GetPoint Point, info(ii,0), info(ii,1), info(ii,2) mx=mx+info(ii,0) my=my+info(ii,1) mz=mz+info(ii,2) Next mx=mx/apc my=my/apc mz=mz/apc 'msgbox ("centre " & mx & " " & my & " " & mz) for ii=0 to apc-1 sdx=sdx+(info(ii,0)-mx)^2 sdy=sdy+(info(ii,1)-my)^2 sdz=sdz+(info(ii,2)-mz)^2 Next sdx=sdx/apc sdy=sdy/apc sdz=sdz/apc 'msgbox ("sds " & sdx & sdy & sdz) if ((sdx elseif ((sdy else Axis=2 end if 'msgbox("axis " & axis) 'move to 000 for ii=0 to apc-1 info(ii,0)=info(ii,0)-mx info(ii,1)=info(ii,1)-my info(ii,2)=info(ii,2)-mz next for ii=0 to apc-1 select case Axis Case 2 'min var in z if info(ii,0)=0 then info(ii,3)=0 else info(ii,3)=atn(info(ii,1)/info(ii,0)) info(ii,3) = QuadrantFix( info(ii,3),info(ii,1),info(ii,0) ) end if Case 1 'min var in y if info(ii,2)=0 then info(ii,3)=0 else info(ii,3)=atn(info(ii,0)/info(ii,2)) info(ii,3) = QuadrantFix (info(ii,3),info(ii,0),info(ii,2)) end if Case 0 'min var in x if info(ii,2)=0 then if info(ii,1)>0 then info(ii,3)=Pion2 else info(ii,3)=Pi+Pion2 end if else info(ii,3)=atn(info(ii,1)/info(ii,2)) ' db.writeline("opp " & info(ii,1) & " adj " & info(ii,2) & " ang " & info(ii,3)) info(ii,3)= QuadrantFix (info(ii,3),info(ii,1),info(ii,2)) ' db.writeline("angle fixre " & info(ii,3)) end if end select next sort info, apc 'db.writeline("sorted" for i=0 to apc-1 'db.writeline(info(i,3)) next for ii=0 to apc-1 info(ii,0)=info(ii,0)+mx info(ii,1)=info(ii,1)+my info(ii,2)=info(ii,2)+mz next for ii=0 to apc-1 Object.AddPoint info(ii,0),info(ii,1),info(ii,2) Face.AddPointAndNormal ii,0 'add the points and the normal to the fac\\ Next '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 Group 'this also triggers the update to the database Group.AddObject Object 'set the object name - note that we can't do this until 'the object is added to a Group Object.SetName "FaceFromPoints" 'Now that we know the size of the object let's set the position of the Group 'so the face is visible 'get the 3D Canvs grid details ' CanvasApp.GetGridDetails GridOriginX, GridOriginY, GridOriginZ, GridSize, GridInterval 'get the object's dimensions ' Object.GetBoundingBox BoxMinX, BoxMinY, BoxMinZ, BoxMaxX, BoxMaxY, BoxMaxZ 'Center the Object's Group on the Scene and have the object sitting nicely 'on the surface ' Group.SetPosition SceneRootGroup, 0, GridOriginX + GridSize / 2, GridOriginY - BoxMinY, GridOriginZ + GridSize /2 else msgbox "need at least three points" End If 'db.close End Sub sub sort(a(),points) 'db.writeline("sorting" & points) dim i dim j dim k dim min dim tempmin dim temp() redim temp(3) 'redim buff(ipc,3) 'for i=0 to points-1' apc-1 ' db.writeline("a" & a(i,3)) 'next tempmin=0 for i=0 to points-2 min=i tempmin=a(i,3) for j=i+1 to points-1 if a(j,3) tempmin=a(j,3) end if next for k=0 to 3 temp(k)=a(i,k) a(i,k)=a(min,k) a(min,k)=temp(k) next next 'db.writeline("sorted" & points) 'for i=0 to points-1' apc-1 ' db.writeline(ii & "," & a(i,0) & "," & a(i,1) & "," & a(i,2) & ","& a(i,3)) 'next end sub function quadrantfix (ang, opp, adj) if ((opp>0) and (adj<0)) then ang=Pi+ ang elseif((opp<0) and [adj<0)) then ang=ang+Pi elseif ((opp<0) and [adj>0)) then ang=ang+ 2 * Pi end if quadrantfix = ang end function '---------------------------code ends-------------- |
|||
|
|
Member |
forgot to say you may need to invert the object created to see it.
|
|||
|
Member![]() |
I knew what you meant :P
and I never heard of a Greek pie. |
|||
|
Member![]() |
Geo
At the risk of evoking your rath, sore hand and all, does this mean I need to adjust the script ? Sorry, the only part that made sense to me was about the pie. KB |
|||
|
Member![]() |
line 84
|
|||
|
|
Member |
hmmm. ijust copiewd from the post and it worked for me. the error means the variable isn't declared, whic should be ok as Option explicit is commented out at the top.
sometimes wrapped long lines from a post muck things up too. back in a minute. |
|||
|
Member![]() |
Geo,
I re-copied the script and it works fine. If this makes sense, the very first " ' " was missing. Thanks and sorry. KB |
|||
|
|
Member |
|
|||
|
| Previous Topic | Next Topic | powered by eve community |
| Please Wait. Your request is being processed... |
|
3D Canvas Community
3D Canvas Discussion Forums
Plug-In Development and Scripting
make face from selected points
