Rotating a object... setting its orgin frist...

Hey ^^, well not as simple as just changing its H so you know. I need to some how changes in orgin frist to be able to change its H corretly… other wise the object will go into an orbit instead… img268.imageshack.us/img268/3065/22247315.png

Heres also an example if you like to actully see what I’m talking about…
sendspace.com/file/t1anqn

I was also told I could change its Bounds with getTightBounds… but I’m not sure what how to do that either…

Either way… I never usally ask this… but if you can get it to work and post the recode… I be most happy! lol.

wasd keys + mouse to move around…

You need to move the node to the origin, like:
(assuming mynode is the node you’re trying to rotate)

bounds = mynode.getTightBounds()
center = [bounds[0][0] + ((bounds[1][0] - bounds[0][0]) / 2), bounds[0][1] + ((bounds[1][1] - bounds[0][1]) / 2), bounds[0][2] + ((bounds[1][2] - bounds[0][2]) / 2)]
newnode.setPos(-center[0], -center[1], -center[2])

discourse.panda3d.org/viewtopic.php?t=8802

Nope ^^; doesn’t seem to work either…

      if NodePathName[0] == "WarpGate":
        boomGeom = nodePath
        boomGeomCenter = boomGeom.getBounds().getCenter() 
        boomGeom.getParent().setPos(boomGeomCenter) 
        boomGeom.setPos(-boomGeomCenter) 
        boomGeom.flattenLight()
        boomGeom.setScale(0.015,0.015,0.015)
        self.Gates[NodePathName[1]] = boomGeom
        self.SuperDeleteList.append(self.Gates[NodePathName[1]])
        NumberOfgeomNode = NumberOfgeomNode - 1

I perty much give on the issue ^^: theres no way it can work… lmao.

You probably need to scale first, then getTightBounds(), then setPos()

I tried that also. Doesn’t work. I think treeform has a option that could work tho. See what he post later to night/day.

It’s simpler to tell your exporter to preserve object’s transform.
Which exporter is it ?

Here is some code to apply a center to all geom vertexes or apply a matrix to all geom vertexes.

You should be able to hook this up to your bounds methods before to recenter the objects.


def geomsMove(model,moveVector):
    if type(model.node()) == GeomNode:
        geomNode = model.node()
        geomMove(geomNode,moveVector)
    for nodePath in model.findAllMatches('**/+GeomNode'):
        geomMove(geomNode,moveVector)
        
def geomMove(geomNode,moveVector):
    for i in range(geomNode.getNumGeoms()):
        geom = geomNode.modifyGeom(i)
        state = geomNode.getGeomState(i)
        #print geom
        #print state
        vdata = geom.modifyVertexData()
        #print vdata
        # process vertex
        vertex = GeomVertexRewriter(vdata, 'vertex')
        while not vertex.isAtEnd():
            v = Vec3(vertex.getData3f())
            v += moveVector
            vertex.setData3f(v)


              
def geomsApply(model,mat):
    if type(model.node()) == GeomNode:
        geomNode = model.node()
        geomApply(geomNode,mat)
    for nodePath in model.findAllMatches('**/+GeomNode'):
        geomApply(geomNode,mat)
        
def geomApply(geomNode,mat):
    for i in range(geomNode.getNumGeoms()):
        geom = geomNode.modifyGeom(i)
        state = geomNode.getGeomState(i)
        #print geom
        #print state
        vdata = geom.modifyVertexData()
        #print vdata
        # process vertex
        vertex = GeomVertexRewriter(vdata, 'vertex')
        while not vertex.isAtEnd():
            x,y,z = vertex.getData3f()
            v = Vec4(x,y,z,1)    
            v = mat.xform(v)
            x,y,z,w = v
            vertex.setData3f(x,y,z)