Update Prop Origin Only Working If I Display Message Boxes ??? [SOLVED - Stupid! Again... :) ]
3dcheapskate
Posts: 2,719
I have a section of code (from about line 1100 of a 1600 line script) to move the origin of the currently selected prop to the world origin while maintaining the prop's position in world space. It works fine:
// 3 - Move Prop Origin To World Origin
// Display current values
tx=oProp.getXPosControl().getValue()
ty=oProp.getYPosControl().getValue()
tz=oProp.getZPosControl().getValue()
ox=oProp.getOriginXControl().getValue()
oy=oProp.getOriginYControl().getValue()
oz=oProp.getOriginZControl().getValue()
sMsg += "
Current XYZ Translations: "+tx.toFixed(3)+","+ty.toFixed(3)+","+tz.toFixed(3)+"
Current Origin: "+ox.toFixed(3)+","+oy.toFixed(3)+","+oz.toFixed(3)
if (g_dsVer==3){ // OffsetA/B only exist in DS3 (and always seem to be zero, but just in case...)
ax=oProp.getXOffsetAControl().getValue()
ay=oProp.getYOffsetAControl().getValue()
az=oProp.getZOffsetAControl().getValue()
bx=oProp.getXOffsetBControl().getValue()
by=oProp.getYOffsetBControl().getValue()
bz=oProp.getZOffsetBControl().getValue()
sMsg+="
Current OffsetA: "+ax.toFixed(3)+","+ay.toFixed(3)+","+az.toFixed(3)+"
Current OffsetB: "+bx.toFixed(3)+","+by.toFixed(3)+","+bz.toFixed(3)
}
MessageBox.information(sMsg, "DEBUG", "&OK;", "" );
// Modify prop origin
setBusyCursor();
beginUndo();
var vOri = new DzVec3(-tx,-ty,-tz);
var vOriInv = new DzVec3(tx,ty,tz);
oProp.setOrigin(vOri, true);
if (g_dsVer==3){
oProp.setOffsetA(vOri, true);
oProp.setOffsetB(vOriInv, true);
}
acceptUndo( g_sTOOL_NAME + " (origin to world centre)");
clearBusyCursor();
// Display modified values
tx=oProp.getXPosControl().getValue()
ty=oProp.getYPosControl().getValue()
tz=oProp.getZPosControl().getValue()
ox=oProp.getOriginXControl().getValue()
oy=oProp.getOriginYControl().getValue()
oz=oProp.getOriginZControl().getValue()
sMsg="<br><b>Unchanged XYZ Translations:</b> "+tx.toFixed(3)+","+ty.toFixed(3)+","+tz.toFixed(3)+"
Adjusted Origin: "+ox.toFixed(3)+","+oy.toFixed(3)+","+oz.toFixed(3)
if (g_dsVer==3){ // OffsetA/B only exist in DS3 (and always seem to be zero, but just in case...)
ax=oProp.getXOffsetAControl().getValue()
ay=oProp.getYOffsetAControl().getValue()
az=oProp.getZOffsetAControl().getValue()
bx=oProp.getXOffsetBControl().getValue()
by=oProp.getYOffsetBControl().getValue()
bz=oProp.getZOffsetBControl().getValue()
sMsg+="
Adjusted OffsetA: "+ax.toFixed(3)+","+ay.toFixed(3)+","+az.toFixed(3)+"
Adjusted OffsetB: "+bx.toFixed(3)+","+by.toFixed(3)+","+bz.toFixed(3)
}
MessageBox.information(sMsg, "DEBUG", "&OK;", "" );
But if I DON'T display the before and after message boxes and just do this then the prop origin doesn't appear to be moved at all !
// 3 - Move Prop Origin To World Origin
// Modify prop origin
setBusyCursor();
beginUndo();
var vOri = new DzVec3(-tx,-ty,-tz);
var vOriInv = new DzVec3(tx,ty,tz);
oProp.setOrigin(vOri, true);
if (g_dsVer==3){
oProp.setOffsetA(vOri, true);
oProp.setOffsetB(vOriInv, true);
}
acceptUndo( g_sTOOL_NAME + " (origin to world centre)");
clearBusyCursor();
Any ideas?
Post edited by 3dcheapskate on
Comments
A Bit Of Further Clarification
I should probably add that the prop in question will have been set up in a specific way before running this:
1) First it's 'zeroed' and parented to a 'DummyHand' proxy prop (the script below does this).The prop origin will now be at the world origin.
2) It will have been translated so that the point I want to be the centre of rotation is at the origin. If any translations are applied then the prop origin will move away from the world origin. It is under these circumstances that I get the problem.
Then after I've moved the prop origin back to the world origin as in the OP I simply rotate the prop. That's how I know that the origin hasn't been moved correctly in the OP
Hmmm... It Looks Like It's Something To Do With The Other 1400-Or-So Lines Of Code In That Script...
Okay, my next step was to take my 1600-or-so-line script and extract just the bits that do the stuff I'm talking about.
That results in the 241 line script below, which seems to do exactly what it's supposed to, regardless of whether or not the message boxes are displayed.(You need to have the M4 Journeyer Scout 'In Hand' katana loaded and it should be the only thing in the scene that's selected)
- I've hard-coded the rotation/translation parameters for the M4 Journeyer Scout 'In Hand' katana (the 'In Scabbard'katana requires different values).
- I've commented out the loading/parenting to a DummyHand proxy, so that anybody can run this script.
- I've also commented out all the messageboxes.
If I uncomment all the commented out message boxes and DummyHand loading/parenting stuff it also works as it's supposed to
Soooo... I'm wondering if it's something to do with the other 1400-or-so lines of code?Especially since I had another still-unresolved problem (but with a different script) where the problem lines work fine in isolation... ("“WARNING: ReferenceError: getNodeParent is not defined” for DzDistantLight::getNodeParent() ??" also in this forum)
Anyway, here's the 241-line version:
Solved, I Think !
(aka... it's nice when you spot your own stupid mistake before anybody else does ! ...)
If anybody else spots it feel free to post here... LOL
(hint - I'd commented out something that should have been left in!) :oS