Object's Center Point

I’m sure every P3D user knows that an objects center point is based on it’s position when exported from what ever app you exported it from; with the center being at x=0 y=0 coords.

This can make things difficult if you want to rotate an object based on it’s true center point, while the game is running, and not based on it’s position in 3D space, in the app you exported it from (which is the center of the screen or 3D space).

Is there a way to recalculate an objects center using P3D’s APIs? I don’t want my object’s position to change if a recalculation can be done, I just ‘wanna’ be able to spin an object on its “H” and not have it rotate around the world axis which is at 0, 0.

“Gohd!” Is there a way to stop this behavior? Someone…anyone… HELP!!! :cry:

You don’t need to recalculate anything (which is possible, of course). The simple way would be to just add a new PandaNode, and reparent your model’s PandaNode to this node. Then offset your model’s PandaNode in the desired way. Apply transforms, e. g. heading, to the new PandaNode.

Example: Assuming your model is a box with it’s origin in the “lower left” corner and extends of 1 x 1 x 1, that is from Point3(0,0,0) to Point3(1,1,1). You want the origin to be the “center” of the box, and not the lower left edge, that is Point3(0.5, 0.5, 0.5).

rootNP = render.attachNewNode('root') # the new node
modelNP = loader.loadModel(...) # your model node
modelNP.reparentTo(rootNP)
modelNP.setPos(0.5, 0.5, 0.5)

rootNP.setPos(...)
rootNP.setH(30.0)

If you want to recalculate the pivot point, I guess you could get the bounding box of the model ( getBounds()?), reposition the node according to that and then use flattenLight(). I don’t remember what getBounds() returns and if flattenLight() only bakes transforms, would like to know that myself.

The thing about using a PandaNode… If you have to reposition the Node, then you might as well just export your Object from your modeling app at point x=0, y=0. Then you can just reposition your Model and the Model’s center axis will run through its center.

This is what I have been doing in some places of my project, but that is also what I want to avoid because it’s time consuming when something is off position by “point some number” and you have to tinker with it.

Much more effective to just position before exporting. It’s like my Main Character. It was exported with a center position inside the modeling app, so when using the model in P3D, it’s center axis is right where it should be.

When level designing, everything can’t sit at 0,0 of course, so it gets exported in position, but the origins for all objects are still tied to P3D’s world center.

P3D could use some form of object center point management.

If you want to preserve each object’s local transform, you should tell the exporter to do so. What’s yours ?

Chicken exporter.

I don’t understand what you are actually asking for. I think we agree that it is possible to move the model’s origin (the “centre point”) in different ways:

  • within the modelling application (or even the exporter)
  • within the Panda3D scene graph
  • in between using the EGG API to load/modify/save a model

Since you ask for a “centre point management” I assume you want some functionality within Panda3D itself.
Can you please suggest an API (new objects or methods)?

Chicken by default exports local transform.

Try 1 of my chicken exported scenes HERE, using this script :

from panda3d.core import Mat4,Vec3
import direct.directbase.DirectStart

a = loader.loadModel('trial1-AO')
a.reparentTo(render)

for c in a.getChild(0).getChildren():
    c.hprInterval(2,Vec3(360,360,0)).loop()

camera.setPos(-6.29, -12.33, 11.52)
camera.setHpr(-28.31, -40.71, -2.11)
mat = Mat4(camera.getMat())
mat.invertInPlace()
base.mouseInterfaceNode.setMat(mat)
run()