CompassEffect again.....

In this scene, the axis should be moving along with the right smiley (it’s parented to the smiley), but it stays still.

import direct.directbase.DirectStart
from direct.interval.IntervalGlobal import Sequence
from pandac.PandaModules import CompassEffect

lilSmileyR=loader.loadModelCopy('misc/lilSmiley')
lilSmileyR.reparentTo(render)
lilSmileyR.setX(.8)
Sequence( lilSmileyR.scaleInterval(1,.5),
          lilSmileyR.scaleInterval(1,1)).loop()

lilSmileyL=loader.loadModelCopy('misc/lilSmiley')
lilSmileyL.reparentTo(render)
lilSmileyL.setX(-.8)

axis=loader.loadModel('zup-axis')
axis.reparentTo(lilSmileyR)
axis.setScale(.1)
axis.setX(-.8)

# marvelous failure ??
axis.setEffect(CompassEffect.make(lilSmileyL, CompassEffect.PScale))

base.cam.setY(-5)
run()

???

I don’t understand what you mean. It seems to be working correctly to me.

You are animating the scale of the right smiley, and you have parented the axis to the right smiley. If there were no CompassEffect, the axis would indeed be inheriting the right smiley’s scale, and would therefore be moving with the right smiley.

But you have added a CompassEffect, and you have used this CompassEffect to specify that the axis’s scale should track the scale of the left smiley instead. Since the scale of the left smiley is not changing, the axis’s (apparent) scale is not changing either. Thus the axis does not appear to be moving.

So the CompassEffect is doing exactly what it is supposed to. What is the problem here?

David

So CompassEffect ignores the parent’s scale.
This is what I need :

import direct.directbase.DirectStart
from direct.interval.IntervalGlobal import Sequence
from pandac.PandaModules import CompassEffect
from direct.task import Task

def followPos(obj,ref):
    Os=obj.getPythonTag('myCompass')
    Rs=ref.getScale(obj.getParent())
    obj.setScale(Os[0]*Rs[0], Os[1]*Rs[1], Os[2]*Rs[2])
    return Task.cont
def myCompass(obj,ref):
    obj.setPythonTag('myCompass',[obj.getSx(),obj.getSy(),obj.getSz()])
    taskMgr.add(followPos,'%s compass %s' %(obj.getName(),ref.getName()),extraArgs=[obj,ref])

def myCompassTrick(obj,ref):
    parent=obj.getParent()
    newParent=parent.attachNewNode('CEdummy')
    newParent.setPos(obj.getPos())
    obj.wrtReparentTo(newParent)
    obj.setEffect(CompassEffect.make(ref, CompassEffect.PScale))

lilSmileyL=loader.loadModelCopy('misc/lilSmiley')
lilSmileyL.reparentTo(render)
lilSmileyL.setX(-1)

lilSmileyR=loader.loadModelCopy('misc/lilSmiley')
lilSmileyR.reparentTo(render)
lilSmileyR.setX(1)
axis=loader.loadModel('zup-axis')
axis.reparentTo(lilSmileyR)
axis.setScale(.04)
axis.setX(-.5)
Sequence( lilSmileyR.scaleInterval(1,.5, blendType='easeOut'),
          lilSmileyR.scaleInterval(1, 1, blendType='easeIn')).loop()
# complicated
myCompass(axis,lilSmileyL)
# this trick works
#myCompassTrick(axis,lilSmileyL)

lilSmileyB=loader.loadModelCopy('misc/lilSmiley')
lilSmileyB.reparentTo(render)
axis2=loader.loadModel('zup-axis')
axis2.reparentTo(lilSmileyB)
axis2.setScale(.06)
axis2.setX(-.5)
Sequence( lilSmileyB.scaleInterval(1,.1, blendType='easeOut'),
          lilSmileyB.scaleInterval(1, 1, blendType='easeIn')).loop()
# complicated
myCompass(axis2,lilSmileyL)
# this trick works
#myCompassTrick(axis2,lilSmileyL)


base.cam.setY(-5)
run()

It is not so much that CompassEffect ignores its parent’s transform, but that it is specifically designed to exactly compensate for it (by implicitly applying the inverse transform). This is the whole raison d’être of the CompassEffect. So when you create a CompassEffect with PScale, you are specifically asking it to “ignore” the parent’s scale and apply the scale from the specified object instead.

If you want the parent’s scale to affect the object’s position, but not otherwise scale the object, then the right solution is to introduce an intervening node above the CompassEffect, and store the object’s position on that node. Then the scale will affect the position in the normal way, and when the CompassEffect kicks in below that node, it will neutralize any further applications of scale. This is basically what you have done in “myCompassTrick”.

David