Notifications
Clear all

[Closed] helper objects

 PEN

Have a look at my down loadable control objects for Max as well for reference on using the drag and drop method with mouse tools.

I’m having some trouble getting this scripted helper objects to work.

Basically I want a scripted plugin to be able to use it’s own helper object. So, I am first trying to make the helper object plugin.

To make a helper object plugin It seems that I have to override getDisplayMesh to createInstance of some object, then return that object.mesh, and also set useWireColor to false. I can script the creation of an object, but I can’t use createInstance on that…so it seems that I need to first make a geometryPlugin of the shape, so that I can create an instance of it to use in the helper object, to use in the real plugin. I will make the first 2 be invisible plugins.

The geometry plugin works fine, and I set the scripted geometry object to be the mesh local var of this plugin.

Then in the helper plugin, I try to create an instance of this but it says “attempt to access deleted scene object” and then gives me an error when I try to create something.

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

No, you are thinking to complicated. The only thing the getDisplayMesh needs is a TriMesh value, and it does not matter where it comes from.
You can take it from an instance, or you can build it yourself inside the plugin by providing a list of vertices and faces, just like you can do with simple geometry plugins.
What people suggested here was to take an existing scene object, snapshot its vertex and face data, write to two arrays and hardcode these arrays into the plugin’s source.

Here is an example:


plugin Helper ArrowHelper
name:"ArrowHelper" 
classID:#(0x47db14ff, 0x4e9b5f92) 
category:"Standard" 
extends:dummy 
( 
local lastSize, meshObj, theMesh, lastHeadWidth, lastHeadHeight, lastStemWidth 

parameters pblock rollout:params
(
	size type:#float animatable:true ui:size default:1.0
	headWidth type:#float animatable:true ui:headWidth default:0.5
	headHeight type:#float animatable:true ui:headHeight default:0.5
	stemWidth type:#float animatable:true ui:stemWidth default:0.3
)

rollout params "Arrow Helper Parameters"
(
	spinner size "Size:" range:[0, 1e9, 1]
	spinner headWidth "Head Width:" range:[0, 1.0, 0.5] scale:0.01
	spinner headHeight "Head Height:" range:[0, 1.0, 0.5] scale:0.01
	spinner stemWidth "Stem:" range:[0, 1.0, 0.3] scale:0.01
)

on getDisplayMesh do 
(
    if theMesh == undefined OR size != lastSize OR lastHeadWidth != headWidth OR  lastHeadHeight != headHeight OR lastStemWidth != stemWidth do 
	(
    	local vertsArray = #( [0,0,0], [headWidth,-headHeight ,0], [stemWidth,-headHeight ,0], [stemWidth,-1,0],[-stemWidth,-1,0],[-stemWidth,-headHeight ,0],[-headWidth,-headHeight ,0])
		local facesArray = #([1,7,6], [1,3,2], [3,5,4], [3,6,5])
    	local edgeVis = #( #(true,true,false), #(false,true,true), #(false,true,true), #(false,true,false) )
		meshObj = mesh vertices:(for v in vertsArray collect v*size) faces:facesArray 
		for face = 1 to edgeVis.count do 
			for i = 1 to 3 do 
				setEdgeVis meshObj face i edgeVis[face][i] 
		theMesh = meshObj.mesh
		delete meshObj
		lastSize = size
		lastHeadWidth = headWidth 
		lastHeadHeight = headHeight
		lastStemWidth = stemWidth 
	)
theMesh
)--end getDisplayMesh

tool create
(
	on mousePoint click do
		case click of
		(
			1: nodeTM.translation = gridPoint
			2: #stop
		)
	
	on mouseMove click do
		case click of
		(
			2: (size = length gridDist)
		)
)--end tool create
)--end plugin

 PEN

Hey Bobo, I just tried the code and it crashed Max out. Does it work at your end?

 PEN

It was in Max 8 that it died. Max 7 appears to work just fine.

 PEN

I love reading your code Bobo, I always learn a little something. It is always at least one line shorted then mine and just a bit cleaner. Thanks for posting that. I just need to clean up some of mine now.

hi bobo

I cant thank you enough for your informative codes. Im learning so much from you. Thanks once again for the script. I will now read through it and gain an understanding of what you have done

many thanks

nebille

Thanks Bobo, I will have a thorough read through of this soon!

For now, the script seems to crash from this:


theMesh = meshObj.mesh
		delete meshObj

You have to change it to:

theMesh = copy meshObj.mesh

then it will work in Max 8. I didn’t try it in 7…maybe they changed how this function works or something. You could probably also leave out the copy statement if you changed theMesh value because then max should implicitly make a copy of it

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Thanks, I assume there is a change in the Garbage Collector in 8 that causes that.
It runs great in 7…

Page 2 / 2