Fitting an object to engulf another one

Hello,

As a simple way to ‘highlight’ an object in the world, I thought it would be sensible to create a sphere and scale it to fit the bounds of the object, have the sphere transparent, and then show it centered on the object.

I have trawled the forums and found that there is no easy primitive sphere class, but I have managed indeed to load a primitive from a panda 3d egg.pz file in the models directory that comes with it, I’ve managed to set the material on it and used one of the suggested transparency techniques.

But what I’ve not found is a way to set the scale appropriately. Is there a sensible method like:

sphere.setScaleToFit(nodePath)

or something like that?

How else should I do it? Should I instead calculate the radius of the bounds of the object to be highlighted and then scale the sphere accordingly (assuming e.g. it is of unit radius)

Perhaps this is the best idea unless anyone else has a good suggestion?

Greg

sphere.reparentTo(yourNode)
sphere.setScale(yourNode.getBounds())

haven’t tested it but something like that.
you can also highlight it by setting the color, or colorscale of the nodepath.

Hmm, I don’t think its as simple as calling setScale with the bounding volume as parameter, but you could do it that way for sure. Calculate the bounding volumes for both, divide one by the other and scale based on that factor.

Okay thanks for this. I have found a reasonably satisfactory way of doing it by dividing the target object’s bounds’ radius by the radius of the sphere’s bounds, increasing this slightly and then using this factor as the scale on the sphere.

Regarding transparency: surely using color scale wouldn’t kind of put a sphere around the whole thing (it would just adjust the colours of the faces of the object itself). Secondly, what is the ‘standard’ way of achieving some transparency. At the moment I am using

attrib = ColorBlendAttrib.make(ColorBlendAttrib.MAdd,
ColorBlendAttrib.OIncomingAlpha, ColorBlendAttrib.OOne)
self.getNodePath().node().setAttrib(attrib)
self.getNodePath().setBin(‘fixed’, 0)

myMaterial = Material()
myMaterial.setAmbient(VBase4(0,1,0,1))
self.getNodePath().setMaterial(myMaterial)

I’m not quite sure how the colorblendattrib thing is working. Is there a simpler/more approved way?

Thank you

Greg

setTransparency(TransparencyAttrib.MAlpha) should work, too.

More about transparency:
panda3d.org/manual/index.php/Trans … d_Blending

But then how to set the actual level of transparency?

setAlphaScale(0~1)