How to set yaw of camera on start via orbitcamera.js

Hi, simple question as my knowledge of JS is not that good…

Would be great if the standard orbit-camera.js script included in the ‘standard model viewer’ had the ability to set starting yaw (ie rotation around Y, up-axis).

Im trying to call the object attribute ‘yaw’ (from the original pc script):

Object.defineProperty(OrbitCamera.prototype, "yaw", {
    get: function() {
        return this._targetYaw;

    set: function(value) {
        this._targetYaw = value;

        // Ensure that the yaw takes the shortest route by making sure that 
        // the difference between the targetYaw and the actual is 180 degrees
        // in either direction
        var diff = this._targetYaw - this._yaw;
        var reminder = diff % 360;
        if (reminder > 180) {
            this._targetYaw = this._yaw - (360 - reminder);
        } else if (reminder < -180) {
            this._targetYaw = this._yaw + (360 + reminder);
        } else {
            this._targetYaw = this._yaw + reminder;

… within the script’s focusEntity() function:

OrbitCamera.prototype.focus = function (focusEntity) {
    // Calculate an bounding box that encompasses all the models to frame in the camera view
    this._buildAabb(focusEntity, 0);

    var halfExtents = this._modelsAabb.halfExtents;

    var distance = Math.max(halfExtents.x, Math.max(halfExtents.y, halfExtents.z));
    distance = (distance / Math.tan(0.5 * * pc.math.DEG_TO_RAD));
    distance = (distance * 2);

    this.distance = distance;



/// smthg like this?


Thanks v much for responses folks.
By the way can we also set a user-input in editor for an orbit rotation speed? (so camera rotates around model)

It be:

/// smthg like this?
this.yaw = this.useryaw;

On the Camera object, there is orbit sensitivity on the touch and mouse controls this will change the ‘speed’ of rotation around the model when the user interacts.

Or did you want something that auto rotates around the model?

1 Like

Yes! works like a charm…

and yes, i was hoping set the option of a constant rotation speed, overridden by user interations…

something like

    //***  set rotation speed on user input
    this._targetYaw += this.userrotspeed*dt;

but I cant see where to put it!
thanks again

I would have another script that references the orbit camera (like what the mouse controls do) and just update the yaw on the Update call. You will need to add some logic to stop the rotation for a bit if the user interacts with the app and restart when the user stops.