Notifications
Clear all

[Closed] "addModifier $ (CameraMap CameraNode:$Camera01)" doesn't work

Hi all,

  I am participating in an online course here in CGSociety and the tutor pointed out, that the following doesn't work for some reason:
addModifier $ (CameraMap CameraNode:$Camera01)

It does apply the Modifier, but it does not pick the camera. And it doesn’t throw an error message or complain in any way.
Even stranger is, that if you execute the exact same line twice, the second CameraMap-Modifier DOES pick the Camera correctly!?!

  And if you do not initialise the 'CameraNode' in the Constructor but later on, things are also fine:
for o in $ do (
      	addModifier o (CameraMap())
      	o.modifiers[1].CameraNode = $Camera01
      )

But why does it not work with the first line I’ve shown?
Is that a bug, or do we miss something here?
Thanks for help.
Uli

3 Replies

not missing anything… and it’s not typically classified as a bug either, but rather as unexpected behavior.

The plugin itself has some internals that only get triggered after the modifier’s creation has complete passed through 3ds Max’s notifications system. When you use the one-liner, that is not the case. It is similar to:


test = createInstance CameraMap
CameraMap:Camera Map Modifier
test.cameranode = $Camera01
$Free_Camera:Camera01 @ [36.113480,12.238129,0.000000]
test.cameranode
undefined

This was actually the topic of a short discussion on our online chat… somebody asked how to get the default value of an object (node, modifier, material, etc.) and I mentioned to them that the only valid way to get that is by actually creating it first – there’s no way to just look it up, and creating an in-memory instance (via createInstance) can sometimes fail to fully initialize the object.

Just to show how the initialization makes for some very odd behavior:


	-- this won't have the camera node set up
	addModifier $ (CameraMap CameraNode:$Camera01)
	-- but this one will
	addModifier $ (CameraMap CameraNode:$Camera01)

Thanks for clarification, ZeBoxx2!

Something like this works fine:


  	arr = for s in selection collect s
  	
  	for a in arr do 
  	(
  		local cam = getNodeByName "ProjectionCam"
  		local cm = CameraMap CameraNode:cam
  		local obj = getNodeByName a.name
  		addModifier obj (copy cm)
  		obj.modifiers[1].CameraNode = cam
  		update obj
  	)