Skip to content

Commit

Permalink
Fix #1198 separate dimensions on 3D cam rigs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico-Duduf committed Jan 2, 2024
1 parent 77d4093 commit 83bc130
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions src/inc/api/camera.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ Duik.CmdLib['Camera']["Camera rig"] = "Duik.Camera.rig()";
/**
* Rigs a camera to make it easier to animate
* @param {CameraLayer} [camera] The camera to rig. If omitted, will try to find it in selected layers or the active comp.
* @param {Boolean} [separateDimensions] Whether to separate the position dimensions on the controllers. If the option is not set, Duik will check if the current camera has its dimensions separated first
* @return {ShapeLayer[]} An array of controllers: [target, cam, main], which may be empty if no camera was found or if it was a one-node camera.
*/
Duik.Camera.rig = function( camera )
Duik.Camera.rig = function( camera, separateDimensions )
{
camera = def(camera, DuAEComp.camera());
if (!camera) return [];
Expand All @@ -151,6 +152,8 @@ Duik.Camera.rig = function( camera )

camera.locked = false;

separateDimensions = def(separateDimensions, camera.transform.position.dimensionsSeparated);

// Position must not be separated
if (camera.transform.position.dimensionsSeparated)
camera.transform.position.dimensionsSeparated = false;
Expand All @@ -163,20 +166,23 @@ Duik.Camera.rig = function( camera )
Duik.Controller.setLimbName( i18n._("Target"), targetCtrl );
targetCtrl.threeDLayer = true;
targetCtrl.position.setValue(camera.transform.pointOfInterest.value);
targetCtrl.position.dimensionsSeparated = separateDimensions;

//create cam
var camCtrl = Duik.Controller.create(comp, Duik.Controller.Type.POSITION );
Duik.Controller.setCharacterName( i18n._("Camera"), camCtrl );
Duik.Controller.setLimbName( i18n._("Cam"), camCtrl ); /// TRANSLATORS: Short for 'Camera'
camCtrl.threeDLayer = true;
camCtrl.position.setValue(camera.transform.position.value);
camCtrl.position.dimensionsSeparated = separateDimensions;

//create main
var mainCtrl = Duik.Controller.create(comp, Duik.Controller.Type.CAMERA);
Duik.Controller.setCharacterName( i18n._("Camera"), mainCtrl );
Duik.Controller.setLimbName( camera.name, mainCtrl );
mainCtrl.threeDLayer = true;
mainCtrl.position.setValue(camera.transform.position.value);
mainCtrl.position.dimensionsSeparated = separateDimensions;

camCtrl.parent = mainCtrl;
targetCtrl.parent = mainCtrl;
Expand Down Expand Up @@ -481,20 +487,7 @@ Duik.Camera.rig = function( camera )
'result;'
].join('\n');

mainCtrl.orientation.expression = iExpr;
camCtrl.position.expression = iExpr;
camCtrl.orientation.expression = iExpr;
camCtrl.xRotation.expression = iExpr;
camCtrl.yRotation.expression = iExpr;
targetCtrl.position.expression = iExpr;
targetCtrl.orientation.expression = iExpr;
targetCtrl.xRotation.expression = iExpr;
targetCtrl.yRotation.expression = iExpr;
if (DuAE.version.version >= 16) targetCtrl.rotation.expression = iExpr;
else targetCtrl.rotation.expression = iExpr;

// Position
mainCtrl.position.expression = [ DuAEExpression.Id.CAMERA_RIG,
var mainPosExpr = [ DuAEExpression.Id.CAMERA_RIG,
fxLink,
gFreqFX,
gPosAmpFX,
Expand Down Expand Up @@ -554,6 +547,38 @@ Duik.Camera.rig = function( camera )
'}',
'result;'
].join('\n');

if (separateDimensions) {
camCtrl.transform.property("ADBE Position_0").expression = iExpr;
camCtrl.transform.property("ADBE Position_1").expression = iExpr;
camCtrl.transform.property("ADBE Position_2").expression = iExpr;

targetCtrl.transform.property("ADBE Position_0").expression = iExpr;
targetCtrl.transform.property("ADBE Position_1").expression = iExpr;
targetCtrl.transform.property("ADBE Position_2").expression = iExpr;

mainCtrl.transform.property("ADBE Position_0").expression = mainPosExpr;
mainCtrl.transform.property("ADBE Position_1").expression = mainPosExpr;
mainCtrl.transform.property("ADBE Position_2").expression = mainPosExpr;
}
else {
camCtrl.position.expression = iExpr;
targetCtrl.position.expression = iExpr;
mainCtrl.position.expression = mainPosExpr;
}

mainCtrl.orientation.expression = iExpr;

camCtrl.orientation.expression = iExpr;
camCtrl.xRotation.expression = iExpr;
camCtrl.yRotation.expression = iExpr;

targetCtrl.orientation.expression = iExpr;
targetCtrl.xRotation.expression = iExpr;
targetCtrl.yRotation.expression = iExpr;
if (DuAE.version.version >= 16) targetCtrl.rotation.expression = iExpr;
else targetCtrl.rotation.expression = iExpr;

// X Rotation
mainCtrl.xRotation.expression = [ DuAEExpression.Id.CAMERA_RIG,
fxLink,
Expand Down

0 comments on commit 83bc130

Please sign in to comment.