Notifications
Clear all

[Closed] Dummy as Bounding Box

When I run this script to create an assembly (from the reference docs), the Dummy head object takes on a really cool behavior were it looks like dummy.boxsize = assemblyBBoxsize, but updates in real time! Is there any way to recreate this outside of assemblies? Lets say I want Mydummy.boxsize = MyDummyChildrenBBoxsize (real time).

object1 = Cylinder() --create a cylinder

object2 = Box() --create a box

object3 = OmniLight()

object4 = sphere() 

obj_array = #(object1, object2, object3,object4) 

new_ass = assemblyMgr.assemble obj_array name:"Test01" classDesc:dummy

assemblyMgr.Open new_ass clearSelection:true
4 Replies
1 Reply
(@denist)
Joined: 2 years ago

Posts: 0

Here is my sample how to do this kind of things:


/****************************************************** 
by denisT
******************************************************/
 
plugin helper BBoxChildren
 name:"BBoxChildren" 
 classID:#(1967, 0x00000abc) 
 category:"Standard" 
 extends:dummy 
( 
 local lastData = #(), meshObj
 parameters main rollout:params
 (
  height type:#worldUnits ui:height default:0
  width type:#worldUnits ui:width default:0
  length type:#worldUnits ui:length default:0
 )
 rollout params "Dimention"
 (
  label height_lb "Height:" across:2 align:#right offset:[-10,0]
  spinner height type:#worldunits range:[-1e9,1e9,0] fieldwidth:64 enabled:off
  label width_lb "Width:" across:2 align:#right offset:[-10,0]
  spinner width type:#worldunits range:[-1e9,1e9,0] fieldwidth:64 enabled:off
  label length_lb "Length:" across:2 align:#right offset:[-10,0]
  spinner length type:#worldunits range:[-1e9,1e9,0] fieldwidth:64 enabled:off
 )
 
 fn getChildrenBBox node tm: = 
 (
  if tm == unsupplied do tm = node.transform
  local minx = #(), miny = #(), minz = #(), maxx = #(), maxy = #(), maxz = #() 
  for c in node.children do
  (
   bb = nodeGetBoundingBox c tm
   append minx bb[1].x
   append miny bb[1].y
   append minz bb[1].z
   append maxx bb[2].x
   append maxy bb[2].y
   append maxz bb[2].z
  )
  minx = amin minx 
  miny = amin miny 
  minz = amin minz 
  maxx = amax maxx 
  maxy = amax maxy 
  maxz = amax maxz
  
  #([minx,miny,minz],[maxx,maxy,maxz], [maxx,maxy,maxz]-[minx,miny,minz], ([maxx,maxy,maxz]+[minx,miny,minz])/2)
 )
 
 on getDisplayMesh do 
 (
  if (meshObj == undefined) do 
  (
   meshObj = createInstance box length:length width:width height:height 
  )
  node = (refs.DependentNodes this)[1]
  if node.children.count != 0 then
  (
   data = getChildrenBBox node
   if data[3] != lastData[3] or data[4] != lastData[4] do 
   (
	size = data[3]
	meshObj.width = width = size.x
	meshObj.length = depth = size.y
	meshObj.height = height = size.z
	node.objectOffsetPos = data[4]-[0,0,height/2]
	gc light:on
   )
  )
  else 
  (
   data = #()
   data[3] = [width, length, height]
   if data[3] != lastData[3] do
   (
	meshObj.length = data[3].x
	meshObj.width = data[3].y
	meshObj.height = data[3].z 
	gc light:on
   )
  )
  lastData = data
  meshObj.mesh
 )
 tool create
 (
  on mousePoint click do case click of
  (
   1: nodeTM.translation = gridPoint
   3: #stop
  )
  on mouseMove click do case click of
  (
   2: 
   (
	width = gridDist.y*2
	length = gridDist.x*2
   )
   3: height = gridDist.z
  )
 )
)


  1. Create BBoxChildren
  2. Link anything to it…
  3. And Play
 PEN

At a guess I would think that you are going to need callbacks for this as you can’t really set up a connection to it with controllers. That being said…

I don’t know if this will work but if you have a CA def that holds reference to the array of nodes using nodeTransformMonitor and a function to calculate the bounding box you could then have a script controller on an xform gizmos transform that references the CA def and calls the function.

How is that for a work around:S

 PEN

That works to, to bad helper objects are so slow in the viewport. This is part of what makes this work. The mesh is always being updated and never gets cached.

1 Reply
(@denist)
Joined: 2 years ago

Posts: 0

It’s slow because I call gc on every mesh rebuild… Otherwise the memory leaking is to big…