更新版本,修复镜像槽问题
This commit is contained in:
		
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,2 +1,3 @@
 | 
				
			|||||||
/node_modules
 | 
					/node_modules
 | 
				
			||||||
/dist
 | 
					/package-lock.json
 | 
				
			||||||
 | 
					.history
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4460
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										4460
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										44
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								package.json
									
									
									
									
									
								
							@@ -6,10 +6,10 @@
 | 
				
			|||||||
  "types": "dist/index.d.ts",
 | 
					  "types": "dist/index.d.ts",
 | 
				
			||||||
  "private": true,
 | 
					  "private": true,
 | 
				
			||||||
  "scripts": {
 | 
					  "scripts": {
 | 
				
			||||||
 | 
					    "t": "tsc --noEmit -w",
 | 
				
			||||||
    "build": "tsc",
 | 
					    "build": "tsc",
 | 
				
			||||||
    "umd": "webpack --config ./config/webpack.umd.ts",
 | 
					    "umd": "webpack --config ./config/webpack.umd.ts",
 | 
				
			||||||
    "dev": "webpack-dev-server --config ./config/webpack.view.ts",
 | 
					    "dev": "webpack-dev-server --config ./config/webpack.view.ts"
 | 
				
			||||||
    "type": "ts-node ./utils/copy_type.ts"
 | 
					 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "repository": {
 | 
					  "repository": {
 | 
				
			||||||
    "type": "git",
 | 
					    "type": "git",
 | 
				
			||||||
@@ -18,29 +18,29 @@
 | 
				
			|||||||
  "author": "cx",
 | 
					  "author": "cx",
 | 
				
			||||||
  "license": "ISC",
 | 
					  "license": "ISC",
 | 
				
			||||||
  "devDependencies": {
 | 
					  "devDependencies": {
 | 
				
			||||||
    "@types/hard-source-webpack-plugin": "^0.9.0",
 | 
					    "@types/hard-source-webpack-plugin": "^1.0.1",
 | 
				
			||||||
    "@types/node": "^10.11.7",
 | 
					    "@types/node": "^13.13.4",
 | 
				
			||||||
    "@types/three": "^0.92.25",
 | 
					    "@types/three": "^0.103.2",
 | 
				
			||||||
    "@types/uglifyjs-webpack-plugin": "^1.1.0",
 | 
					    "@types/uglifyjs-webpack-plugin": "^1.1.0",
 | 
				
			||||||
    "@types/webpack": "^4.4.16",
 | 
					    "@types/webpack": "^4.41.12",
 | 
				
			||||||
    "@types/webpack-dev-server": "^3.1.1",
 | 
					    "@types/webpack-dev-server": "^3.10.1",
 | 
				
			||||||
    "@types/webpack-env": "^1.13.6",
 | 
					    "@types/webpack-env": "^1.15.2",
 | 
				
			||||||
    "@types/webpack-merge": "^4.1.3",
 | 
					    "@types/webpack-merge": "^4.1.5",
 | 
				
			||||||
    "awesome-typescript-loader": "^5.2.1",
 | 
					    "awesome-typescript-loader": "^5.2.1",
 | 
				
			||||||
    "fork-ts-checker-webpack-plugin": "^0.4.8",
 | 
					    "fork-ts-checker-webpack-plugin": "^4.1.3",
 | 
				
			||||||
    "hard-source-webpack-plugin": "^0.12.0",
 | 
					    "hard-source-webpack-plugin": "^0.13.1",
 | 
				
			||||||
    "html-webpack-plugin": "^3.2.0",
 | 
					    "html-webpack-plugin": "^4.2.1",
 | 
				
			||||||
    "ts-loader": "^5.2.1",
 | 
					    "ts-loader": "^7.0.2",
 | 
				
			||||||
    "ts-node": "^7.0.1",
 | 
					    "ts-node": "^8.9.1",
 | 
				
			||||||
    "typescript": "^3.1.3",
 | 
					    "typescript": "^3.8.3",
 | 
				
			||||||
    "uglifyjs-webpack-plugin": "^2.0.1",
 | 
					    "uglifyjs-webpack-plugin": "^2.2.0",
 | 
				
			||||||
    "webpack": "^4.20.2",
 | 
					    "webpack": "^4.43.0",
 | 
				
			||||||
    "webpack-cli": "^3.1.2",
 | 
					    "webpack-cli": "^3.3.11",
 | 
				
			||||||
    "webpack-dev-server": "^3.1.9",
 | 
					    "webpack-dev-server": "^3.10.3",
 | 
				
			||||||
    "webpack-merge": "^4.1.4"
 | 
					    "webpack-merge": "^4.2.2"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
    "three": "^0.95.0",
 | 
					    "three": "^0.115.0",
 | 
				
			||||||
    "wolfy87-eventemitter": "^5.2.5"
 | 
					    "wolfy87-eventemitter": "^5.2.9"
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,4 @@
 | 
				
			|||||||
import * as THREE from 'three';
 | 
					import { Box3, Camera, MathUtils, OrthographicCamera, PerspectiveCamera, Vector3 } from 'three';
 | 
				
			||||||
import { Vector3 } from 'three';
 | 
					 | 
				
			||||||
import { Orbit } from './Orbit';
 | 
					import { Orbit } from './Orbit';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@@ -14,8 +13,8 @@ import { Orbit } from './Orbit';
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
export class CameraUpdate
 | 
					export class CameraUpdate
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    private m_CurCamera: THREE.Camera;
 | 
					    private m_CurCamera: Camera;
 | 
				
			||||||
    private m_CameraArray: Map<any, THREE.Camera> = new Map<any, THREE.Camera>();
 | 
					    private m_CameraArray: Map<any, Camera> = new Map<any, Camera>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //视口的画布大小
 | 
					    //视口的画布大小
 | 
				
			||||||
    private m_Width: number;
 | 
					    private m_Width: number;
 | 
				
			||||||
@@ -24,9 +23,9 @@ export class CameraUpdate
 | 
				
			|||||||
    private m_ViewHeight: number = 10;
 | 
					    private m_ViewHeight: number = 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //观察的位置
 | 
					    //观察的位置
 | 
				
			||||||
    private m_Target: THREE.Vector3 = new THREE.Vector3();
 | 
					    private m_Target: Vector3 = new Vector3();
 | 
				
			||||||
    //观察向量
 | 
					    //观察向量
 | 
				
			||||||
    private m_Direction: THREE.Vector3 = new THREE.Vector3(0, 0, -1);
 | 
					    private m_Direction: Vector3 = new Vector3(0, 0, -1);
 | 
				
			||||||
    //观察的轨道.
 | 
					    //观察的轨道.
 | 
				
			||||||
    private m_Orbit: Orbit = new Orbit();
 | 
					    private m_Orbit: Orbit = new Orbit();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -35,12 +34,12 @@ export class CameraUpdate
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    constructor()
 | 
					    constructor()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        this.m_CameraArray.set(THREE.OrthographicCamera, new THREE.OrthographicCamera(-2, 2, 2, -2,
 | 
					        this.m_CameraArray.set(OrthographicCamera, new OrthographicCamera(-2, 2, 2, -2,
 | 
				
			||||||
            -1e6, 1e6));
 | 
					            -1e6, 1e6));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.m_CameraArray.set(THREE.PerspectiveCamera, new THREE.PerspectiveCamera(50, 1, 0.01, 10000));
 | 
					        this.m_CameraArray.set(PerspectiveCamera, new PerspectiveCamera(50, 1, 0.01, 10000));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.m_CurCamera = this.m_CameraArray.get(THREE.OrthographicCamera);
 | 
					        this.m_CurCamera = this.m_CameraArray.get(OrthographicCamera);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.m_Orbit.UpdateRoValue(this.m_Direction);
 | 
					        this.m_Orbit.UpdateRoValue(this.m_Direction);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -53,7 +52,7 @@ export class CameraUpdate
 | 
				
			|||||||
        return this.m_Width / this.m_Height;
 | 
					        return this.m_Width / this.m_Height;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    get Camera(): THREE.Camera
 | 
					    get Camera(): Camera
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return this.m_CurCamera;
 | 
					        return this.m_CurCamera;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -63,7 +62,7 @@ export class CameraUpdate
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    set ViewHeight(height)
 | 
					    set ViewHeight(height)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        this.m_ViewHeight = THREE.Math.clamp(height, this.m_MinViewHeight, this.m_MaxViewHeight);
 | 
					        this.m_ViewHeight = MathUtils.clamp(height, this.m_MinViewHeight, this.m_MaxViewHeight);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    SetSize(width: number, height: number)
 | 
					    SetSize(width: number, height: number)
 | 
				
			||||||
@@ -75,10 +74,10 @@ export class CameraUpdate
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 平移相机.
 | 
					     * 平移相机.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param {THREE.Vector3} mouseMove
 | 
					     * @param {Vector3} mouseMove
 | 
				
			||||||
     * @memberof CameraControl
 | 
					     * @memberof CameraControl
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    Pan(mouseMove: THREE.Vector3)
 | 
					    Pan(mouseMove: Vector3)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        mouseMove.y *= -1;
 | 
					        mouseMove.y *= -1;
 | 
				
			||||||
        mouseMove.multiplyScalar(-this.m_ViewHeight / this.m_Height);
 | 
					        mouseMove.multiplyScalar(-this.m_ViewHeight / this.m_Height);
 | 
				
			||||||
@@ -86,7 +85,7 @@ export class CameraUpdate
 | 
				
			|||||||
        this.m_Target.add(mouseMove);
 | 
					        this.m_Target.add(mouseMove);
 | 
				
			||||||
        this.Update();
 | 
					        this.Update();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    Rotate(mouseMove: THREE.Vector3, target: THREE.Vector3)
 | 
					    Rotate(mouseMove: Vector3, target: Vector3)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        this.m_Orbit.RoX -= mouseMove.y * 0.003;
 | 
					        this.m_Orbit.RoX -= mouseMove.y * 0.003;
 | 
				
			||||||
        this.m_Orbit.RoZ -= mouseMove.x * 0.003;
 | 
					        this.m_Orbit.RoZ -= mouseMove.x * 0.003;
 | 
				
			||||||
@@ -112,9 +111,9 @@ export class CameraUpdate
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        this.Update();
 | 
					        this.Update();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    Zoom(scale: number, scaleCenter?: THREE.Vector3)
 | 
					    Zoom(scale: number, scaleCenter?: Vector3)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (this.Camera instanceof THREE.OrthographicCamera)
 | 
					        if (this.Camera instanceof OrthographicCamera)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.ViewHeight *= scale;
 | 
					            this.ViewHeight *= scale;
 | 
				
			||||||
            if (scaleCenter && this.m_ViewHeight < this.m_MaxViewHeight)
 | 
					            if (scaleCenter && this.m_ViewHeight < this.m_MaxViewHeight)
 | 
				
			||||||
@@ -124,7 +123,7 @@ export class CameraUpdate
 | 
				
			|||||||
                this.m_Target.add(scaleCenter);
 | 
					                this.m_Target.add(scaleCenter);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else if (this.Camera instanceof THREE.PerspectiveCamera)
 | 
					        else if (this.Camera instanceof PerspectiveCamera)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            let add = scale > 1 ? 1 : -1;
 | 
					            let add = scale > 1 ? 1 : -1;
 | 
				
			||||||
            add *= this.Camera.position.distanceTo(this.m_Target) / 10;
 | 
					            add *= this.Camera.position.distanceTo(this.m_Target) / 10;
 | 
				
			||||||
@@ -132,7 +131,7 @@ export class CameraUpdate
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        this.Update();
 | 
					        this.Update();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    ZoomExtensBox3(box3: THREE.Box3)
 | 
					    ZoomExtensBox3(box3: Box3)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (!box3 || box3.isEmpty()) return;
 | 
					        if (!box3 || box3.isEmpty()) return;
 | 
				
			||||||
        this.Camera.updateMatrixWorld(false);
 | 
					        this.Camera.updateMatrixWorld(false);
 | 
				
			||||||
@@ -159,7 +158,7 @@ export class CameraUpdate
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        this.Update();
 | 
					        this.Update();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    LookAt(dir: THREE.Vector3)
 | 
					    LookAt(dir: Vector3)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        this.m_Orbit.UpdateRoValue(dir);
 | 
					        this.m_Orbit.UpdateRoValue(dir);
 | 
				
			||||||
        this.m_Direction.copy(dir);
 | 
					        this.m_Direction.copy(dir);
 | 
				
			||||||
@@ -181,7 +180,7 @@ export class CameraUpdate
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        this.Camera.position.copy(this.m_Target);
 | 
					        this.Camera.position.copy(this.m_Target);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (this.Camera instanceof THREE.OrthographicCamera)
 | 
					        if (this.Camera instanceof OrthographicCamera)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.Camera.left = this.Aspect * this.m_ViewHeight / -2;
 | 
					            this.Camera.left = this.Aspect * this.m_ViewHeight / -2;
 | 
				
			||||||
            this.Camera.right = this.Aspect * this.m_ViewHeight / 2;
 | 
					            this.Camera.right = this.Aspect * this.m_ViewHeight / 2;
 | 
				
			||||||
@@ -190,10 +189,10 @@ export class CameraUpdate
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            this.Camera.position.sub(this.m_Direction);
 | 
					            this.Camera.position.sub(this.m_Direction);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else if (this.Camera instanceof THREE.PerspectiveCamera)
 | 
					        else if (this.Camera instanceof PerspectiveCamera)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.Camera.aspect = this.Aspect;
 | 
					            this.Camera.aspect = this.Aspect;
 | 
				
			||||||
            let distens = (this.m_ViewHeight / 2) / (Math.tan(THREE.Math.degToRad(this.Camera.fov) / 2));
 | 
					            let distens = (this.m_ViewHeight / 2) / (Math.tan(MathUtils.degToRad(this.Camera.fov) / 2));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            this.Camera.position.sub(this.m_Direction.clone().multiplyScalar(distens));
 | 
					            this.Camera.position.sub(this.m_Direction.clone().multiplyScalar(distens));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -209,13 +208,13 @@ export class CameraUpdate
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    SwitchCamera()
 | 
					    SwitchCamera()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (this.Camera instanceof THREE.OrthographicCamera)
 | 
					        if (this.Camera instanceof OrthographicCamera)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.m_CurCamera = this.m_CameraArray.get(THREE.PerspectiveCamera);
 | 
					            this.m_CurCamera = this.m_CameraArray.get(PerspectiveCamera);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            this.m_CurCamera = this.m_CameraArray.get(THREE.OrthographicCamera);
 | 
					            this.m_CurCamera = this.m_CameraArray.get(OrthographicCamera);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        this.UpdateUp();
 | 
					        this.UpdateUp();
 | 
				
			||||||
        this.Update();
 | 
					        this.Update();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,6 @@ import { MoveMatrix } from "./GeUtils";
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 标注实体
 | 
					 * 标注实体
 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * @export
 | 
					 * @export
 | 
				
			||||||
 * @class Dimension
 | 
					 * @class Dimension
 | 
				
			||||||
 * @extends {Group}
 | 
					 * @extends {Group}
 | 
				
			||||||
@@ -42,12 +41,12 @@ export class Dimension extends Group
 | 
				
			|||||||
        if (mirror)
 | 
					        if (mirror)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            let roMat = new Matrix4().makeRotationZ(Math.PI);
 | 
					            let roMat = new Matrix4().makeRotationZ(Math.PI);
 | 
				
			||||||
            text.applyMatrix(roMat);
 | 
					            text.applyMatrix4(roMat);
 | 
				
			||||||
            text.applyMatrix(MoveMatrix(new Vector3(length * 0.5, footLength - textHeight * 0.1)));
 | 
					            text.applyMatrix4(MoveMatrix(new Vector3(length * 0.5, footLength - textHeight * 0.1)));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            text.applyMatrix(MoveMatrix(new Vector3(length * 0.5, footLength * 1.1)));
 | 
					            text.applyMatrix4(MoveMatrix(new Vector3(length * 0.5, footLength * 1.1)));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
import { Box3, Vector3, Matrix4, Mesh } from "three";
 | 
					import { Box3, Matrix4, Mesh, Vector3 } from "three";
 | 
				
			||||||
import { Dimension, GetBoxArr } from ".";
 | 
					import { Dimension, GetBoxArr } from ".";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -24,7 +24,7 @@ export function DrawDimension(brList: Mesh[]): Dimension[]
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    let textHeight = 45;
 | 
					    let textHeight = 45;
 | 
				
			||||||
    let dimx = new Dimension(size.x, textHeight, true);
 | 
					    let dimx = new Dimension(size.x, textHeight, true);
 | 
				
			||||||
    dimx.applyMatrix(mat4);
 | 
					    dimx.applyMatrix4(mat4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let dimz = new Dimension(size.z, textHeight);
 | 
					    let dimz = new Dimension(size.z, textHeight);
 | 
				
			||||||
    mat4.makeBasis(
 | 
					    mat4.makeBasis(
 | 
				
			||||||
@@ -33,7 +33,7 @@ export function DrawDimension(brList: Mesh[]): Dimension[]
 | 
				
			|||||||
        new Vector3(0, -1, 0)
 | 
					        new Vector3(0, -1, 0)
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    mat4.setPosition(box.max.clone().add(new Vector3(30, -size.y)));
 | 
					    mat4.setPosition(box.max.clone().add(new Vector3(30, -size.y)));
 | 
				
			||||||
    dimz.applyMatrix(mat4);
 | 
					    dimz.applyMatrix4(mat4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let dimy = new Dimension(size.y, textHeight, true, true);
 | 
					    let dimy = new Dimension(size.y, textHeight, true, true);
 | 
				
			||||||
    mat4.makeBasis(
 | 
					    mat4.makeBasis(
 | 
				
			||||||
@@ -42,7 +42,7 @@ export function DrawDimension(brList: Mesh[]): Dimension[]
 | 
				
			|||||||
        new Vector3(0, 0, 1)
 | 
					        new Vector3(0, 0, 1)
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    mat4.setPosition(box.max.clone().add(new Vector3(30, -size.y)));
 | 
					    mat4.setPosition(box.max.clone().add(new Vector3(30, -size.y)));
 | 
				
			||||||
    dimy.applyMatrix(mat4);
 | 
					    dimy.applyMatrix4(mat4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return [dimx, dimy, dimz];
 | 
					    return [dimx, dimy, dimz];
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,12 +1,11 @@
 | 
				
			|||||||
import * as THREE from 'three';
 | 
					import { Geometry, Vector, Vector2, Vector3, Box3, Matrix4, Object3D, Line, Mesh } from 'three';
 | 
				
			||||||
import { Geometry, Vector, Vector2, Vector3, Box3 } from 'three';
 | 
					 | 
				
			||||||
import { Matrix2 } from './Matrix2';
 | 
					import { Matrix2 } from './Matrix2';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const cZeroVec = new THREE.Vector3();
 | 
					export const cZeroVec = new Vector3();
 | 
				
			||||||
export const cXAxis = new THREE.Vector3(1, 0, 0);
 | 
					export const cXAxis = new Vector3(1, 0, 0);
 | 
				
			||||||
export const cYAxis = new THREE.Vector3(0, 1, 0);
 | 
					export const cYAxis = new Vector3(0, 1, 0);
 | 
				
			||||||
export const cZAxis = new THREE.Vector3(0, 0, 1);
 | 
					export const cZAxis = new Vector3(0, 0, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 旋转一个点,旋转中心在原点
 | 
					 * 旋转一个点,旋转中心在原点
 | 
				
			||||||
@@ -26,6 +25,12 @@ export function equaln(v1: number, v2: number, fuzz = 1e-3)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    return Math.abs(v1 - v2) < fuzz;
 | 
					    return Math.abs(v1 - v2) < fuzz;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function equalv3(v1: Vector3, v2: Vector3, fuzz = 1e-8)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return equaln(v1.x, v2.x, fuzz) && equaln(v1.y, v2.y, fuzz) && equaln(v1.z, v2.z, fuzz);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function equal<T extends Vector>(v1: T, v2: T)
 | 
					export function equal<T extends Vector>(v1: T, v2: T)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return v1.distanceToSquared(v2) < 1e-8;
 | 
					    return v1.distanceToSquared(v2) < 1e-8;
 | 
				
			||||||
@@ -77,21 +82,21 @@ export function angle(v: Vector3 | Vector2)
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * 求两个向量的夹角,顺时针为负,逆时针为正
 | 
					 * 求两个向量的夹角,顺时针为负,逆时针为正
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @param {THREE.Vector3} v1 
 | 
					 * @param {Vector3} v1
 | 
				
			||||||
 * @param {THREE.Vector3} v2 
 | 
					 * @param {Vector3} v2
 | 
				
			||||||
 * @param {THREE.Vector3} [ref] 参考向量,如果为世界坐标系则为0,0,1
 | 
					 * @param {Vector3} [ref] 参考向量,如果为世界坐标系则为0,0,1
 | 
				
			||||||
 * @returns
 | 
					 * @returns
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
export function angleTo(v1: THREE.Vector3, v2: THREE.Vector3, ref: THREE.Vector3 = new THREE.Vector3(0, 0, 1))
 | 
					export function angleTo(v1: Vector3, v2: Vector3, ref: Vector3 = new Vector3(0, 0, 1))
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (!ref.equals(new Vector3(0, 0, 1)))
 | 
					    if (!ref.equals(new Vector3(0, 0, 1)))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        //任意轴坐标系. 使用相机的构造矩阵.
 | 
					        //任意轴坐标系. 使用相机的构造矩阵.
 | 
				
			||||||
        ref.multiplyScalar(-1);
 | 
					        ref.multiplyScalar(-1);
 | 
				
			||||||
        let up = getLoocAtUpVec(ref);
 | 
					        let up = getLoocAtUpVec(ref);
 | 
				
			||||||
        let refOcs = new THREE.Matrix4();
 | 
					        let refOcs = new Matrix4();
 | 
				
			||||||
        refOcs.lookAt(cZeroVec, ref, up);
 | 
					        refOcs.lookAt(cZeroVec, ref, up);
 | 
				
			||||||
        let refOcsInv = new THREE.Matrix4().getInverse(refOcs);
 | 
					        let refOcsInv = new Matrix4().getInverse(refOcs);
 | 
				
			||||||
        v1.applyMatrix4(refOcsInv);
 | 
					        v1.applyMatrix4(refOcsInv);
 | 
				
			||||||
        v2.applyMatrix4(refOcsInv);
 | 
					        v2.applyMatrix4(refOcsInv);
 | 
				
			||||||
        v1.z = 0;
 | 
					        v1.z = 0;
 | 
				
			||||||
@@ -103,7 +108,7 @@ export function angleTo(v1: THREE.Vector3, v2: THREE.Vector3, ref: THREE.Vector3
 | 
				
			|||||||
    return cv.z === 0 ? v1.angleTo(v2) : v1.angleTo(v2) * cv.z;
 | 
					    return cv.z === 0 ? v1.angleTo(v2) : v1.angleTo(v2) * cv.z;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function getLoocAtUpVec(dir: THREE.Vector3): THREE.Vector3
 | 
					export function getLoocAtUpVec(dir: Vector3): Vector3
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (dir.equals(cZeroVec))
 | 
					    if (dir.equals(cZeroVec))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -112,37 +117,37 @@ export function getLoocAtUpVec(dir: THREE.Vector3): THREE.Vector3
 | 
				
			|||||||
    let norm = dir.clone().normalize();
 | 
					    let norm = dir.clone().normalize();
 | 
				
			||||||
    if (norm.equals(cZAxis))
 | 
					    if (norm.equals(cZAxis))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return new THREE.Vector3(0, 1, 0);
 | 
					        return new Vector3(0, 1, 0);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (norm.equals(cZAxis.clone().negate()))
 | 
					    else if (norm.equals(cZAxis.clone().negate()))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return new THREE.Vector3(0, -1, 0);
 | 
					        return new Vector3(0, -1, 0);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        let xv: THREE.Vector3 = new THREE.Vector3();
 | 
					        let xv: Vector3 = new Vector3();
 | 
				
			||||||
        xv.crossVectors(cZAxis, norm);
 | 
					        xv.crossVectors(cZAxis, norm);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let up = new THREE.Vector3();
 | 
					        let up = new Vector3();
 | 
				
			||||||
        up.crossVectors(norm, xv);
 | 
					        up.crossVectors(norm, xv);
 | 
				
			||||||
        return up;
 | 
					        return up;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function createLookAtMat4(dir: THREE.Vector3): THREE.Matrix4
 | 
					export function createLookAtMat4(dir: Vector3): Matrix4
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    let up = getLoocAtUpVec(dir);
 | 
					    let up = getLoocAtUpVec(dir);
 | 
				
			||||||
    let mat = new THREE.Matrix4();
 | 
					    let mat = new Matrix4();
 | 
				
			||||||
    mat.lookAt(cZeroVec, dir, up);
 | 
					    mat.lookAt(cZeroVec, dir, up);
 | 
				
			||||||
    return mat;
 | 
					    return mat;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function isParallelTo(v1: THREE.Vector3, v2: THREE.Vector3)
 | 
					export function isParallelTo(v1: Vector3, v2: Vector3)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return v1.clone().cross(v2).lengthSq() < 1e-9;
 | 
					    return v1.clone().cross(v2).lengthSq() < 1e-9;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function ptToString(v: THREE.Vector3, fractionDigits: number = 3): string
 | 
					export function ptToString(v: Vector3, fractionDigits: number = 3): string
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return v.toArray().map(o =>
 | 
					    return v.toArray().map(o =>
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -150,16 +155,16 @@ export function ptToString(v: THREE.Vector3, fractionDigits: number = 3): string
 | 
				
			|||||||
    }).join(",")
 | 
					    }).join(",")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function midPoint(v1: THREE.Vector3, v2: THREE.Vector3): THREE.Vector3
 | 
					export function midPoint(v1: Vector3, v2: Vector3): Vector3
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return v1.clone().add(v2).multiplyScalar(0.5);
 | 
					    return v1.clone().add(v2).multiplyScalar(0.5);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
export function midPoint2(v1: THREE.Vector2, v2: THREE.Vector2): THREE.Vector2
 | 
					export function midPoint2(v1: Vector2, v2: Vector2): Vector2
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return v1.clone().add(v2).multiplyScalar(0.5);
 | 
					    return v1.clone().add(v2).multiplyScalar(0.5);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function midPtCir(v1: THREE.Vector3, v2: THREE.Vector3)
 | 
					export function midPtCir(v1: Vector3, v2: Vector3)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    let baseline = new Vector3(1, 0, 0);
 | 
					    let baseline = new Vector3(1, 0, 0);
 | 
				
			||||||
    let outLine = v2.clone().sub(v1);
 | 
					    let outLine = v2.clone().sub(v1);
 | 
				
			||||||
@@ -174,7 +179,7 @@ export function midPtCir(v1: THREE.Vector3, v2: THREE.Vector3)
 | 
				
			|||||||
 * @param [updateMatrix] 是否应该更新对象矩阵
 | 
					 * @param [updateMatrix] 是否应该更新对象矩阵
 | 
				
			||||||
 * @returns box
 | 
					 * @returns box
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
export function GetBox(obj: THREE.Object3D, updateMatrix?: boolean): THREE.Box3
 | 
					export function GetBox(obj: Object3D, updateMatrix?: boolean): Box3
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    let box = new Box3();
 | 
					    let box = new Box3();
 | 
				
			||||||
    if (updateMatrix) obj.updateMatrixWorld(false);
 | 
					    if (updateMatrix) obj.updateMatrixWorld(false);
 | 
				
			||||||
@@ -199,7 +204,7 @@ export function GetBox(obj: THREE.Object3D, updateMatrix?: boolean): THREE.Box3
 | 
				
			|||||||
    return box;
 | 
					    return box;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function GetBoxArr(arr: Array<THREE.Object3D>): THREE.Box3
 | 
					export function GetBoxArr(arr: Array<Object3D>): Box3
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    let box = new Box3();
 | 
					    let box = new Box3();
 | 
				
			||||||
    for (let o of arr)
 | 
					    for (let o of arr)
 | 
				
			||||||
@@ -211,9 +216,9 @@ export function GetBoxArr(arr: Array<THREE.Object3D>): THREE.Box3
 | 
				
			|||||||
    return box;
 | 
					    return box;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function MoveMatrix(v: THREE.Vector3): THREE.Matrix4
 | 
					export function MoveMatrix(v: Vector3): Matrix4
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    let mat = new THREE.Matrix4();
 | 
					    let mat = new Matrix4();
 | 
				
			||||||
    mat.makeTranslation(v.x, v.y, v.z);
 | 
					    mat.makeTranslation(v.x, v.y, v.z);
 | 
				
			||||||
    return mat;
 | 
					    return mat;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -275,9 +280,9 @@ export function angleTo2Pi(an: number)
 | 
				
			|||||||
    if (an < 0) an += Math.PI * 2
 | 
					    if (an < 0) an += Math.PI * 2
 | 
				
			||||||
    return an;
 | 
					    return an;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
export function updateGeometry(l: THREE.Line | THREE.Mesh, geometry: Geometry)
 | 
					export function updateGeometry(l: Line | Mesh, geometry: Geometry)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    let geo = l.geometry as THREE.Geometry;
 | 
					    let geo = l.geometry as Geometry;
 | 
				
			||||||
    geo.dispose();
 | 
					    geo.dispose();
 | 
				
			||||||
    l.geometry = geometry;
 | 
					    l.geometry = geometry;
 | 
				
			||||||
    geometry.verticesNeedUpdate = true;
 | 
					    geometry.verticesNeedUpdate = true;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										34
									
								
								src/Orbit.ts
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								src/Orbit.ts
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
import * as THREE from "three";
 | 
					import { MathUtils, Vector3 } from "three";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 轨道控制的数学类,观察向量和角度的互相转换
 | 
					 * 轨道控制的数学类,观察向量和角度的互相转换
 | 
				
			||||||
@@ -20,19 +20,19 @@ export class Orbit
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    set RoX(v)
 | 
					    set RoX(v)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        this.m_RoX = THREE.Math.clamp(v, Math.PI * -0.5, Math.PI * 0.5);
 | 
					        this.m_RoX = MathUtils.clamp(v, Math.PI * -0.5, Math.PI * 0.5);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 使用旋转角度 计算观察向量
 | 
					     * 使用旋转角度 计算观察向量
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param {THREE.Vector3} [dir] 引用传入,如果传入,那么就不构造新的向量
 | 
					     * @param {Vector3} [dir] 引用传入,如果传入,那么就不构造新的向量
 | 
				
			||||||
     * @returns {THREE.Vector3} 返回观察向量
 | 
					     * @returns {Vector3} 返回观察向量
 | 
				
			||||||
     * @memberof Orbit
 | 
					     * @memberof Orbit
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    UpdateDirection(dir?: THREE.Vector3): THREE.Vector3
 | 
					    UpdateDirection(dir?: Vector3): Vector3
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        let rtDir = dir ? dir : new THREE.Vector3();
 | 
					        let rtDir = dir ? dir : new Vector3();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        rtDir.z = Math.sin(this.m_RoX);
 | 
					        rtDir.z = Math.sin(this.m_RoX);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -48,10 +48,10 @@ export class Orbit
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 使用观察向量,计算旋转角度
 | 
					     * 使用观察向量,计算旋转角度
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param {THREE.Vector3} dir 
 | 
					     * @param {Vector3} dir
 | 
				
			||||||
     * @memberof Orbit
 | 
					     * @memberof Orbit
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    UpdateRoValue(dir: THREE.Vector3)
 | 
					    UpdateRoValue(dir: Vector3)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        dir.normalize();
 | 
					        dir.normalize();
 | 
				
			||||||
        this.m_RoX = Math.asin(dir.z);
 | 
					        this.m_RoX = Math.asin(dir.z);
 | 
				
			||||||
@@ -66,26 +66,26 @@ export class Orbit
 | 
				
			|||||||
     * 根据观察向量 求头部的向量.
 | 
					     * 根据观察向量 求头部的向量.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @static
 | 
					     * @static
 | 
				
			||||||
     * @param {THREE.Vector3} dir 
 | 
					     * @param {Vector3} dir
 | 
				
			||||||
     * @param {THREE.Vector3} [up] 
 | 
					     * @param {Vector3} [up]
 | 
				
			||||||
     * @returns {THREE.Vector3} 
 | 
					     * @returns {Vector3}
 | 
				
			||||||
     * @memberof Orbit
 | 
					     * @memberof Orbit
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    static ComputUpDirection(dir: THREE.Vector3, up?: THREE.Vector3): THREE.Vector3
 | 
					    static ComputUpDirection(dir: Vector3, up?: Vector3): Vector3
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        let upRes = up ? up : new THREE.Vector3();
 | 
					        let upRes = up ? up : new Vector3();
 | 
				
			||||||
        if (dir.equals(new THREE.Vector3(0, 0, -1)))
 | 
					        if (dir.equals(new Vector3(0, 0, -1)))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            upRes.set(0, 1, 0);
 | 
					            upRes.set(0, 1, 0);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else if (dir.equals(new THREE.Vector3(0, 0, 1)))
 | 
					        else if (dir.equals(new Vector3(0, 0, 1)))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            upRes.set(0, -1, 0);
 | 
					            upRes.set(0, -1, 0);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            let xv = new THREE.Vector3();
 | 
					            let xv = new Vector3();
 | 
				
			||||||
            xv.crossVectors(new THREE.Vector3(0, 0, 1), dir);
 | 
					            xv.crossVectors(new Vector3(0, 0, 1), dir);
 | 
				
			||||||
            upRes.crossVectors(dir, xv);
 | 
					            upRes.crossVectors(dir, xv);
 | 
				
			||||||
            upRes.normalize();
 | 
					            upRes.normalize();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,7 +30,7 @@ export class DbText extends Mesh
 | 
				
			|||||||
  {
 | 
					  {
 | 
				
			||||||
    let font = FontLoaderUtil.Load();
 | 
					    let font = FontLoaderUtil.Load();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let shapes: THREE.Shape[] = font.generateShapes(str, height, 0.1);
 | 
					    let shapes: THREE.Shape[] = font.generateShapes(str, height);
 | 
				
			||||||
    let geometry = new ShapeGeometry(shapes);
 | 
					    let geometry = new ShapeGeometry(shapes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    geometry.computeBoundingBox();
 | 
					    geometry.computeBoundingBox();
 | 
				
			||||||
@@ -38,6 +38,6 @@ export class DbText extends Mesh
 | 
				
			|||||||
    super(geometry, ColorMaterial.GetBasicMaterial(5));
 | 
					    super(geometry, ColorMaterial.GetBasicMaterial(5));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let center = geometry.boundingBox.getCenter(new Vector3());
 | 
					    let center = geometry.boundingBox.getCenter(new Vector3());
 | 
				
			||||||
    this.applyMatrix(MoveMatrix(new Vector3(-center.x, 0, 0)));
 | 
					    this.applyMatrix4(MoveMatrix(new Vector3(-center.x, 0, 0)));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -71,31 +71,6 @@ export class ThreeBSP
 | 
				
			|||||||
                vertex = new Vertex(vertex.x, vertex.y, vertex.z, face.vertexNormals[2], uvs);
 | 
					                vertex = new Vertex(vertex.x, vertex.y, vertex.z, face.vertexNormals[2], uvs);
 | 
				
			||||||
                vertex.applyMatrix4(this.matrix);
 | 
					                vertex.applyMatrix4(this.matrix);
 | 
				
			||||||
                polygon.vertices.push(vertex);
 | 
					                polygon.vertices.push(vertex);
 | 
				
			||||||
            } else if (typeof THREE.Face4)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                vertex = geometry.vertices[face.a];
 | 
					 | 
				
			||||||
                uvs = faceVertexUvs ? new THREE.Vector2(faceVertexUvs[0].x, faceVertexUvs[0].y) : null;
 | 
					 | 
				
			||||||
                vertex = new Vertex(vertex.x, vertex.y, vertex.z, face.vertexNormals[0], uvs);
 | 
					 | 
				
			||||||
                vertex.applyMatrix4(this.matrix);
 | 
					 | 
				
			||||||
                polygon.vertices.push(vertex);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                vertex = geometry.vertices[face.b];
 | 
					 | 
				
			||||||
                uvs = faceVertexUvs ? new THREE.Vector2(faceVertexUvs[1].x, faceVertexUvs[1].y) : null;
 | 
					 | 
				
			||||||
                vertex = new Vertex(vertex.x, vertex.y, vertex.z, face.vertexNormals[1], uvs);
 | 
					 | 
				
			||||||
                vertex.applyMatrix4(this.matrix);
 | 
					 | 
				
			||||||
                polygon.vertices.push(vertex);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                vertex = geometry.vertices[face.c];
 | 
					 | 
				
			||||||
                uvs = faceVertexUvs ? new THREE.Vector2(faceVertexUvs[2].x, faceVertexUvs[2].y) : null;
 | 
					 | 
				
			||||||
                vertex = new Vertex(vertex.x, vertex.y, vertex.z, face.vertexNormals[2], uvs);
 | 
					 | 
				
			||||||
                vertex.applyMatrix4(this.matrix);
 | 
					 | 
				
			||||||
                polygon.vertices.push(vertex);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                vertex = geometry.vertices[face.d];
 | 
					 | 
				
			||||||
                uvs = faceVertexUvs ? new THREE.Vector2(faceVertexUvs[3].x, faceVertexUvs[3].y) : null;
 | 
					 | 
				
			||||||
                vertex = new Vertex(vertex.x, vertex.y, vertex.z, face.vertexNormals[3], uvs);
 | 
					 | 
				
			||||||
                vertex.applyMatrix4(this.matrix);
 | 
					 | 
				
			||||||
                polygon.vertices.push(vertex);
 | 
					 | 
				
			||||||
            } else
 | 
					            } else
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                throw 'Invalid face type at index ' + i;
 | 
					                throw 'Invalid face type at index ' + i;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,6 @@
 | 
				
			|||||||
import * as THREE from 'three';
 | 
					import { CylinderGeometry, Geometry, LineSegments, Mesh, Shape, Vector2, Vector3, Matrix4, ExtrudeGeometry, EdgesGeometry } from 'three';
 | 
				
			||||||
import { CylinderGeometry, Geometry, LineSegments, Mesh, Shape, Vector2 } from 'three';
 | 
					 | 
				
			||||||
import { ColorMaterial } from './ColorPalette';
 | 
					import { ColorMaterial } from './ColorPalette';
 | 
				
			||||||
import { polar } from './GeUtils';
 | 
					import { equalv3, polar } from './GeUtils';
 | 
				
			||||||
import { boardMaterial, edgeMaterial } from './Material';
 | 
					import { boardMaterial, edgeMaterial } from './Material';
 | 
				
			||||||
import { RotateUVs } from './RotateUV';
 | 
					import { RotateUVs } from './RotateUV';
 | 
				
			||||||
import { ThreeBSP } from './ThreeCSG';
 | 
					import { ThreeBSP } from './ThreeCSG';
 | 
				
			||||||
@@ -10,16 +9,16 @@ export class Arc2d
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    m_StartAn: number;
 | 
					    m_StartAn: number;
 | 
				
			||||||
    m_EndAn: number;
 | 
					    m_EndAn: number;
 | 
				
			||||||
    m_StartPoint: THREE.Vector2;
 | 
					    m_StartPoint: Vector2;
 | 
				
			||||||
    m_EndPoint: THREE.Vector2;
 | 
					    m_EndPoint: Vector2;
 | 
				
			||||||
    m_Center: THREE.Vector2;
 | 
					    m_Center: Vector2;
 | 
				
			||||||
    m_Radius: number;
 | 
					    m_Radius: number;
 | 
				
			||||||
    constructor(p1: THREE.Vector2, p2: THREE.Vector2, bul: number)
 | 
					    constructor(p1: Vector2, p2: Vector2, bul: number)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        this.m_StartPoint = p1.clone();
 | 
					        this.m_StartPoint = p1.clone();
 | 
				
			||||||
        this.m_EndPoint = p2.clone();
 | 
					        this.m_EndPoint = p2.clone();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let vec: THREE.Vector2 = p2.clone().sub(p1);
 | 
					        let vec: Vector2 = p2.clone().sub(p1);
 | 
				
			||||||
        let len = vec.length();
 | 
					        let len = vec.length();
 | 
				
			||||||
        let an = vec.angle();
 | 
					        let an = vec.angle();
 | 
				
			||||||
        this.m_Radius = len / Math.sin(2 * Math.atan(bul)) / 2;
 | 
					        this.m_Radius = len / Math.sin(2 * Math.atan(bul)) / 2;
 | 
				
			||||||
@@ -72,23 +71,23 @@ export function createPath(pts: Vector2[], buls: number[], shapeOut?: Shape): Sh
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    return shape;
 | 
					    return shape;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
export function getVec(data: object): THREE.Vector3
 | 
					export function getVec(data: object): Vector3
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return new THREE.Vector3(data["x"], data["y"], data["z"]);
 | 
					    return new Vector3(data["x"], data["y"], data["z"]);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//创建板件 暂时这么写
 | 
					//创建板件 暂时这么写
 | 
				
			||||||
export function createBoard(boardData: object)
 | 
					export function createBoard(boardData: object)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    let pts: THREE.Vector2[] = [];
 | 
					    let pts: Vector2[] = [];
 | 
				
			||||||
    let buls: number[] = [];
 | 
					    let buls: number[] = [];
 | 
				
			||||||
    let boardPts = boardData["Pts"];
 | 
					    let boardPts = boardData["Pts"];
 | 
				
			||||||
    let boardBuls = boardData["Buls"];
 | 
					    let boardBuls = boardData["Buls"];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let boardHeight = boardData["H"];
 | 
					    let boardHeight = boardData["H"];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let boardMat = new THREE.Matrix4();
 | 
					    let boardMat = new Matrix4();
 | 
				
			||||||
    let matInv: THREE.Matrix4 = new THREE.Matrix4();
 | 
					    let matInv: Matrix4 = new Matrix4();
 | 
				
			||||||
    //InitBoardMat
 | 
					    //InitBoardMat
 | 
				
			||||||
    let xD = getVec(boardData["XVec"]);
 | 
					    let xD = getVec(boardData["XVec"]);
 | 
				
			||||||
    let yD = getVec(boardData["YVec"]);
 | 
					    let yD = getVec(boardData["YVec"]);
 | 
				
			||||||
@@ -97,7 +96,7 @@ export function createBoard(boardData: object)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    boardMat.makeBasis(xD, yD, ZD);
 | 
					    boardMat.makeBasis(xD, yD, ZD);
 | 
				
			||||||
    boardMat.setPosition(pBase);
 | 
					    boardMat.setPosition(pBase);
 | 
				
			||||||
    matInv.getInverse(boardMat, true);
 | 
					    matInv.getInverse(boardMat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (boardPts && boardPts.length !== 0)
 | 
					    if (boardPts && boardPts.length !== 0)
 | 
				
			||||||
        for (let i = 0; i < boardPts.length; i++)
 | 
					        for (let i = 0; i < boardPts.length; i++)
 | 
				
			||||||
@@ -105,7 +104,7 @@ export function createBoard(boardData: object)
 | 
				
			|||||||
            let pt = getVec(boardPts[i]);
 | 
					            let pt = getVec(boardPts[i]);
 | 
				
			||||||
            if (boardPts[i].z !== undefined)
 | 
					            if (boardPts[i].z !== undefined)
 | 
				
			||||||
                pt.applyMatrix4(matInv);
 | 
					                pt.applyMatrix4(matInv);
 | 
				
			||||||
            pts.push(new THREE.Vector2(pt.x, pt.y));
 | 
					            pts.push(new Vector2(pt.x, pt.y));
 | 
				
			||||||
            buls.push(boardBuls[i]);
 | 
					            buls.push(boardBuls[i]);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
@@ -126,14 +125,20 @@ export function createBoard(boardData: object)
 | 
				
			|||||||
    let extrudeSettings = {
 | 
					    let extrudeSettings = {
 | 
				
			||||||
        steps: 1,
 | 
					        steps: 1,
 | 
				
			||||||
        bevelEnabled: false,
 | 
					        bevelEnabled: false,
 | 
				
			||||||
        amount: boardHeight
 | 
					        depth: boardHeight
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let ext = new THREE.ExtrudeGeometry(sp, extrudeSettings) as Geometry;
 | 
					    let ext = new ExtrudeGeometry(sp, extrudeSettings) as Geometry;
 | 
				
			||||||
    ext.computeBoundingSphere();
 | 
					    ext.computeBoundingSphere();
 | 
				
			||||||
    ext.computeBoundingBox();
 | 
					    ext.computeBoundingBox();
 | 
				
			||||||
    ext.translate(0, 0, -boardHeight)
 | 
					    ext.translate(0, 0, -boardHeight)
 | 
				
			||||||
    ext.applyMatrix(boardMat);
 | 
					    ext.applyMatrix4(boardMat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!equalv3(xD.clone().cross(yD), ZD))
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        for (let f of ext.faces)
 | 
				
			||||||
 | 
					            [f.a, f.c] = [f.c, f.a];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //外边.
 | 
					    //外边.
 | 
				
			||||||
    let edges: (LineSegments | Mesh)[] = [createEdge(ext)];
 | 
					    let edges: (LineSegments | Mesh)[] = [createEdge(ext)];
 | 
				
			||||||
@@ -167,7 +172,7 @@ export function createBoard(boardData: object)
 | 
				
			|||||||
                else             //1反
 | 
					                else             //1反
 | 
				
			||||||
                    geo.translate(dri.x, dri.y, dri.h * 0.5 - boardData["H"]);
 | 
					                    geo.translate(dri.x, dri.y, dri.h * 0.5 - boardData["H"]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                geo.applyMatrix(boardMat);
 | 
					                geo.applyMatrix4(boardMat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                let mesh = new Mesh(geo, ColorMaterial.GetBasicMaterial(1));
 | 
					                let mesh = new Mesh(geo, ColorMaterial.GetBasicMaterial(1));
 | 
				
			||||||
                edges.push(mesh);
 | 
					                edges.push(mesh);
 | 
				
			||||||
@@ -185,7 +190,7 @@ export function createBoard(boardData: object)
 | 
				
			|||||||
    if (boardData["BoardName"] === "地脚线")
 | 
					    if (boardData["BoardName"] === "地脚线")
 | 
				
			||||||
        RotateUVs(ext);
 | 
					        RotateUVs(ext);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let mesh = new THREE.Mesh(ext, boardMaterial);
 | 
					    let mesh = new Mesh(ext, boardMaterial);
 | 
				
			||||||
    mesh.userData = ZD;
 | 
					    mesh.userData = ZD;
 | 
				
			||||||
    edges.forEach(e => e.userData = ZD);
 | 
					    edges.forEach(e => e.userData = ZD);
 | 
				
			||||||
    return { mesh, edges };
 | 
					    return { mesh, edges };
 | 
				
			||||||
@@ -211,6 +216,6 @@ export function createTemplateBoard(brDataList: any[])
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export function createEdge(geo: Geometry): LineSegments
 | 
					export function createEdge(geo: Geometry): LineSegments
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    let edge = new THREE.EdgesGeometry(geo, 1);
 | 
					    let edge = new EdgesGeometry(geo, 1);
 | 
				
			||||||
    return new LineSegments(edge, edgeMaterial);
 | 
					    return new LineSegments(edge, edgeMaterial);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -96,7 +96,7 @@ downloadTypes({
 | 
				
			|||||||
    urlPath: "https://gitee.com/BearCAD/DefinitelyType2/raw/master/three/",
 | 
					    urlPath: "https://gitee.com/BearCAD/DefinitelyType2/raw/master/three/",
 | 
				
			||||||
    files: [
 | 
					    files: [
 | 
				
			||||||
        // "index.d.ts",
 | 
					        // "index.d.ts",
 | 
				
			||||||
        "three-core.d.ts",
 | 
					        // "three-core.d.ts",
 | 
				
			||||||
        // "three-outlinepass.d.ts",
 | 
					        // "three-outlinepass.d.ts",
 | 
				
			||||||
        // "three-smaapass.d.ts"
 | 
					        // "three-smaapass.d.ts"
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user