/**
 * Copyright (c) 2018 Bitbloq (BQ)
 *
 * License: MIT
 *
 * long description for the file
 *
 * @summary short description for the file
 * @author David García <https://github.com/empoalp>,
 * @author Alberto Valero <https://github.com/avalero>
 *
 * Created at     : 2018-10-17 12:30:09
 * Last modified  : 2018-11-06 10:33:55
 */
import * as THREE from 'three';
var RotationHelper = /** @class */ (function () {
    function RotationHelper(mesh, axis, relative) {
        var boundingBoxDims = new THREE.Vector3();
        new THREE.Box3().setFromObject(mesh).getSize(boundingBoxDims);
        var radius = 0.5;
        var color;
        var separation = 10;
        var length;
        var extraLength = 30;
        var toroidRadius;
        var toroidArc = 2 * Math.PI;
        var toroidInnerRadius = 0.7;
        if (axis === 'x') {
            color = 0xff0000;
            toroidRadius =
                Math.max(boundingBoxDims.y, boundingBoxDims.z) / 2 + separation;
            length = Math.max(boundingBoxDims.y, boundingBoxDims.z) + extraLength;
        }
        else if (axis === 'y') {
            color = 0x0000ff;
            toroidRadius =
                Math.max(boundingBoxDims.x, boundingBoxDims.z) / 2 + separation;
            length = Math.max(boundingBoxDims.x, boundingBoxDims.z) + extraLength;
        }
        else {
            color = 0x00ff00;
            toroidRadius =
                Math.max(boundingBoxDims.x, boundingBoxDims.y) / 2 + separation;
            length = Math.max(boundingBoxDims.x, boundingBoxDims.y) + extraLength;
        }
        var cylinderGeometry = new THREE.CylinderGeometry(radius, radius, length);
        cylinderGeometry.rotateZ(Math.PI / 2);
        var toroidGeometry = new THREE.TorusGeometry(toroidRadius, toroidInnerRadius, 6, toroidRadius * 2, // lets make number of segments equal to radius * factor
        toroidArc);
        toroidGeometry.rotateY(Math.PI / 2);
        var material = new THREE.MeshBasicMaterial({
            color: color,
            opacity: 0.5,
            transparent: true,
            depthWrite: false,
        });
        this.helperMesh = new THREE.Group();
        this.helperMesh.add(new THREE.Mesh(cylinderGeometry, material));
        this.helperMesh.add(new THREE.Mesh(toroidGeometry, material));
        this.helperMesh.position.copy(mesh.position);
        if (relative === true) {
            this.helperMesh.setRotationFromEuler(mesh.rotation);
        }
        if (axis === 'y')
            this.helperMesh.rotateZ(Math.PI / 2);
        if (axis === 'z') {
            this.helperMesh.rotateY(-Math.PI / 2);
            this.helperMesh.rotateX(Math.PI / 2);
        }
    }
    Object.defineProperty(RotationHelper.prototype, "mesh", {
        get: function () {
            return this.helperMesh;
        },
        enumerable: true,
        configurable: true
    });
    return RotationHelper;
}());
export default RotationHelper;
//# sourceMappingURL=RotationHelper.js.map