Home Technical Talk

[MAXScript] WM3_MC_BuildFromNode problem

polycounter lvl 13
Offline / Send Message
Wesley polycounter lvl 13
Okay I've hit brick wall with a script I'm working on.

Essentially I'm checking that two objects have the same topology, so I'm using a morph and adding one to another and checking that it worked.
originalMesh = $box01
newMesh = $box003

originalMeshCheck = copy originalMesh
--Delete modifier because the original mesh already has a morpher modifier
deleteModifier originalMeshCheck 1
--define modifier
compatibilityCheck = (Morpher())
--add modifier to new mesh and check if it's compatible with the original mesh
addModifier newMesh compatibilityCheck
WM3_MC_BuildFromNode compatibilityCheck 1 originalMeshCheck

In my script the originalMesh and newMesh are picked in other methods, but are defined and called with no problem. Later on there is a check for whether slot 1 in the morpher has data.

So long story short, the modifier is added but it won't load in the mesh. Even though it works when I do it myself. If I run this code right here in its own script it works but then in my script it doesn't; yet it's executed in the same way.

Replies

  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter
    I've been struggling with this myself the last couple of days - does it work the second time you try it ?

    I'm pretty sure it's down to when and how you declare variables - you could try explicitly making everything global to and declaring them right at the top to test whether that's the problem or not (you'll need to clear them out manually after running the script btw)
  • Wesley
    Options
    Offline / Send Message
    Wesley polycounter lvl 13
    Okay well I've tried declaring the variables in a different manner but I'm still having no luck.
    --Boolean gates
    	global selectedMeshes = false
    	global meshHasMorpher = false
    	global meshesMatch = false
    	
    	on originalMeshPick pressed do
    	(
    		--1.Define what meshes are what
    		global originalMesh = originalMeshPick.object
    	)
    	on newMeshPick pressed do
    	(
    		--1.Define what meshes are what
    		global newMesh = newMeshPick.object
    	)
    	on transposeBtn pressed do
    	(		
    		--Check that user hasn't deleted picked meshes
    		if (originalMesh != undefined and newMesh != undefined) then
    		(
    			--1.Define what meshes are what
    			--Selected meshes?
    			selectedMeshes = true
    		)
    		else
    		(
    			messageBox "Error: Mesh(es) have been deleted"
    		)
    		
    		--Check that original mesh has a morph modifier at the top of the stack
    		if selectedMeshes == true then
    		(
    			if classOf originalMesh.modifiers[1] == Morpher then
    			(
    				meshHasMorpher = true
    			)
    			else
    			(
    				messageBox "Error: Original mesh needs morph target"
    			)
    		)
    		
    		--Check that meshes have same topology
    		if meshHasMorpher == true then
    		(
    			--2.Check if meshes are compatible
    			--Copy original mesh and delete morpher
    			originalMeshCheck = copy originalMesh
                            --delete morpher modifier present on the originalMeshCheck
    			deleteModifier originalMeshCheck 1
    			--add modifier to new mesh and check if it's compatible with the original mesh
    			addModifier newMesh (Morpher())
    			WM3_MC_BuildFromNode newMesh.morpher 1 originalMeshCheck
    		)
    	)
    
  • Wesley
    Options
    Offline / Send Message
    Wesley polycounter lvl 13
    Obviously I have two pick buttons and a regular button that are functioning fine.
  • Wesley
    Options
    Offline / Send Message
    Wesley polycounter lvl 13
    Okay it's definitely to do with it simply being in a button.
    on bigBtn pressed do
     (
     originalMesh = $originalBox
     newMesh = $newBox
     originalMeshCheck = copy originalMesh
     compatibilityCheck = (Morpher())
     addModifier newMesh compatibilityCheck
     WM3_MC_BuildFromNode compatibilityCheck 1 originalMeshCheck
     --Then there'd be an if statement to check if morph data present
     )
    

    This works flawlessly if I just run it manually line by line, as soon as it's ran within a button press it doesn't work though (the modifier is added but that's it).

    I have no idea why being in a button press would break it.
  • Wesley
    Options
    Offline / Send Message
    Wesley polycounter lvl 13
    Okay I fixed it.

    Essentially before I add the morph target I have to select the object.

    Makes no sense; I shouldn't have to select it; it works if I manually run that single line without it selected - but in the script it needs to be selected.

    Moral of the story: MAXScript makes no sense sometimes.
Sign In or Register to comment.