[Closed] How to get smoothing group of Edit_Poly faces?
using bit interface also causes memory leaking… do it this way:
local bit_or = bit.or
for f in faces where bit_or <...> n do...
it saves you a lot of memory
DenisT, can you show me where to find your method of how to get poly face using mesh face id?
Right now I use this:
(
local curObj = modpanel.getcurrentobject()
local tempMesh = copy $.mesh
local bit_get = bit.get
function GetFaceUsingVertsEPM curObj verts =
(
local faceVerts = #()
local faceCount = curObj.GetVertexFaceCount verts node:$
for i = 1 to faceCount do
append faceVerts (curObj.GetVertexFace verts i node:$)
faceVerts as bitarray
)
function GetVertUsingFacesEPM curObj faces =
(
local vertFaces = #()
local vertsCount = curObj.GetFaceDegree faces node:$
for i = 1 to vertsCount do
append vertFaces (curObj.GetVertexFace faces i node:$)
vertFaces as bitarray
)
-- created by Enrico Gullotti
function getPolyFromMeshFace iMeshFace =
(
if ((iMeshFace == 0) or (iMeshFace == undefined)) then
return 0
local aiMeshVert = (meshOp.getVertsUsingFace tempMesh iMeshFace) as Array
local aiPolyFromVert = #()
for iVert in aiMeshVert do
append aiPolyFromVert (GetFaceUsingVertsEPM curObj iVert)
local baPoly = aiPolyFromVert[1] * aiPolyFromVert[2] * aiPolyFromVert[3]
if (baPoly.numberSet == 1) then
(
return (baPoly as Array)[1]
)
else
(
local baMeshFaceInPoly = meshOp.getPolysUsingFace tempMesh iMeshFace ignoreVisEdges:false threshhold:90
local baMeshFaceVert = meshOp.getVertsUsingFace tempMesh baMeshFaceInPoly
for iPoly in baPoly do
(
local baPolyVert = GetVertUsingFacesEPM curObj iPoly
if (((baPolyVert - baMeshFaceVert).isEmpty == true) and ((baMeshFaceVert - baPolyVert).isEmpty == true)) then
(
return iPoly
)
)
)
)
for f in tempMesh.faces as bitarray do
(
for i = 1 to 32 where (bit_get(getfacesmoothgroup tempMesh f) i) do
(
epFace = getPolyFromMeshFace f
print epFace -- return only OK
-- apply unique matID to each faces
)
)
)
The function that get poly face from mesh is created by Enrico Gullotti. I added Edit_Poly support, but… not very efficient, because at some point of calculating the script stop and throw an error.
i couldn’t find it so i’ve written it again:
fn getPolyByMeshIndex node face show:on =
(
local mesh = node.mesh
polys = meshop.getpolysusingface mesh face
vlist = meshop.getvertsusingface mesh polys
faces = meshop.getfacesusingvert mesh vlist
verts = meshop.getvertsusingface mesh faces
delete mesh
epolys = (polyop.getfacesusingvert node vlist) - (polyop.getfacesusingvert node (verts - vlist))
if show do node.selectedfaces = epolys
epolys
)
fn getAllPolysByMeshIndex node = if iskindof node Editable_Poly do
(
local mesh_getpoly = meshop.getpolysusingface
local mesh_getvert = meshop.getvertsusingface
local mesh_getface = meshop.getfacesusingvert
local poly_getface = polyop.getfacesusingvert
mesh = snapshotasmesh node
done = #{}
plist = #()
plist.count = mesh.numfaces
for face in mesh.faces as bitarray where not done[face] do
(
polys = mesh_getpoly mesh face
vlist = mesh_getvert mesh polys
faces = mesh_getface mesh vlist
verts = mesh_getvert mesh faces
join done polys
epolys = (poly_getface node vlist) - (poly_getface node (verts - vlist))
p = (epolys as array)[1]
for f in polys do plist[f] = p
)
delete mesh
plist
)
actually to get all polys using opposite way is 5 times faster:
fn getAllPolysByMeshIndex2 node = if iskindof node Editable_Poly do
(
local mesh_getvert = meshop.getvertsusingface
local mesh_getface = meshop.getfacesusingvert
local poly_getvert = polyop.getvertsusingface
mesh = snapshotasmesh node
plist = #()
plist.count = mesh.numfaces
for face in node.faces as bitarray do
(
vlist = poly_getvert node face
flist = mesh_getface mesh vlist
verts = mesh_getvert mesh flist
faces = (mesh_getface mesh vlist) - (mesh_getface mesh (verts - vlist))
for f in faces do plist[f] = face
)
delete mesh
plist
)
meshop.getpolysusingface is very slow…
Thank you!
Still I have to find a way to set the materialID of each face without selecting it.
why do you want to use Edit_Poly modifier? to do the same things with Editable_Poly is much easier.
Personally I always try to avoid edit_poly, or I use it knowing that I’ll collapse the stack later.
How to get smoothing group of Edit_Poly faces :
–select faces using x smoothing group:
$.modifiers[1].selectBySmoothingGroup=2048
$.modifiers[1].setOperation #SelectBySmooth
–getting the face’s smoothing group:
$.modifiers[1].GetFaceSmoothingGroups 10
i told that the main problem of the using of the edit_poly modifier is the necessity of do it with opened modpanel. it makes everything slow…
where is the real point to stay with the edit_poly?
I will try to explain, but sorry for my english.
So, as I already said, the purpos of this is to create mask map. I’m using materialID to separete by color the elements of the objects.
My first idea was to work directly with the objects, but this will overwrite the existing materialIDs, and I think that this is wrong approach.
Then I decide to use theHold>begin() <-> theHold.Cancel(). This will allow me to work directly with the objects, but when I start testing one problem occure – every time when I press the Render button max show the “Raytrace engine Setup” dialog and the rendered image of the first object was black. NO mater what I use – theHold, scenestat оr maxHold <-> maxFetch the “Raytrace engine Setup” appear and the map of the first object is broken.
Another problem when working with original objects is that in some cases not every objects are Editable_Poly or Editable_Mesh. So I have to find a way to work with primitives and with PolyMeshObjects. I can convert them to editable_poly,but this will collapse modifier stack of objects, and the user may not want this.
Then I write the code that copy objects and convert copyes to editable_poly. The problem is when the object is too large – max(system) run out of memory and crash.
So,I have two options,but may be you can offer another one.
Option 1 – the user(or the script) save scene, convert all(needed) objects to editable_poly and work with them. Then the original scene will be loaded. I’d prefere this mothod, but CodeFather(the guy that work with me on RTTAssist) don’tlike it.
OPtion 2 – use the Edit_Poly modifier on top of the modifier stack ot every objects. This will allow me to set what ever materialID I want, to bake the mask map and when the script delete the edit_poly modifier the objects will be in its initial state – no modifications by the script.
But in maxscript referense is written:
[left]<Edit_Poly>.smoothingGroupsToSet Integer default: 0 -- integer; Smoothing_Groups_to_Set
[left]Get/Set the smoothing group to set.[/left]
So,the GET is now working.
[/left]