PDA

View Full Version : Skin Modifier Issue And Alternative


johnwhile
11-19-2010, 02:56 PM
Hi, i have a big problem of crash when i utilize the skin modifier in my script
This is a small description of my script:

Struct MeshClass
(
filename = "", Faces=#(),FacesIndex=#(),FacesName=#(),VertsData=#(),TVertsData=#(),
WeightsData=#(), -- bone1_idx ; bone2_idx ; %bone1
NormalData=#(),BoneMesh=#(),BoundingSphere=#(),TextureData=#(),SkeletonData=#(),
fn deleteProp =
(
Faces=FacesIndex=FacesName=VertsData=TVertsData=NormalData= undefined
),
fn AssignWeight Weight_Arrar Obj_Array=
(
st = timeStamp()
format "Drawing weight bone...\n"
progressStart "Drawing weight bone"
cont = Obj_Array.count
listen = stringStream ""
for i=1 to cont do
(
progressUpdate ((i*100.0/cont) as integer)
format "obj%\n" i
obj = Obj_Array[i]
weight = Weight_Arrar[i]
if obj.numverts != weight.count do (MessageBox "Attention, error in the object" ; return False)

theskin = Skin()
theskin.rigid_vertices = false
select obj
max modify mode
addModifier obj theskin
skinops.buttonInclude theskin
for i=1 to SkeletonData.count do
(
skinOps.addbone theskin (getNodeByName SkeletonData[i].Bone.name ) 1
)
nbone = skinops.getNumberBones theskin
obj.selectedVerts = #{1..obj.numverts}
skinOps.resetSelectedVerts theskin
nverts = skinops.getNumberVertices theskin

for i = 1 to obj.numverts do skinOps.ReplaceVertexWeights theskin i 1 1.0
update obj geometry:true normals:true
redrawViews()
format "%\t%\t%" obj.name obj.modifiers[#Skin] nbone to:listen
)
close listen
format "%\n" (listen as string)
ok
),
fn readMesh =
(
-- a function that import data from a binary file
),
fn buildgeometry =
(
-- after readMesh() i build the object with all information, only bone assignment must be assigned after, a "Weight_Arrar" and "Obj_Array" was generate to store all mesh and relative vertex's weight
deleteProp()
AssignWeight Weight_Arrar Obj_Array
--enableSceneRedraw()
--redrawViews()
clearSelection()
)
)


This script work, there aren't error message but when i clic on the scene there are a crash !!!
http://img89.imageshack.us/img89/3709/immaginejl.th.jpg (http://img89.imageshack.us/i/immaginejl.jpg/)

I have made a lot of variant but it crash everytime... so I decided starting my own skin modifier as a plugin ... but is very frustrating this issue

johnwhile
11-20-2010, 10:02 PM
i make a little check, this is the synthetic code:

FOR LOOP
...
theskin = Skin()
theskin.rigid_vertices = false
select obj
addModifier obj theskin
max modify mode
checkmod = modPanel.getCurrentObject()
format "CURRENT: %\n" checkmod
if checkmod==undefined then error.e -- make a "stop error"
skinops.buttonInclude theskin
...

Listener:

CURRENT: Skin:Skin --loop1
CURRENT: undefined --loop2

the problem is on second loop, the checkmod = modPanel.getCurrentObject() return undefined but is not possible... why max crash in the modifier pannel ????

eek
11-21-2010, 05:58 PM
I really don't know what your trying to do, from what i can make out your trying to add bones to a skin modifier. Something like this:

fn addBoneToSkin skinMod bones =
(
-- we check the modifier is valid
if classOf skinMod == Skin do
(
-- set the rollout panel
max modify mode
modPanel.setCurrentObject skinMod

-- add the bones
for each in bones do
(
if each != undefined do
(
skinOps.addBone each 1
)
)
)
)


To load weights onto a vertex you need an array of bone IDs reflective of the bone list in the skin modifier, and an array of weights - that equal one. If you want every vertex set to the first bone with a weight of one:

fn setDefaultWeight skinMod =
(
local skinObj

if classOf skinMod == Skin do
(
max modify mode
modPanel.setCurrentObject skinMod

-- we get the dependent mesh from the skin
skinObj = (refs.dependents skinMod)[3]

-- we should check if there are bones to skin
if skinOps.getNumberBones skinMod >= 1 do
(
-- we set the weight
for v = 1 to skinObj.verts.count do
(
skinOps.ReplaceVertexWeights skinMod v 1 1.0
)
)
)
)

johnwhile
11-22-2010, 10:04 AM
THANK for answer, but i found the problem:
i have utilized the ProgressBar (ProgressStart ""; progressEnd(); progressUpdate() ) but i put two ProgressStart "", the second bar make some problem with modify mode of max, in fact all work if i write:
.
..
...
theskin = Skin()
theskin.rigid_vertices = false
select obj
--resumeEditing()
addModifier obj theskin
max modify mode
modPanel.setCurrentObject theskin

checkmod = modPanel.getCurrentObject()

format "current_modifier: %" checkmod
if checkmod==undefined do
(
format "--> Error, try to resume -->"
resumeEditing()
select obj
max modify mode
modPanel.setCurrentObject theskin
checkmod = modPanel.getCurrentObject()
format "current_modifier: %" checkmod
if checkmod==undefined do return undefined
)
format "\n"
skinops.buttonInclude theskin
...
..
.
from listener:

CURRENT: Skin:Skin
CURRENT: undefined ERROR, TRY TO RESUME CURRENT: Skin:Skin
CURRENT: undefined ERROR, TRY TO RESUME CURRENT: Skin:Skin
CURRENT: undefined ERROR, TRY TO RESUME CURRENT: Skin:Skin
etc...

i delete the progressBar and all work:

CURRENT: Skin:Skin
CURRENT: Skin:Skin
CURRENT: Skin:Skin
CURRENT: Skin:Skin
etc...

But i have windows7 x64 and if the script run for more than 7 seconds 3dstudio sleep until the script stop... with progressBar windows have a lot of "output" from 3dstudio and don't sleep.... but the modify panel don't work...

So i must delete the progressBar dialog and all work correctly

johnwhile
11-25-2010, 06:52 PM
NO SORRY, the problem isn't the ProgressBar...
i make the simple function:

function AssignWeight obj weight SkeletonData=
(
try
(
max modify mode
select obj
subObjectLevel = 0
Local theskin = Skin()
addModifier obj theskin
Local theskin = obj.modifiers[#Skin]
subobjectLevel = 1
modPanel.setCurrentObject obj.modifiers[#Skin]
subobjectLevel = 1
skinOps.addbone theskin (getNodeByName SkeletonData[1].Bone.name ) -1
update obj
obj.selectedVerts = #{1..obj.numverts}
skinOps.resetSelectedVerts theskin
update obj
subObjectLevel = 0
deselect obj
)
catch getCurrentException()
)

the script don't make error, but the bone aren't added in the list and when i clic on object the 3dstudio crash !
I don't undertand why... all is correct.
If i use the only function:
addModifier obj theskin
without all other "skinOps." function, 3dstudio don't crash... the problem is on "skinOps.addbone", it don't work !

eek
11-26-2010, 05:22 AM
Roughly, I'm not at my desk...


fn addSkinNBones obj boneNames =
(
if obj != undefined do
(
local skinMod, bone

addModifier obj (skin())
skinMod = obj.skin

max modify mode
modifyPanel.setCurrentObject skinMod

for each in boneNames do
(
bone = (getNodeByName each)

if bone != undefined do
(
skinOps.addBone skinMod bone 1
)
)
)
)

johnwhile
11-26-2010, 11:01 AM
I put my script in a essential version, the script apply the skin() modifier and if you clic ok in the queryBox the script add the bones in the skins witout error.
BUT:
when i clic on box objects the 3dstudio crash !?! WHY ???

CGTalk Moderation
11-26-2010, 11:01 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.