var RadianContant = 0.01745;

var Accuracy = 0.001;
let MinRotateAngle = 2 * RadianContant;
let MaxRotateAngle = 178 * RadianContant;

//切割模式
var ClipType = {
    DrawLine: 0,
    MoveClipPlane:1,
};
//切面类型，当前切面法向量与哪个cube面法向量夹角最小即与哪个cube面的类型相同
var ClipFaceType = {
    None: 0,
    Front: 1,   //cube面法向量：0,1,0
    Right: 2,   //cube面法向量：-1,0,0
    Up: 3,      //cube面法向量：0,0,-1
    Behind: 4,  //cube面法向量：0,-1,0
    Left: 5,    //cube面法向量：1,0,0
    Down: 6    //cube面法向量：0,0,1
};
var ClipCategory = {
    Flank: 0,
    Soleplate: 1
};
var RotateState = {
    None: 0,
    Rotating: 1,
    RotateEnd: 2,
    MaximumAngle:3
};
Array.prototype.max = function () {
    return Math.max.apply(null, this);
};
Array.prototype.min = function () {
    return Math.min.apply(null, this);
};
var cefMappingPoint = function Line3(x, y, z) {
    this.X = x;
    this.Y = y;
    this.Z = z;
};
//切面信息
var ClipMeshInfo = {
    createNew: function (object, plane, materialIndex) {
        var info = {};
        info.Object = object;
        info.Plane = plane;
        info.ImageName = object.uuid+".jpg";
        info.Normal = info.Plane.normal.clone();
        info.Constant = info.Plane.constant;
        info.Index = materialIndex;
        info.dispose = function () {
            if (this.Object!=undefined) {
                this.Object.material.map.dispose();
            }
        };
        return info;
    }

};
//当前激活的切面信息
var ActiveMeshInfo = {
    createNew: function (mesh, point, meshType) {
        var info = {};
        info.Mesh = mesh; //当前点击的面信息, if meshType is cube, mesh is intersectobject, if mesh type is plane, mesh is a clipmeshinfo
        info.MeshType = meshType;
        info.Point = point;
        info.Vertices = undefined;
        info.MaxForwardDistance = undefined;
        info.resetPlaneInfo = function() {
            this.Mesh.Normal = this.Mesh.Plane.normal.clone();
            this.Mesh.Constant = this.Mesh.Plane.constant;
            this.Mesh.Index = undefined;
            this.Mesh.MeshType = MeshType.additionalMesh;
        };
        info.isMovePlane = function() {
            return this.Mesh.Plane != undefined &&
                this.Mesh.Constant != this.Mesh.Plane.constant;
        };
        info.isCubeMesh = function () {
            return this.MeshType == MeshType.cube;
        };
        info.getClipPlanes = function () {
            return this.isCubeMesh() ? this.Mesh.object.material[0].clippingPlanes : this.Mesh.Object.material.clippingPlanes;
        };
        info.getClonedVertices = function () {
            return this.isCubeMesh() ? this.Mesh.object.geometry.vertices.slice(0) : this.Mesh.Object.geometry.vertices.slice(0);
        };
        info.getRaycasterFirstIntersectObject = function(raycaster){
            let intersectObjects;
            if (this.isCubeMesh()) {
                intersectObjects = raycaster.intersectObject(this.Mesh.object);
            } else {
                intersectObjects = raycaster.intersectObject(this.Mesh.Object);
            }

            if(intersectObjects.length > 0)
            {
                return intersectObjects[0];
            }

            return undefined;
        };

        info.getClonedNormal = function()
        {
            return this.isCubeMesh() ? this.Mesh.face.normal.clone() : this.Mesh.Plane.normal.clone();
        };
        return info;
    }
};
//鼠标拾取面的类型
var MeshType = {
    cube: 0,
    additionalMesh: 1
};
