41 Commits

Author SHA1 Message Date
xief
c586096fe0 更新版本号 2021-04-08 14:56:48 +08:00
xief
0aa70fdb14 新增鼠标选择回调事件 2021-03-17 15:53:32 +08:00
xief
93ac737777 支持材质自定义 2021-03-03 15:07:59 +08:00
xiefan
01110a8858 Merge remote-tracking branch 'origin/master' into select-block 2020-10-20 14:16:22 +08:00
xiefan
77f997b849 更新three版本 2020-10-20 14:16:04 +08:00
xiefan
23fa547a3a 修复类型错误 2020-10-20 14:03:21 +08:00
FishOrBear
e712b7b4e2 同步代码 2020-05-07 10:51:27 +08:00
xiefan
d266b5ac2d Merge branch 'master' into select-block 2020-04-30 17:21:10 +08:00
FishOrBear
85db279fab 更新版本,修复镜像槽问题 2020-04-30 17:12:30 +08:00
xiefan
5bccd97ab1 修复选择无法取消 2020-04-03 10:32:08 +08:00
xiefan
caa39923dd 调整选择板代码 2020-04-03 10:17:02 +08:00
xiefan
35347e004e 调整板材选择 2020-04-02 17:24:43 +08:00
xiefan
2fd1b48d32 调整包配置 2020-04-01 16:25:47 +08:00
xiefan
a10bb71035 调整threejs类型 2020-04-01 16:12:28 +08:00
xiefan
1fbd3d6563 更新package配置,移除弃用文件 2020-04-01 15:47:30 +08:00
xiefan
fc4c46d280 新增通过ID选中板材 2020-04-01 14:15:29 +08:00
ChenX
d79d759091 更新爆炸图例子 2018-10-29 14:49:40 +08:00
ChenX
bda2b05204 更新配置,能够简单运行实例. 2018-10-12 17:02:10 +08:00
ChenX
2ef48e17c6 更新打包设置 2018-08-17 21:26:32 +08:00
ChenX
c99f7f8149 升级到webpack4 2018-08-17 17:39:11 +08:00
ChenX
563ea73750 view构造函数允许直接传入一个画布. 2018-07-02 15:19:22 +08:00
ChenX
c1e9aac48b 修正内存泄漏,提供增量加载. 2018-07-02 12:07:16 +08:00
ChenX
fcf2a1eb73 暴露相机控制变量. 2018-06-06 17:44:54 +08:00
ChenX
29a6dd0fff 更新编译输出为es5支持老旧的浏览器 2018-06-06 17:23:22 +08:00
ChenX
256a7ea8a6 修正在手机状态下得到的视图大小错误的问题. 2018-06-06 16:00:53 +08:00
ChenX
1f0a91b75a 加入umd编译配置,精简调色面板的数量. 2018-06-05 10:08:20 +08:00
ChenX
fa20fa5f48 排钻显示改成实体显示. 2018-05-31 21:01:30 +08:00
ChenX
f72bb04ff5 取消排钻挖孔. 2018-05-31 15:57:24 +08:00
ChenX
ffd1404d12 修正排钻孔洞没有在正确的位置 2018-05-31 11:24:37 +08:00
ChenX
128b1bcf70 更新版本号 2018-05-31 11:13:05 +08:00
ChenX
cbe28efb08 分离选择材质,避免实体选中时,选中材质导致的内部拉槽显示问题.
修正未选中板件时,视图没有刷新的问题.
加入排钻显示.
2018-05-31 11:12:29 +08:00
ChenX
4f3d7a6388 增加用户缩放相机体验,扩大相机范围,并且限定用户的缩放范围,避免缩放后物体过小而对象找不到的问题. 2018-05-31 10:48:43 +08:00
ChenX
35443367f3 增加双击中键缩放到全部的特性. 2018-05-31 10:35:32 +08:00
ChenX
957107378e Merge branch 'master' of http://git.cf/cx/CADViewComponent 2018-05-30 18:32:45 +08:00
ChenX
2a17e619a2 清理代码格式 2018-05-30 18:32:42 +08:00
xf
5fc8d4b0f4 Merge branch 'master' of http://git.cf/cx/CADViewComponent 2018-05-30 11:20:29 +08:00
xf
2a209becbb 增加仓库地址配置 2018-05-30 11:20:10 +08:00
ChenX
e3c565a83d 将包设置为私有 2018-05-29 10:30:41 +08:00
ChenX
2cd7f413da 更新版本号 2018-05-29 10:13:54 +08:00
ChenX
aed2217f2e 修正z轴为空的时候 判断错误的问题. 2018-05-29 10:13:37 +08:00
ChenX
98cd31e18c 保证格式统一. 2018-05-29 09:57:50 +08:00
83 changed files with 9696 additions and 1723 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
/node_modules
/package-lock.json
.history

2
.vscode/launch.json vendored
View File

@@ -8,7 +8,7 @@
"type": "chrome",
"request": "launch",
"name": "启动 Chrome 并打开 localhost",
"url": "http://localhost:666",
"url": "http://localhost:7776",
"webRoot": "${workspaceFolder}"
}
]

15
.vscode/settings.json vendored
View File

@@ -1,3 +1,16 @@
// 将设置放入此文件中以覆盖默认值和用户设置。
{
"editor.formatOnSave": true
"typescript.tsdk": "node_modules\\typescript\\lib",
//格式化设置
"editor.tabSize": 4,
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
//格式设置
"typescript.format.placeOpenBraceOnNewLineForFunctions": true,
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": true,
"typescript.referencesCodeLens.enabled": true,
"javascript.format.placeOpenBraceOnNewLineForFunctions": true,
"javascript.format.enable": true,
"files.insertFinalNewline": true,
"editor.detectIndentation": true,
}

2
config/umd/cad.js Normal file

File diff suppressed because one or more lines are too long

1
config/umd/cad.js.map Normal file

File diff suppressed because one or more lines are too long

41
config/webpack.common.ts Normal file
View File

@@ -0,0 +1,41 @@
import * as HardSourceWebpackPlugin from 'hard-source-webpack-plugin';
import * as webpack from 'webpack';
import ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const TS_LOADER = [
{ loader: 'cache-loader', options: { cacheDirectory: "node_modules/.cache_loader" } },
{
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
}
];
const config: webpack.Configuration = {
devtool: "source-map",
//项目需要解析的文件拓展名称
resolve: {
extensions: [".ts", ".tsx", ".js", "json"]
},
//模块加载器设置
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: TS_LOADER,
},
{ test: /\.css$/, loader: ['style-loader', 'css-loader'] },
{ test: /\.[(jpg)|(png)|(obj)|(json)]$/, loader: "url-loader" },
]
},
plugins: [
new HardSourceWebpackPlugin(),
new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true }),
]
}
export default config;

24
config/webpack.umd.ts Normal file
View File

@@ -0,0 +1,24 @@
import * as webpack from 'webpack';
import * as merge from 'webpack-merge';
import common from './webpack.common';
import * as path from 'path';
const config: webpack.Configuration = merge(
common,
{
mode: "production",
entry: "./src/index.ts",
externals: {
'three': "THREE"
},
//输出设置
output: {
filename: "cad.js",
path: path.resolve(__dirname, './umd'),
library: "cad",
libraryTarget: "umd"
},
}
);
export default config;

29
config/webpack.view.ts Normal file
View File

@@ -0,0 +1,29 @@
import * as webpack from 'webpack';
import * as merge from 'webpack-merge';
import common from './webpack.common';
import * as HtmlWebPackPlugin from "html-webpack-plugin";
const config: webpack.Configuration = merge(
common,
{
mode: "development",
entry: "./src/ViewSrc/index.ts",
output: { pathinfo: false },
devtool: "eval-source-map",
devServer: {
contentBase: "./dist/",
port: 7776,
hot: true,
},
plugins: [
new webpack.NamedModulesPlugin(),//Hot
new webpack.HotModuleReplacementPlugin(),//Hot
new HtmlWebPackPlugin({
title: "webCAD",
// template: './src/index.html'
}),
]
}
);
export default config;

View File

@@ -5,7 +5,7 @@ export declare enum CameraControlState {
Null = 0,
Pan = 1,
Rotate = 2,
Scale = 3,
Scale = 3
}
export declare class CameraControls {
m_TouthTypeList: CameraControlState[];
@@ -31,6 +31,7 @@ export declare class CameraControls {
onTouchEnd: (event: TouchEvent) => void;
onTouchMove: (event: TouchEvent) => void;
beginRotate(): void;
lastMiddleClickTime: number;
onMouseDown: (event: MouseEvent) => void;
onMouseUp: (event: MouseEvent) => void;
onMouseMove: (event: MouseEvent) => void;

146
dist/CameraControls.js vendored
View File

@@ -1,15 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three");
const KeyEnum_1 = require("./KeyEnum");
const three_1 = require("three");
//控制类型
var CameraControlsEnabled;
(function (CameraControlsEnabled) {
CameraControlsEnabled[CameraControlsEnabled["Rotate"] = 1] = "Rotate";
CameraControlsEnabled[CameraControlsEnabled["Zoom"] = 2] = "Zoom";
CameraControlsEnabled[CameraControlsEnabled["Pan"] = 4] = "Pan";
})(CameraControlsEnabled || (CameraControlsEnabled = {}));
var THREE = require("three");
var KeyEnum_1 = require("./KeyEnum");
var three_1 = require("three");
//相机控制状态
var CameraControlState;
(function (CameraControlState) {
@@ -18,8 +11,9 @@ var CameraControlState;
CameraControlState[CameraControlState["Rotate"] = 2] = "Rotate";
CameraControlState[CameraControlState["Scale"] = 3] = "Scale";
})(CameraControlState = exports.CameraControlState || (exports.CameraControlState = {}));
class CameraControls {
constructor(viewer) {
var CameraControls = /** @class */ (function () {
function CameraControls(viewer) {
var _this = this;
this.m_TouthTypeList = [CameraControlState.Rotate, CameraControlState.Scale, CameraControlState.Pan];
//起始点击
this.m_StartClickPoint = new THREE.Vector3();
@@ -37,36 +31,36 @@ class CameraControls {
*
* @memberof CameraControls
*/
this.onBlur = () => {
this.m_KeyDown.clear();
this.m_MouseDown.clear();
this.onBlur = function () {
_this.m_KeyDown.clear();
_this.m_MouseDown.clear();
};
//触屏开始事件
this.onTouchStart = (event) => {
this.m_Viewer.UpdateLockTarget();
this.m_StartClickPoint.set(event.touches[0].pageX, event.touches[0].pageY, 0);
this.onTouchStart = function (event) {
_this.m_Viewer.UpdateLockTarget();
_this.m_StartClickPoint.set(event.touches[0].pageX, event.touches[0].pageY, 0);
if (event.touches.length < 4) {
if (event.touches.length == 2) {
var dx = event.touches[0].pageX - event.touches[1].pageX;
var dy = event.touches[0].pageY - event.touches[1].pageY;
var distance = Math.sqrt(dx * dx + dy * dy);
this.m_DollyStart.set(0, distance);
_this.m_DollyStart.set(0, distance);
}
this.m_State = this.m_TouthTypeList[event.touches.length - 1];
_this.m_State = _this.m_TouthTypeList[event.touches.length - 1];
}
};
this.onTouchEnd = (event) => {
this.m_State = CameraControlState.Null;
this.onTouchEnd = function (event) {
_this.m_State = CameraControlState.Null;
};
this.onTouchMove = (event) => {
this.onTouchMove = function (event) {
event.preventDefault();
event.stopPropagation();
this.m_EndClickPoint.set(event.touches[0].pageX, event.touches[0].pageY, 0);
let vec = this.m_EndClickPoint.clone().sub(this.m_StartClickPoint);
switch (this.m_State) {
_this.m_EndClickPoint.set(event.touches[0].pageX, event.touches[0].pageY, 0);
var vec = _this.m_EndClickPoint.clone().sub(_this.m_StartClickPoint);
switch (_this.m_State) {
case CameraControlState.Pan:
{
this.m_Viewer.Pan(vec);
_this.m_Viewer.Pan(vec);
break;
}
case CameraControlState.Scale:
@@ -74,46 +68,55 @@ class CameraControls {
var dx = event.touches[0].pageX - event.touches[1].pageX;
var dy = event.touches[0].pageY - event.touches[1].pageY;
var distance = Math.sqrt(dx * dx + dy * dy);
this.m_DollyEnd.set(0, distance);
if (distance > this.m_DollyStart.y) {
this.m_Viewer.Zoom(0.95);
_this.m_DollyEnd.set(0, distance);
if (distance > _this.m_DollyStart.y) {
_this.m_Viewer.Zoom(0.95);
}
else {
this.m_Viewer.Zoom(1.05);
_this.m_Viewer.Zoom(1.05);
}
this.m_DollyStart.copy(this.m_DollyEnd);
_this.m_DollyStart.copy(_this.m_DollyEnd);
break;
}
case CameraControlState.Rotate:
{
this.m_Viewer.Rotate(vec.multiplyScalar(2));
_this.m_Viewer.Rotate(vec.multiplyScalar(2));
break;
}
}
this.m_StartClickPoint.copy(this.m_EndClickPoint);
this.m_Viewer.m_bNeedUpdate = true;
_this.m_StartClickPoint.copy(_this.m_EndClickPoint);
_this.m_Viewer.m_bNeedUpdate = true;
};
//最后一次按中键的时间
this.lastMiddleClickTime = 0;
//鼠标
this.onMouseDown = (event) => {
this.onMouseDown = function (event) {
event.preventDefault();
let key = event.button;
this.m_MouseDown.set(key, true);
this.m_StartClickPoint.set(event.offsetX, event.offsetY, 0);
var key = event.button;
_this.m_MouseDown.set(key, true);
_this.m_StartClickPoint.set(event.offsetX, event.offsetY, 0);
switch (key) {
case KeyEnum_1.MouseKey.Left:
{
if (this.m_LeftUseRotate) {
this.beginRotate();
if (_this.m_LeftUseRotate) {
_this.beginRotate();
}
break;
}
case KeyEnum_1.MouseKey.Middle:
{
if (this.m_KeyDown.get(KeyEnum_1.KeyBoard.Control)) {
this.beginRotate();
var curTime = Date.now();
var t = curTime - _this.lastMiddleClickTime;
_this.lastMiddleClickTime = curTime;
if (t < 350) {
_this.m_Viewer.ZoomAll();
return;
}
if (_this.m_KeyDown.get(KeyEnum_1.KeyBoard.Control)) {
_this.beginRotate();
}
else {
this.m_State = CameraControlState.Pan;
_this.m_State = CameraControlState.Pan;
}
break;
}
@@ -123,25 +126,25 @@ class CameraControls {
}
}
};
this.onMouseUp = (event) => {
this.onMouseUp = function (event) {
event.preventDefault();
this.m_State = CameraControlState.Null;
this.m_MouseDown.set(event.button, false);
_this.m_State = CameraControlState.Null;
_this.m_MouseDown.set(event.button, false);
};
this.onMouseMove = (event) => {
this.onMouseMove = function (event) {
event.preventDefault();
this.m_EndClickPoint.set(event.offsetX, event.offsetY, 0);
let changeVec = this.m_EndClickPoint.clone().sub(this.m_StartClickPoint);
this.m_StartClickPoint.copy(this.m_EndClickPoint);
if ((this.m_LeftUseRotate ||
(this.m_KeyDown.get(KeyEnum_1.KeyBoard.Control)))
&& this.m_State == CameraControlState.Rotate) {
this.m_Viewer.Rotate(changeVec);
_this.m_EndClickPoint.set(event.offsetX, event.offsetY, 0);
var changeVec = _this.m_EndClickPoint.clone().sub(_this.m_StartClickPoint);
_this.m_StartClickPoint.copy(_this.m_EndClickPoint);
if ((_this.m_LeftUseRotate ||
(_this.m_KeyDown.get(KeyEnum_1.KeyBoard.Control)))
&& _this.m_State == CameraControlState.Rotate) {
_this.m_Viewer.Rotate(changeVec);
}
switch (this.m_State) {
switch (_this.m_State) {
case CameraControlState.Pan:
{
this.m_Viewer.Pan(changeVec);
_this.m_Viewer.Pan(changeVec);
break;
}
case CameraControlState.Rotate:
@@ -159,30 +162,30 @@ class CameraControls {
*
* @memberof CameraControls
*/
this.onMouseWheel = (event) => {
this.onMouseWheel = function (event) {
event.preventDefault();
event.stopPropagation();
let pt = new THREE.Vector3(event.offsetX, event.offsetY, 0);
this.m_Viewer.ScreenToWorld(pt, new three_1.Vector3().setFromMatrixColumn(this.m_Viewer.m_Camera.Camera.matrixWorld, 2));
var pt = new THREE.Vector3(event.offsetX, event.offsetY, 0);
_this.m_Viewer.ScreenToWorld(pt, new three_1.Vector3().setFromMatrixColumn(_this.m_Viewer.m_Camera.Camera.matrixWorld, 2));
if (event.deltaY < 0) {
this.m_Viewer.Zoom(0.6, pt);
_this.m_Viewer.Zoom(0.6, pt);
}
else if (event.deltaY > 0) {
this.m_Viewer.Zoom(1.4, pt);
_this.m_Viewer.Zoom(1.4, pt);
}
};
//按键
this.onKeyDown = (event) => {
this.m_KeyDown.set(event.keyCode, true);
this.onKeyDown = function (event) {
_this.m_KeyDown.set(event.keyCode, true);
};
this.onKeyUp = (event) => {
this.m_KeyDown.set(event.keyCode, false);
this.onKeyUp = function (event) {
_this.m_KeyDown.set(event.keyCode, false);
};
this.m_Viewer = viewer;
this.m_domElement = viewer.m_Render.domElement.parentElement;
this.RegisterEvent();
}
RegisterEvent() {
CameraControls.prototype.RegisterEvent = function () {
if (this.m_domElement) {
this.m_domElement.addEventListener("mousedown", this.onMouseDown, false);
this.m_domElement.addEventListener("mousemove", this.onMouseMove, false);
@@ -195,11 +198,12 @@ class CameraControls {
this.m_domElement.addEventListener('touchmove', this.onTouchMove, false);
window.addEventListener("blur", this.onBlur, false);
}
}
beginRotate() {
};
CameraControls.prototype.beginRotate = function () {
this.m_State = CameraControlState.Rotate;
this.m_Viewer.UpdateLockTarget();
}
}
};
return CameraControls;
}());
exports.CameraControls = CameraControls;
//# sourceMappingURL=CameraControls.js.map

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +1,4 @@
import * as THREE from 'three';
import { Box3, Camera, Vector3 } from 'three';
/**
*
* 相机的控制.
@@ -18,22 +18,25 @@ export declare class CameraUpdate {
private m_Target;
private m_Direction;
private m_Orbit;
m_MinViewHeight: number;
m_MaxViewHeight: number;
constructor();
readonly Aspect: number;
readonly Camera: THREE.Camera;
ViewHeight: number;
get Aspect(): number;
get Camera(): Camera;
get ViewHeight(): number;
set ViewHeight(height: number);
SetSize(width: number, height: number): void;
/**
* 平移相机.
*
* @param {THREE.Vector3} mouseMove
* @param {Vector3} mouseMove
* @memberof CameraControl
*/
Pan(mouseMove: THREE.Vector3): void;
Rotate(mouseMove: THREE.Vector3, target: THREE.Vector3): void;
Zoom(scale: number, scaleCenter?: THREE.Vector3): void;
ZoomExtensBox3(box3: THREE.Box3): void;
LookAt(dir: THREE.Vector3): void;
Pan(mouseMove: Vector3): void;
Rotate(mouseMove: Vector3, target: Vector3): void;
Zoom(scale: number, scaleCenter?: Vector3): void;
ZoomExtensBox3(box3: Box3): void;
LookAt(dir: Vector3): void;
UpdateUp(): void;
/**
* 根据视口大小,设置相机视口范围.

124
dist/CameraUpdate.js vendored
View File

@@ -1,8 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three");
const three_1 = require("three");
const Orbit_1 = require("./Orbit");
var three_1 = require("three");
var Orbit_1 = require("./Orbit");
/**
*
* 相机的控制.
@@ -13,64 +12,78 @@ const Orbit_1 = require("./Orbit");
* @export
* @class ViewCameraManage
*/
class CameraUpdate {
constructor() {
var CameraUpdate = /** @class */ (function () {
function CameraUpdate() {
this.m_CameraArray = new Map();
//视口显示的高度
this.m_ViewHeight = 10;
//观察的位置
this.m_Target = new THREE.Vector3();
this.m_Target = new three_1.Vector3();
//观察向量
this.m_Direction = new THREE.Vector3(0, 0, -1);
this.m_Direction = new three_1.Vector3(0, 0, -1);
//观察的轨道.
this.m_Orbit = new Orbit_1.Orbit();
this.m_CameraArray.set(THREE.OrthographicCamera, new THREE.OrthographicCamera(-2, 2, 2, -2, -100000, 100000));
this.m_CameraArray.set(THREE.PerspectiveCamera, new THREE.PerspectiveCamera(50, 1, 0.01, 10000));
this.m_CurCamera = this.m_CameraArray.get(THREE.OrthographicCamera);
this.m_MinViewHeight = 10;
this.m_MaxViewHeight = 3e4;
this.m_CameraArray.set(three_1.OrthographicCamera, new three_1.OrthographicCamera(-2, 2, 2, -2, -1e6, 1e6));
this.m_CameraArray.set(three_1.PerspectiveCamera, new three_1.PerspectiveCamera(50, 1, 0.01, 10000));
this.m_CurCamera = this.m_CameraArray.get(three_1.OrthographicCamera);
this.m_Orbit.UpdateRoValue(this.m_Direction);
this.UpdateUp();
this.Update();
}
get Aspect() {
Object.defineProperty(CameraUpdate.prototype, "Aspect", {
get: function () {
return this.m_Width / this.m_Height;
}
get Camera() {
},
enumerable: true,
configurable: true
});
Object.defineProperty(CameraUpdate.prototype, "Camera", {
get: function () {
return this.m_CurCamera;
}
get ViewHeight() {
},
enumerable: true,
configurable: true
});
Object.defineProperty(CameraUpdate.prototype, "ViewHeight", {
get: function () {
return this.m_ViewHeight;
}
set ViewHeight(height) {
this.m_ViewHeight = THREE.Math.clamp(height, 1e-8, 1e8);
}
SetSize(width, height) {
},
set: function (height) {
this.m_ViewHeight = three_1.MathUtils.clamp(height, this.m_MinViewHeight, this.m_MaxViewHeight);
},
enumerable: true,
configurable: true
});
CameraUpdate.prototype.SetSize = function (width, height) {
this.m_Width = width;
this.m_Height = height;
}
};
/**
* 平移相机.
*
* @param {THREE.Vector3} mouseMove
* @param {Vector3} mouseMove
* @memberof CameraControl
*/
Pan(mouseMove) {
CameraUpdate.prototype.Pan = function (mouseMove) {
mouseMove.y *= -1;
mouseMove.multiplyScalar(-this.m_ViewHeight / this.m_Height);
mouseMove.applyQuaternion(this.Camera.quaternion);
this.m_Target.add(mouseMove);
this.Update();
}
Rotate(mouseMove, target) {
};
CameraUpdate.prototype.Rotate = function (mouseMove, target) {
this.m_Orbit.RoX -= mouseMove.y * 0.003;
this.m_Orbit.RoZ -= mouseMove.x * 0.003;
//缓存观察点
let oldTargetFormCameraSpace = target.clone().applyMatrix4(this.Camera.matrixWorldInverse);
var oldTargetFormCameraSpace = target.clone().applyMatrix4(this.Camera.matrixWorldInverse);
this.m_Orbit.UpdateDirection(this.m_Direction);
this.UpdateUp();
this.Update();
//-----还原观察点
//得到新的观察点相对于相机的位置
let newTargetFormCameraSpace = target.clone().applyMatrix4(this.Camera.matrixWorldInverse);
var newTargetFormCameraSpace = target.clone().applyMatrix4(this.Camera.matrixWorldInverse);
//减去原先的位置. 得到观测点在相机内移动的向量
newTargetFormCameraSpace.sub(oldTargetFormCameraSpace);
//乘以相机的矩阵. 得到向量在世界坐标系的位置
@@ -80,25 +93,25 @@ class CameraUpdate {
//加上移动的向量. 使得观察点时钟在相机的某个位置
this.m_Target.add(newTargetFormCameraSpace);
this.Update();
}
Zoom(scale, scaleCenter) {
if (this.Camera instanceof THREE.OrthographicCamera) {
};
CameraUpdate.prototype.Zoom = function (scale, scaleCenter) {
if (this.Camera instanceof three_1.OrthographicCamera) {
this.ViewHeight *= scale;
if (scaleCenter) {
if (scaleCenter && this.m_ViewHeight < this.m_MaxViewHeight) {
this.m_Target.sub(scaleCenter);
this.m_Target.multiplyScalar(scale);
this.m_Target.add(scaleCenter);
}
}
else if (this.Camera instanceof THREE.PerspectiveCamera) {
let add = scale > 1 ? 1 : -1;
else if (this.Camera instanceof three_1.PerspectiveCamera) {
var add = scale > 1 ? 1 : -1;
add *= this.Camera.position.distanceTo(this.m_Target) / 10;
this.m_Target.add(this.m_Direction.clone().multiplyScalar(-add));
}
this.Update();
}
ZoomExtensBox3(box3) {
if (!box3)
};
CameraUpdate.prototype.ZoomExtensBox3 = function (box3) {
if (!box3 || box3.isEmpty())
return;
this.Camera.updateMatrixWorld(false);
//变换到相机坐标系
@@ -108,10 +121,10 @@ class CameraUpdate {
//世界坐标系
this.m_Target.applyMatrix4(this.Camera.matrix);
//size
let size = box3.getSize(new three_1.Vector3());
var size = box3.getSize(new three_1.Vector3());
//宽高比
let aspectRatio = size.x / size.y;
let viewAspectRatio = this.Aspect;
var aspectRatio = size.x / size.y;
var viewAspectRatio = this.Aspect;
//
if (aspectRatio > viewAspectRatio) {
this.m_ViewHeight = size.x / viewAspectRatio;
@@ -120,34 +133,34 @@ class CameraUpdate {
this.m_ViewHeight = size.y;
}
this.Update();
}
LookAt(dir) {
};
CameraUpdate.prototype.LookAt = function (dir) {
this.m_Orbit.UpdateRoValue(dir);
this.m_Direction.copy(dir);
this.UpdateUp();
this.Update();
}
UpdateUp() {
};
CameraUpdate.prototype.UpdateUp = function () {
Orbit_1.Orbit.ComputUpDirection(this.m_Direction, this.Camera.up);
}
};
/**
* 根据视口大小,设置相机视口范围.
*
* @returns
* @memberof CameraControl
*/
Update() {
CameraUpdate.prototype.Update = function () {
this.Camera.position.copy(this.m_Target);
if (this.Camera instanceof THREE.OrthographicCamera) {
if (this.Camera instanceof three_1.OrthographicCamera) {
this.Camera.left = this.Aspect * this.m_ViewHeight / -2;
this.Camera.right = this.Aspect * this.m_ViewHeight / 2;
this.Camera.bottom = this.m_ViewHeight / -2;
this.Camera.top = this.m_ViewHeight / 2;
this.Camera.position.sub(this.m_Direction);
}
else if (this.Camera instanceof THREE.PerspectiveCamera) {
else if (this.Camera instanceof three_1.PerspectiveCamera) {
this.Camera.aspect = this.Aspect;
let distens = (this.m_ViewHeight / 2) / (Math.tan(THREE.Math.degToRad(this.Camera.fov) / 2));
var distens = (this.m_ViewHeight / 2) / (Math.tan(three_1.MathUtils.degToRad(this.Camera.fov) / 2));
this.Camera.position.sub(this.m_Direction.clone().multiplyScalar(distens));
}
else {
@@ -156,17 +169,18 @@ class CameraUpdate {
this.Camera.lookAt(this.m_Target);
this.Camera.updateProjectionMatrix();
this.Camera.updateMatrixWorld(false);
}
SwitchCamera() {
if (this.Camera instanceof THREE.OrthographicCamera) {
this.m_CurCamera = this.m_CameraArray.get(THREE.PerspectiveCamera);
};
CameraUpdate.prototype.SwitchCamera = function () {
if (this.Camera instanceof three_1.OrthographicCamera) {
this.m_CurCamera = this.m_CameraArray.get(three_1.PerspectiveCamera);
}
else {
this.m_CurCamera = this.m_CameraArray.get(THREE.OrthographicCamera);
this.m_CurCamera = this.m_CameraArray.get(three_1.OrthographicCamera);
}
this.UpdateUp();
this.Update();
}
}
};
return CameraUpdate;
}());
exports.CameraUpdate = CameraUpdate;
//# sourceMappingURL=CameraUpdate.js.map

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,10 @@
import * as THREE from 'three';
import { LineBasicMaterial, MeshBasicMaterial } from 'three';
export declare class ColorMaterial {
private constructor();
private static m_LineMaterialMap;
static GetLineMaterial(index: any): THREE.LineBasicMaterial;
static GetLineMaterial(index: any): LineBasicMaterial;
private static m_BasicMaterialMap;
static GetBasicMaterial(index: number): MeshBasicMaterial;
static GetColor(index: number): THREE.Color;
}

289
dist/ColorPalette.js vendored
View File

@@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three");
const ColorPalette = [
var three_1 = require("three");
var ColorPalette = [
[255, 0, 0, 255],
//[255, 255, 255, 255],//----- 0 - ByBlock - White
[255, 0, 0, 255],
@@ -11,276 +11,33 @@ const ColorPalette = [
[0, 255, 255, 255],
[0, 0, 255, 255],
[255, 0, 255, 255],
// [255, 0, 0, 255], //----- 7 - More red Red
// [255, 0, 0, 255], //----- 8 - More red Red
// [255, 0, 0, 255], //----- 9 - More red Red
[255, 255, 255, 255],
[255, 255, 255, 255],
[255, 255, 255, 255],
[255, 0, 0, 255],
[255, 127, 127, 255],
[165, 0, 0, 255],
[165, 82, 82, 255],
[127, 0, 0, 255],
[127, 63, 63, 255],
[76, 0, 0, 255],
[76, 38, 38, 255],
[38, 0, 0, 255],
[38, 19, 19, 255],
[255, 63, 0, 255],
[255, 159, 127, 255],
[165, 41, 0, 255],
[165, 103, 82, 255],
[127, 31, 0, 255],
[127, 79, 63, 255],
[76, 19, 0, 255],
[76, 47, 38, 255],
[38, 9, 0, 255],
[38, 23, 19, 255],
[255, 127, 0, 255],
[255, 191, 127, 255],
[165, 82, 0, 255],
[165, 124, 82, 255],
[127, 63, 0, 255],
[127, 95, 63, 255],
[76, 38, 0, 255],
[76, 57, 38, 255],
[38, 19, 0, 255],
[38, 28, 19, 255],
[255, 191, 0, 255],
[255, 223, 127, 255],
[165, 124, 0, 255],
[165, 145, 82, 255],
[127, 95, 0, 255],
[127, 111, 63, 255],
[76, 57, 0, 255],
[76, 66, 38, 255],
[38, 28, 0, 255],
[38, 33, 19, 255],
[255, 255, 0, 255],
[255, 255, 127, 255],
[165, 165, 0, 255],
[165, 165, 82, 255],
[127, 127, 0, 255],
[127, 127, 63, 255],
[76, 76, 0, 255],
[76, 76, 38, 255],
[38, 38, 0, 255],
[38, 38, 19, 255],
[191, 255, 0, 255],
[223, 255, 127, 255],
[124, 165, 0, 255],
[145, 165, 82, 255],
[95, 127, 0, 255],
[111, 127, 63, 255],
[57, 76, 0, 255],
[66, 76, 38, 255],
[28, 38, 0, 255],
[33, 38, 19, 255],
[127, 255, 0, 255],
[191, 255, 127, 255],
[82, 165, 0, 255],
[124, 165, 82, 255],
[63, 127, 0, 255],
[95, 127, 63, 255],
[38, 76, 0, 255],
[57, 76, 38, 255],
[19, 38, 0, 255],
[28, 38, 19, 255],
[63, 255, 0, 255],
[159, 255, 127, 255],
[41, 165, 0, 255],
[103, 165, 82, 255],
[31, 127, 0, 255],
[79, 127, 63, 255],
[19, 76, 0, 255],
[47, 76, 38, 255],
[9, 38, 0, 255],
[23, 38, 19, 255],
[0, 255, 0, 255],
[127, 255, 127, 255],
[0, 165, 0, 255],
[82, 165, 82, 255],
[0, 127, 0, 255],
[63, 127, 63, 255],
[0, 76, 0, 255],
[38, 76, 38, 255],
[0, 38, 0, 255],
[19, 38, 19, 255],
[0, 255, 63, 255],
[127, 255, 159, 255],
[0, 165, 41, 255],
[82, 165, 103, 255],
[0, 127, 31, 255],
[63, 127, 79, 255],
[0, 76, 19, 255],
[38, 76, 47, 255],
[0, 38, 9, 255],
[19, 38, 23, 255],
[0, 255, 127, 255],
[127, 255, 191, 255],
[0, 165, 82, 255],
[82, 165, 124, 255],
[0, 127, 63, 255],
[63, 127, 95, 255],
[0, 76, 38, 255],
[38, 76, 57, 255],
[0, 38, 19, 255],
[19, 38, 28, 255],
[0, 255, 191, 255],
[127, 255, 223, 255],
[0, 165, 124, 255],
[82, 165, 145, 255],
[0, 127, 95, 255],
[63, 127, 111, 255],
[0, 76, 57, 255],
[38, 76, 66, 255],
[0, 38, 28, 255],
[19, 38, 33, 255],
[0, 255, 255, 255],
[127, 255, 255, 255],
[0, 165, 165, 255],
[82, 165, 165, 255],
[0, 127, 127, 255],
[63, 127, 127, 255],
[0, 76, 76, 255],
[38, 76, 76, 255],
[0, 38, 38, 255],
[19, 38, 38, 255],
[0, 191, 255, 255],
[127, 223, 255, 255],
[0, 124, 165, 255],
[82, 145, 165, 255],
[0, 95, 127, 255],
[63, 111, 127, 255],
[0, 57, 76, 255],
[38, 66, 76, 255],
[0, 28, 38, 255],
[19, 33, 38, 255],
[0, 127, 255, 255],
[127, 191, 255, 255],
[0, 82, 165, 255],
[82, 124, 165, 255],
[0, 63, 127, 255],
[63, 95, 127, 255],
[0, 38, 76, 255],
[38, 57, 76, 255],
[0, 19, 38, 255],
[19, 28, 38, 255],
[0, 63, 255, 255],
[127, 159, 255, 255],
[0, 41, 165, 255],
[82, 103, 165, 255],
[0, 31, 127, 255],
[63, 79, 127, 255],
[0, 19, 76, 255],
[38, 47, 76, 255],
[0, 9, 38, 255],
[19, 23, 38, 255],
[0, 0, 255, 255],
[127, 127, 255, 255],
[0, 0, 165, 255],
[82, 82, 165, 255],
[0, 0, 127, 255],
[63, 63, 127, 255],
[0, 0, 76, 255],
[38, 38, 76, 255],
[0, 0, 38, 255],
[19, 19, 38, 255],
[63, 0, 255, 255],
[159, 127, 255, 255],
[41, 0, 165, 255],
[103, 82, 165, 255],
[31, 0, 127, 255],
[79, 63, 127, 255],
[19, 0, 76, 255],
[47, 38, 76, 255],
[9, 0, 38, 255],
[23, 19, 38, 255],
[127, 0, 255, 255],
[191, 127, 255, 255],
[82, 0, 165, 255],
[124, 82, 165, 255],
[63, 0, 127, 255],
[95, 63, 127, 255],
[38, 0, 76, 255],
[57, 38, 76, 255],
[19, 0, 38, 255],
[28, 19, 38, 255],
[191, 0, 255, 255],
[223, 127, 255, 255],
[124, 0, 165, 255],
[145, 82, 165, 255],
[95, 0, 127, 255],
[111, 63, 127, 255],
[57, 0, 76, 255],
[66, 38, 76, 255],
[28, 0, 38, 255],
[33, 19, 38, 255],
[255, 0, 255, 255],
[255, 127, 255, 255],
[165, 0, 165, 255],
[165, 82, 165, 255],
[127, 0, 127, 255],
[127, 63, 127, 255],
[76, 0, 76, 255],
[76, 38, 76, 255],
[38, 0, 38, 255],
[38, 19, 38, 255],
[255, 0, 191, 255],
[255, 127, 223, 255],
[165, 0, 124, 255],
[165, 82, 145, 255],
[127, 0, 95, 255],
[127, 63, 111, 255],
[76, 0, 57, 255],
[76, 38, 66, 255],
[38, 0, 28, 255],
[38, 19, 33, 255],
[255, 0, 127, 255],
[255, 127, 191, 255],
[165, 0, 82, 255],
[165, 82, 124, 255],
[127, 0, 63, 255],
[127, 63, 95, 255],
[76, 0, 38, 255],
[76, 38, 57, 255],
[38, 0, 19, 255],
[38, 19, 28, 255],
[255, 0, 63, 255],
[255, 127, 159, 255],
[165, 0, 41, 255],
[165, 82, 103, 255],
[127, 0, 31, 255],
[127, 63, 79, 255],
[76, 0, 19, 255],
[76, 38, 47, 255],
[38, 0, 9, 255],
[38, 19, 23, 255],
[84, 84, 84, 255],
[118, 118, 118, 255],
[152, 152, 152, 255],
[186, 186, 186, 255],
[220, 220, 220, 255],
[255, 255, 255, 255],
[255, 255, 255, 255] //----- ByLayer - White
];
//颜色材质,对于二维图像来说可能有用,应该不对三维对象使用该材质
class ColorMaterial {
constructor() { }
static GetLineMaterial(index) {
var ColorMaterial = /** @class */ (function () {
function ColorMaterial() {
}
ColorMaterial.GetLineMaterial = function (index) {
if (this.m_LineMaterialMap.has(index))
return this.m_LineMaterialMap.get(index);
let mat = new THREE.LineBasicMaterial({ color: this.GetColor(index) });
var mat = new three_1.LineBasicMaterial({ color: this.GetColor(index) });
this.m_LineMaterialMap.set(index, mat);
return mat;
}
static GetColor(index) {
let rgb = ColorPalette[index];
};
ColorMaterial.GetBasicMaterial = function (index) {
if (this.m_BasicMaterialMap.has(index))
return this.m_BasicMaterialMap.get(index);
var mat = new three_1.MeshBasicMaterial({ color: this.GetColor(index) });
this.m_BasicMaterialMap.set(index, mat);
return mat;
};
ColorMaterial.GetColor = function (index) {
var rgb = ColorPalette[index];
if (rgb)
return new THREE.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255);
}
}
ColorMaterial.m_LineMaterialMap = new Map();
return new three_1.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255);
};
ColorMaterial.m_LineMaterialMap = new Map();
ColorMaterial.m_BasicMaterialMap = new Map();
return ColorMaterial;
}());
exports.ColorMaterial = ColorMaterial;
//# sourceMappingURL=ColorPalette.js.map

File diff suppressed because one or more lines are too long

1
dist/Dimension.d.ts vendored
View File

@@ -1,7 +1,6 @@
import { Group } from "three";
/**
* 标注实体
*
* @export
* @class Dimension
* @extends {Group}

64
dist/Dimension.js vendored
View File

@@ -1,46 +1,64 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const three_1 = require("three");
const ColorPalette_1 = require("./ColorPalette");
const Text_1 = require("./Text");
const GeUtils_1 = require("./GeUtils");
var three_1 = require("three");
var ColorPalette_1 = require("./ColorPalette");
var Text_1 = require("./Text");
var GeUtils_1 = require("./GeUtils");
/**
* 标注实体
*
* @export
* @class Dimension
* @extends {Group}
*/
class Dimension extends three_1.Group {
constructor(length, textHeight = 25, mirror = false, mirrorFoot = false) {
super();
let footLength = 60;
var Dimension = /** @class */ (function (_super) {
__extends(Dimension, _super);
function Dimension(length, textHeight, mirror, mirrorFoot) {
if (textHeight === void 0) { textHeight = 25; }
if (mirror === void 0) { mirror = false; }
if (mirrorFoot === void 0) { mirrorFoot = false; }
var _this = _super.call(this) || this;
var footLength = 60;
if (mirrorFoot) {
footLength = -footLength;
}
//针脚几何体
let lineGeo = new three_1.Geometry();
var lineGeo = new three_1.Geometry();
lineGeo.vertices.push(new three_1.Vector3(), new three_1.Vector3(0, footLength, 0));
//托盘几何体
let lineGeo2 = new three_1.Geometry();
var lineGeo2 = new three_1.Geometry();
lineGeo2.vertices.push(new three_1.Vector3(0, footLength), new three_1.Vector3(length, footLength, 0));
let material = ColorPalette_1.ColorMaterial.GetLineMaterial(5);
let line1 = new three_1.Line(lineGeo, material);
let line2 = new three_1.Line(lineGeo, material);
var material = ColorPalette_1.ColorMaterial.GetLineMaterial(5);
var line1 = new three_1.Line(lineGeo, material);
var line2 = new three_1.Line(lineGeo, material);
line2.position.x = length;
let line3 = new three_1.Line(lineGeo2, material);
let text = new Text_1.DbText(parseFloat(length.toFixed(2)).toString(), textHeight);
var line3 = new three_1.Line(lineGeo2, material);
var text = new Text_1.DbText(parseFloat(length.toFixed(2)).toString(), textHeight);
if (mirror) {
let roMat = new three_1.Matrix4().makeRotationZ(Math.PI);
text.applyMatrix(roMat);
text.applyMatrix(GeUtils_1.MoveMatrix(new three_1.Vector3(length * 0.5, footLength - textHeight * 0.1)));
var roMat = new three_1.Matrix4().makeRotationZ(Math.PI);
text.applyMatrix4(roMat);
text.applyMatrix4(GeUtils_1.MoveMatrix(new three_1.Vector3(length * 0.5, footLength - textHeight * 0.1)));
}
else {
text.applyMatrix(GeUtils_1.MoveMatrix(new three_1.Vector3(length * 0.5, footLength * 1.1)));
text.applyMatrix4(GeUtils_1.MoveMatrix(new three_1.Vector3(length * 0.5, footLength * 1.1)));
}
this.add(text);
this.add(line1, line2, line3);
_this.add(text);
_this.add(line1, line2, line3);
return _this;
}
}
return Dimension;
}(three_1.Group));
exports.Dimension = Dimension;
//# sourceMappingURL=Dimension.js.map

View File

@@ -1 +1 @@
{"version":3,"file":"Dimension.js","sourceRoot":"","sources":["../src/Dimension.ts"],"names":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GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;;IAClC,CAAC;IACL,gBAAC;AAAD,CAAC,AA7CD,CAA+B,aAAK,GA6CnC;AA7CY,8BAAS"}

24
dist/DrawDimension.js vendored
View File

@@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const three_1 = require("three");
const _1 = require(".");
var three_1 = require("three");
var _1 = require(".");
/**
* 绘制标注实体
*
@@ -10,22 +10,22 @@ const _1 = require(".");
* @returns 标注实体列表
*/
function DrawDimension(brList) {
let box = _1.GetBoxArr(brList);
let size = box.getSize(new three_1.Vector3());
let mat4 = new three_1.Matrix4();
var box = _1.GetBoxArr(brList);
var size = box.getSize(new three_1.Vector3());
var mat4 = new three_1.Matrix4();
mat4.makeBasis(new three_1.Vector3(-1, 0, 0), new three_1.Vector3(0, -1, 0), new three_1.Vector3(0, 0, 1));
mat4.setPosition(box.min.clone().add(new three_1.Vector3(size.x, -30)));
let textHeight = 45;
let dimx = new _1.Dimension(size.x, textHeight, true);
dimx.applyMatrix(mat4);
let dimz = new _1.Dimension(size.z, textHeight);
var textHeight = 45;
var dimx = new _1.Dimension(size.x, textHeight, true);
dimx.applyMatrix4(mat4);
var dimz = new _1.Dimension(size.z, textHeight);
mat4.makeBasis(new three_1.Vector3(0, 0, -1), new three_1.Vector3(1, 0, 0), new three_1.Vector3(0, -1, 0));
mat4.setPosition(box.max.clone().add(new three_1.Vector3(30, -size.y)));
dimz.applyMatrix(mat4);
let dimy = new _1.Dimension(size.y, textHeight, true, true);
dimz.applyMatrix4(mat4);
var dimy = new _1.Dimension(size.y, textHeight, true, true);
mat4.makeBasis(new three_1.Vector3(0, 1, 0), new three_1.Vector3(-1, 0, 0), new three_1.Vector3(0, 0, 1));
mat4.setPosition(box.max.clone().add(new three_1.Vector3(30, -size.y)));
dimy.applyMatrix(mat4);
dimy.applyMatrix4(mat4);
return [dimx, dimy, dimz];
}
exports.DrawDimension = DrawDimension;

View File

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C,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACrB,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CACvB,CAAA;IACD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,IAAI,eAAO,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAGxB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC;AArCD,sCAqCC"}

52
dist/GeUtils.d.ts vendored
View File

@@ -1,9 +1,8 @@
import * as THREE from 'three';
import { Geometry, Vector, Vector2, Vector3 } from 'three';
export declare const cZeroVec: THREE.Vector3;
export declare const cXAxis: THREE.Vector3;
export declare const cYAxis: THREE.Vector3;
export declare const cZAxis: THREE.Vector3;
import { Geometry, Vector, Vector2, Vector3, Box3, Matrix4, Object3D, Line, Mesh } from 'three';
export declare const cZeroVec: Vector3;
export declare const cXAxis: Vector3;
export declare const cYAxis: Vector3;
export declare const cZAxis: Vector3;
/**
* 旋转一个点,旋转中心在原点
*
@@ -14,6 +13,7 @@ export declare const cZAxis: THREE.Vector3;
*/
export declare function rotatePoint(pt: Vector3, ang: number): Vector3;
export declare function equaln(v1: number, v2: number, fuzz?: number): boolean;
export declare function equalv3(v1: Vector3, v2: Vector3, fuzz?: number): boolean;
export declare function equal<T extends Vector>(v1: T, v2: T): boolean;
export declare function fixAngle(an: number, fixAngle: number, fuzz?: number): number;
/**
@@ -31,29 +31,35 @@ export declare function angle(v: Vector3 | Vector2): number;
/**
* 求两个向量的夹角,顺时针为负,逆时针为正
*
* @param {THREE.Vector3} v1
* @param {THREE.Vector3} v2
* @param {THREE.Vector3} [ref] 参考向量,如果为世界坐标系则为0,0,1
* @param {Vector3} v1
* @param {Vector3} v2
* @param {Vector3} [ref] 参考向量,如果为世界坐标系则为0,0,1
* @returns
*/
export declare function angleTo(v1: THREE.Vector3, v2: THREE.Vector3, ref?: THREE.Vector3): number;
export declare function getLoocAtUpVec(dir: THREE.Vector3): THREE.Vector3;
export declare function createLookAtMat4(dir: THREE.Vector3): THREE.Matrix4;
export declare function isParallelTo(v1: THREE.Vector3, v2: THREE.Vector3): boolean;
export declare function ptToString(v: THREE.Vector3, fractionDigits?: number): string;
export declare function midPoint(v1: THREE.Vector3, v2: THREE.Vector3): THREE.Vector3;
export declare function midPoint2(v1: THREE.Vector2, v2: THREE.Vector2): THREE.Vector2;
export declare function midPtCir(v1: THREE.Vector3, v2: THREE.Vector3): THREE.Vector3;
export declare function GetBox(obj: THREE.Object3D, updateMatrix?: boolean): THREE.Box3;
export declare function GetBoxArr(arr: Array<THREE.Object3D>): THREE.Box3;
export declare function MoveMatrix(v: THREE.Vector3): THREE.Matrix4;
export declare function angleTo(v1: Vector3, v2: Vector3, ref?: Vector3): number;
export declare function getLoocAtUpVec(dir: Vector3): Vector3;
export declare function createLookAtMat4(dir: Vector3): Matrix4;
export declare function isParallelTo(v1: Vector3, v2: Vector3): boolean;
export declare function ptToString(v: Vector3, fractionDigits?: number): string;
export declare function midPoint(v1: Vector3, v2: Vector3): Vector3;
export declare function midPoint2(v1: Vector2, v2: Vector2): Vector2;
export declare function midPtCir(v1: Vector3, v2: Vector3): Vector3;
/**
* 获得Three对象的包围盒.
* @param obj
* @param [updateMatrix] 是否应该更新对象矩阵
* @returns box
*/
export declare function GetBox(obj: Object3D, updateMatrix?: boolean): Box3;
export declare function GetBoxArr(arr: Array<Object3D>): Box3;
export declare function MoveMatrix(v: Vector3): Matrix4;
export declare function getProjectDist(v1: Vector3, v2: Vector3): {
h: number;
v: number;
};
export declare function getPtPostion(sp: Vector3, ep: Vector3, c: Vector3, inPt: Vector3): {
sp: THREE.Vector3;
ep: THREE.Vector3;
sp: Vector3;
ep: Vector3;
};
export declare function angleAndX(v: Vector3 | Vector2): number;
/**
@@ -63,4 +69,4 @@ export declare function angleAndX(v: Vector3 | Vector2): number;
* @param {number} an
*/
export declare function angleTo2Pi(an: number): number;
export declare function updateGeometry(l: THREE.Line | THREE.Mesh, geometry: Geometry): void;
export declare function updateGeometry(l: Line | Mesh, geometry: Geometry): void;

154
dist/GeUtils.js vendored
View File

@@ -1,12 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three");
const three_1 = require("three");
const Matrix2_1 = require("./Matrix2");
exports.cZeroVec = new THREE.Vector3();
exports.cXAxis = new THREE.Vector3(1, 0, 0);
exports.cYAxis = new THREE.Vector3(0, 1, 0);
exports.cZAxis = new THREE.Vector3(0, 0, 1);
var three_1 = require("three");
var Matrix2_1 = require("./Matrix2");
exports.cZeroVec = new three_1.Vector3();
exports.cXAxis = new three_1.Vector3(1, 0, 0);
exports.cYAxis = new three_1.Vector3(0, 1, 0);
exports.cZAxis = new three_1.Vector3(0, 0, 1);
/**
* 旋转一个点,旋转中心在原点
*
@@ -20,19 +19,26 @@ function rotatePoint(pt, ang) {
return pt;
}
exports.rotatePoint = rotatePoint;
function equaln(v1, v2, fuzz = 1e-3) {
function equaln(v1, v2, fuzz) {
if (fuzz === void 0) { fuzz = 1e-3; }
return Math.abs(v1 - v2) < fuzz;
}
exports.equaln = equaln;
function equalv3(v1, v2, fuzz) {
if (fuzz === void 0) { fuzz = 1e-8; }
return equaln(v1.x, v2.x, fuzz) && equaln(v1.y, v2.y, fuzz) && equaln(v1.z, v2.z, fuzz);
}
exports.equalv3 = equalv3;
function equal(v1, v2) {
return v1.distanceToSquared(v2) < 1e-8;
}
exports.equal = equal;
function fixAngle(an, fixAngle, fuzz = 0.1) {
function fixAngle(an, fixAngle, fuzz) {
if (fuzz === void 0) { fuzz = 0.1; }
if (an < 0)
an += Math.PI * 2;
an += fuzz;
let rem = an % fixAngle;
var rem = an % fixAngle;
if (rem < fuzz * 2) {
an -= rem;
}
@@ -61,7 +67,7 @@ exports.polar = polar;
function angle(v) {
if (equaln(v.y, 0) && v.x > 0)
return 0;
let angle = Math.atan2(v.y, v.x);
var angle = Math.atan2(v.y, v.x);
if (angle < 0)
angle += Math.PI * 2;
return angle;
@@ -70,19 +76,20 @@ exports.angle = angle;
/**
* 求两个向量的夹角,顺时针为负,逆时针为正
*
* @param {THREE.Vector3} v1
* @param {THREE.Vector3} v2
* @param {THREE.Vector3} [ref] 参考向量,如果为世界坐标系则为0,0,1
* @param {Vector3} v1
* @param {Vector3} v2
* @param {Vector3} [ref] 参考向量,如果为世界坐标系则为0,0,1
* @returns
*/
function angleTo(v1, v2, ref = new THREE.Vector3(0, 0, 1)) {
function angleTo(v1, v2, ref) {
if (ref === void 0) { ref = new three_1.Vector3(0, 0, 1); }
if (!ref.equals(new three_1.Vector3(0, 0, 1))) {
//任意轴坐标系. 使用相机的构造矩阵.
ref.multiplyScalar(-1);
let up = getLoocAtUpVec(ref);
let refOcs = new THREE.Matrix4();
var up = getLoocAtUpVec(ref);
var refOcs = new three_1.Matrix4();
refOcs.lookAt(exports.cZeroVec, ref, up);
let refOcsInv = new THREE.Matrix4().getInverse(refOcs);
var refOcsInv = new three_1.Matrix4().getInverse(refOcs);
v1.applyMatrix4(refOcsInv);
v2.applyMatrix4(refOcsInv);
v1.z = 0;
@@ -90,7 +97,7 @@ function angleTo(v1, v2, ref = new THREE.Vector3(0, 0, 1)) {
}
if (v1.equals(exports.cZeroVec) || v2.equals(exports.cZeroVec))
return 0;
let cv = new three_1.Vector3().crossVectors(v1, v2).normalize();
var cv = new three_1.Vector3().crossVectors(v1, v2).normalize();
return cv.z === 0 ? v1.angleTo(v2) : v1.angleTo(v2) * cv.z;
}
exports.angleTo = angleTo;
@@ -98,25 +105,25 @@ function getLoocAtUpVec(dir) {
if (dir.equals(exports.cZeroVec)) {
throw ("zero vector");
}
let norm = dir.clone().normalize();
var norm = dir.clone().normalize();
if (norm.equals(exports.cZAxis)) {
return new THREE.Vector3(0, 1, 0);
return new three_1.Vector3(0, 1, 0);
}
else if (norm.equals(exports.cZAxis.clone().negate())) {
return new THREE.Vector3(0, -1, 0);
return new three_1.Vector3(0, -1, 0);
}
else {
let xv = new THREE.Vector3();
var xv = new three_1.Vector3();
xv.crossVectors(exports.cZAxis, norm);
let up = new THREE.Vector3();
var up = new three_1.Vector3();
up.crossVectors(norm, xv);
return up;
}
}
exports.getLoocAtUpVec = getLoocAtUpVec;
function createLookAtMat4(dir) {
let up = getLoocAtUpVec(dir);
let mat = new THREE.Matrix4();
var up = getLoocAtUpVec(dir);
var mat = new three_1.Matrix4();
mat.lookAt(exports.cZeroVec, dir, up);
return mat;
}
@@ -125,8 +132,9 @@ function isParallelTo(v1, v2) {
return v1.clone().cross(v2).lengthSq() < 1e-9;
}
exports.isParallelTo = isParallelTo;
function ptToString(v, fractionDigits = 3) {
return v.toArray().map(o => {
function ptToString(v, fractionDigits) {
if (fractionDigits === void 0) { fractionDigits = 3; }
return v.toArray().map(function (o) {
return o.toFixed(fractionDigits);
}).join(",");
}
@@ -140,60 +148,60 @@ function midPoint2(v1, v2) {
}
exports.midPoint2 = midPoint2;
function midPtCir(v1, v2) {
let baseline = new three_1.Vector3(1, 0, 0);
let outLine = v2.clone().sub(v1);
let ang = angleTo(baseline, outLine) / 2;
let midLine = rotatePoint(outLine, -ang);
var baseline = new three_1.Vector3(1, 0, 0);
var outLine = v2.clone().sub(v1);
var ang = angleTo(baseline, outLine) / 2;
var midLine = rotatePoint(outLine, -ang);
return v1.clone().add(midLine);
}
exports.midPtCir = midPtCir;
/**
* 获得Three对象的包围盒.
* @param obj
* @param [updateMatrix] 是否应该更新对象矩阵
* @returns box
*/
function GetBox(obj, updateMatrix) {
var box = new three_1.Box3();
if (updateMatrix)
obj.updateMatrixWorld(false);
if (obj.hasOwnProperty("geometry")) {
let geo = obj["geometry"];
if (geo instanceof THREE.Geometry || geo instanceof THREE.BufferGeometry) {
if (!obj.visible)
return box;
obj.traverse(function (o) {
//因为实体Erase时,实体仍然保存在Scene中.
if (o.visible === false)
return;
//@ts-ignore
var geo = o.geometry;
if (geo) {
if (!geo.boundingBox)
geo.computeBoundingBox();
return geo.boundingBox.clone().applyMatrix4(obj.matrixWorld);
box.union(geo.boundingBox.clone().applyMatrix4(o.matrixWorld));
}
}
else if (obj.children.length > 0) {
let box = obj.children.reduce((sumBox, itemObj) => {
let itemBox = GetBox(itemObj);
if (itemBox)
sumBox.union(itemBox);
return sumBox;
}, new THREE.Box3());
// if (box) box.applyMatrix4(obj.matrixWorld);
});
return box;
}
else
return null;
}
exports.GetBox = GetBox;
function GetBoxArr(arr) {
if (arr.length == 0) {
return null;
var box = new three_1.Box3();
for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
var o = arr_1[_i];
var b = GetBox(o);
if (!b.isEmpty())
box.union(b);
}
return arr.map(o => {
return GetBox(o);
}).filter(o => {
return o;
}).reduce((sumBox, objBox) => {
return sumBox.union(objBox);
}, new THREE.Box3());
return box;
}
exports.GetBoxArr = GetBoxArr;
function MoveMatrix(v) {
let mat = new THREE.Matrix4();
var mat = new three_1.Matrix4();
mat.makeTranslation(v.x, v.y, v.z);
return mat;
}
exports.MoveMatrix = MoveMatrix;
function getProjectDist(v1, v2) {
let ang = v1.angleTo(v2);
let dist = v1.length();
var ang = v1.angleTo(v2);
var dist = v1.length();
return {
h: dist * Math.cos(ang),
v: dist * Math.sin(ang)
@@ -202,31 +210,31 @@ function getProjectDist(v1, v2) {
exports.getProjectDist = getProjectDist;
//获得输入点在2线组成的4个区间的位置
function getPtPostion(sp, ep, c, inPt) {
let l1 = sp.clone().sub(c);
let l2 = ep.clone().sub(c);
let l3 = l1.clone().negate();
let l4 = l2.clone().negate();
let inputLine = inPt.clone().sub(c);
let ang1 = angleTo(l1, l2);
let ang2 = Math.PI;
let ang3 = ang2 + Math.abs(ang1);
let inputAng = angleTo(l1, inputLine);
var l1 = sp.clone().sub(c);
var l2 = ep.clone().sub(c);
var l3 = l1.clone().negate();
var l4 = l2.clone().negate();
var inputLine = inPt.clone().sub(c);
var ang1 = angleTo(l1, l2);
var ang2 = Math.PI;
var ang3 = ang2 + Math.abs(ang1);
var inputAng = angleTo(l1, inputLine);
if (ang1 * inputAng < 0) {
inputAng = (Math.PI * 2 - Math.abs(inputAng));
}
ang1 = Math.abs(ang1);
inputAng = Math.abs(inputAng);
if (inputAng <= ang1) {
return { sp, ep };
return { sp: sp, ep: ep };
}
else if (inputAng > ang1 && inputAng <= ang2) {
return { sp: c.clone().add(l3), ep };
return { sp: c.clone().add(l3), ep: ep };
}
else if (inputAng > ang2 && inputAng <= ang3) {
return { sp: c.clone().add(l3), ep: c.clone().add(l4) };
}
else {
return { sp, ep: c.clone().add(l4) };
return { sp: sp, ep: c.clone().add(l4) };
}
}
exports.getPtPostion = getPtPostion;
@@ -248,7 +256,7 @@ function angleTo2Pi(an) {
}
exports.angleTo2Pi = angleTo2Pi;
function updateGeometry(l, geometry) {
let geo = l.geometry;
var geo = l.geometry;
geo.dispose();
l.geometry = geometry;
geometry.verticesNeedUpdate = true;

2
dist/GeUtils.js.map vendored

File diff suppressed because one or more lines are too long

4
dist/KeyEnum.d.ts vendored
View File

@@ -1,7 +1,7 @@
export declare enum MouseKey {
Left = 0,
Middle = 1,
Right = 2,
Right = 2
}
export declare enum KeyBoard {
Digit1 = 49,
@@ -145,5 +145,5 @@ export declare enum KeyBoard {
NumpadMultiply = 106,
NumpadSubtract = 109,
NumpadDot = 110,
NumpadDot1 = 190,
NumpadDot1 = 190
}

1
dist/Material.d.ts vendored
View File

@@ -1,3 +1,4 @@
import { MeshBasicMaterial, LineBasicMaterial } from "three";
export declare let boardMaterial: MeshBasicMaterial;
export declare let selectMaterial: MeshBasicMaterial;
export declare let edgeMaterial: LineBasicMaterial;

8
dist/Material.js vendored
View File

@@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const three_1 = require("three");
var three_1 = require("three");
//板件的材质,使用这个材质避免板件将线覆盖.
exports.boardMaterial = new three_1.MeshBasicMaterial({
color: new three_1.Color(0.8, 0.8, 0.8),
@@ -8,6 +8,12 @@ exports.boardMaterial = new three_1.MeshBasicMaterial({
polygonOffsetFactor: 1,
polygonOffsetUnits: 1
});
exports.selectMaterial = new three_1.MeshBasicMaterial({
color: new three_1.Color(0.1, 0.5, 0.5),
polygonOffset: true,
polygonOffsetFactor: 1,
polygonOffsetUnits: 1
});
//线框的材质
exports.edgeMaterial = new three_1.LineBasicMaterial({ linewidth: 2, color: new three_1.Color(0, 0, 0) });
//# sourceMappingURL=Material.js.map

View File

@@ -1 +1 @@
{"version":3,"file":"Material.js","sourceRoot":"","sources":["../src/Material.ts"],"names":[],"mappings":";;AAAA,iCAAoE;AAEpE,uBAAuB;AACZ,QAAA,aAAa,GAAG,IAAI,yBAAiB,CAAC;IAC7C,KAAK,EAAE,IAAI,aAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IAC/B,aAAa,EAAE,IAAI;IACnB,mBAAmB,EAAE,CAAC;IACtB,kBAAkB,EAAE,CAAC;CACxB,CAAC,CAAC;AAEH,OAAO;AACI,QAAA,YAAY,GAAG,IAAI,yBAAiB,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,aAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC"}
{"version":3,"file":"Material.js","sourceRoot":"","sources":["../src/Material.ts"],"names":[],"mappings":";;AAAA,+BAAoE;AAEpE,uBAAuB;AACZ,QAAA,aAAa,GAAG,IAAI,yBAAiB,CAAC;IAC7C,KAAK,EAAE,IAAI,aAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IAC/B,aAAa,EAAE,IAAI;IACnB,mBAAmB,EAAE,CAAC;IACtB,kBAAkB,EAAE,CAAC;CACxB,CAAC,CAAC;AAEQ,QAAA,cAAc,GAAG,IAAI,yBAAiB,CAAC;IAC9C,KAAK,EAAE,IAAI,aAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IAC/B,aAAa,EAAE,IAAI;IACnB,mBAAmB,EAAE,CAAC;IACtB,kBAAkB,EAAE,CAAC;CACxB,CAAC,CAAC;AAEH,OAAO;AACI,QAAA,YAAY,GAAG,IAAI,yBAAiB,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,aAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC"}

29
dist/Matrix2.js vendored
View File

@@ -1,30 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Matrix2 {
constructor() {
var Matrix2 = /** @class */ (function () {
function Matrix2() {
this.el = [1, 0, 0, 1];
}
set(n11, n12, n21, n22) {
let te = this.el;
Matrix2.prototype.set = function (n11, n12, n21, n22) {
var te = this.el;
te[0] = n11;
te[1] = n21;
te[2] = n12;
te[3] = n22;
return this;
}
applyVector(vec) {
let x = vec.x, y = vec.y;
let e = this.el;
};
Matrix2.prototype.applyVector = function (vec) {
var x = vec.x, y = vec.y;
var e = this.el;
vec.x = e[0] * x + e[2] * y;
vec.y = e[1] * x + e[3] * y;
return this;
}
setRotate(theta) {
let el = this.el;
let c = Math.cos(theta), s = Math.sin(theta);
};
Matrix2.prototype.setRotate = function (theta) {
var el = this.el;
var c = Math.cos(theta), s = Math.sin(theta);
this.set(c, -s, s, c);
return this;
}
}
};
return Matrix2;
}());
exports.Matrix2 = Matrix2;
//# sourceMappingURL=Matrix2.js.map

2
dist/Matrix2.js.map vendored
View File

@@ -1 +1 @@
{"version":3,"file":"Matrix2.js","sourceRoot":"","sources":["../src/Matrix2.ts"],"names":[],"mappings":";;AAEA;IAAA;QAEY,OAAE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IA4B9B,CAAC;IA3BG,GAAG,CAAC,GAAW,EAAE,GAAW,EAAE,GAAW,EAAE,GAAW;QAElD,IAAI,EAAE,GAAG,IAAI,CAA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,GAAW,EAAE,GAAW;QAElD,IAAI,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAEjB,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACzB,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACzB,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,6BAAW,GAAX,UAAY,GAAsB;QAE9B,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QACzB,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;QAChB,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC5B,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAE5B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,2BAAS,GAAT,UAAU,KAAa;QAEnB,IAAI,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QACjB,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAE7C,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EACV,CAAC,EAAE,CAAC,CAAC,CAAC;QACV,OAAO,IAAI,CAAC;IAChB,CAAC;IACL,cAAC;AAAD,CAAC,AA9BD,IA8BC;AA9BY,0BAAO"}

23
dist/Orbit.d.ts vendored
View File

@@ -1,4 +1,4 @@
import * as THREE from "three";
import { Vector3 } from "three";
/**
* 轨道控制的数学类,观察向量和角度的互相转换
* 当x当抬头或者低头到90度时,触发万向锁.
@@ -8,31 +8,32 @@ import * as THREE from "three";
export declare class Orbit {
private m_RoX;
RoZ: number;
RoX: number;
get RoX(): number;
set RoX(v: number);
/**
* 使用旋转角度 计算观察向量
*
* @param {THREE.Vector3} [dir] 引用传入,如果传入,那么就不构造新的向量
* @returns {THREE.Vector3} 返回观察向量
* @param {Vector3} [dir] 引用传入,如果传入,那么就不构造新的向量
* @returns {Vector3} 返回观察向量
* @memberof Orbit
*/
UpdateDirection(dir?: THREE.Vector3): THREE.Vector3;
UpdateDirection(dir?: Vector3): Vector3;
/**
* 使用观察向量,计算旋转角度
*
* @param {THREE.Vector3} dir
* @param {Vector3} dir
* @memberof Orbit
*/
UpdateRoValue(dir: THREE.Vector3): void;
UpdateRoValue(dir: Vector3): void;
/**
*
* 根据观察向量 求头部的向量.
*
* @static
* @param {THREE.Vector3} dir
* @param {THREE.Vector3} [up]
* @returns {THREE.Vector3}
* @param {Vector3} dir
* @param {Vector3} [up]
* @returns {Vector3}
* @memberof Orbit
*/
static ComputUpDirection(dir: THREE.Vector3, up?: THREE.Vector3): THREE.Vector3;
static ComputUpDirection(dir: Vector3, up?: Vector3): Vector3;
}

61
dist/Orbit.js vendored
View File

@@ -1,81 +1,86 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three");
var three_1 = require("three");
/**
* 轨道控制的数学类,观察向量和角度的互相转换
* 当x当抬头或者低头到90度时,触发万向锁.
*
* @class Orbit
*/
class Orbit {
constructor() {
var Orbit = /** @class */ (function () {
function Orbit() {
//抬头低头 正数抬头 负数低头
this.m_RoX = 0;
//身体旋转 0为正右边 逆时针旋转
this.RoZ = 0;
}
get RoX() {
Object.defineProperty(Orbit.prototype, "RoX", {
get: function () {
return this.m_RoX;
}
set RoX(v) {
this.m_RoX = THREE.Math.clamp(v, Math.PI * -0.5, Math.PI * 0.5);
}
},
set: function (v) {
this.m_RoX = three_1.MathUtils.clamp(v, Math.PI * -0.5, Math.PI * 0.5);
},
enumerable: true,
configurable: true
});
/**
* 使用旋转角度 计算观察向量
*
* @param {THREE.Vector3} [dir] 引用传入,如果传入,那么就不构造新的向量
* @returns {THREE.Vector3} 返回观察向量
* @param {Vector3} [dir] 引用传入,如果传入,那么就不构造新的向量
* @returns {Vector3} 返回观察向量
* @memberof Orbit
*/
UpdateDirection(dir) {
let rtDir = dir ? dir : new THREE.Vector3();
Orbit.prototype.UpdateDirection = function (dir) {
var rtDir = dir ? dir : new three_1.Vector3();
rtDir.z = Math.sin(this.m_RoX);
//归一化专用.
let d = Math.abs(Math.cos(this.m_RoX));
var d = Math.abs(Math.cos(this.m_RoX));
rtDir.x = Math.cos(this.RoZ) * d;
rtDir.y = Math.sin(this.RoZ) * d;
return rtDir;
}
};
/**
* 使用观察向量,计算旋转角度
*
* @param {THREE.Vector3} dir
* @param {Vector3} dir
* @memberof Orbit
*/
UpdateRoValue(dir) {
Orbit.prototype.UpdateRoValue = function (dir) {
dir.normalize();
this.m_RoX = Math.asin(dir.z);
if (dir.x < 1e-4 && dir.y < 1e-4)
this.RoZ = Math.PI * 0.5;
else
this.RoZ = Math.atan2(dir.y, dir.x);
}
};
/**
*
* 根据观察向量 求头部的向量.
*
* @static
* @param {THREE.Vector3} dir
* @param {THREE.Vector3} [up]
* @returns {THREE.Vector3}
* @param {Vector3} dir
* @param {Vector3} [up]
* @returns {Vector3}
* @memberof Orbit
*/
static ComputUpDirection(dir, up) {
let upRes = up ? up : new THREE.Vector3();
if (dir.equals(new THREE.Vector3(0, 0, -1))) {
Orbit.ComputUpDirection = function (dir, up) {
var upRes = up ? up : new three_1.Vector3();
if (dir.equals(new three_1.Vector3(0, 0, -1))) {
upRes.set(0, 1, 0);
}
else if (dir.equals(new THREE.Vector3(0, 0, 1))) {
else if (dir.equals(new three_1.Vector3(0, 0, 1))) {
upRes.set(0, -1, 0);
}
else {
let xv = new THREE.Vector3();
xv.crossVectors(new THREE.Vector3(0, 0, 1), dir);
var xv = new three_1.Vector3();
xv.crossVectors(new three_1.Vector3(0, 0, 1), dir);
upRes.crossVectors(dir, xv);
upRes.normalize();
}
return upRes;
}
}
};
return Orbit;
}());
exports.Orbit = Orbit;
//# sourceMappingURL=Orbit.js.map

2
dist/Orbit.js.map vendored
View File

@@ -1 +1 @@
{"version":3,"file":"Orbit.js","sourceRoot":"","sources":["../src/Orbit.ts"],"names":[],"mappings":";;AAAA,+BAA+B;AAE/B;;;;;GAKG;AACH;IAAA;QAEI,gBAAgB;QACR,UAAK,GAAW,CAAC,CAAC;QAE1B,kBAAkB;QAClB,QAAG,GAAW,CAAC,CAAC;IA+EpB,CAAC;IA7EG,IAAI,GAAG;QAEH,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IACD,IAAI,GAAG,CAAC,CAAC;QAEL,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;OAMG;IACH,eAAe,CAAC,GAAmB;QAE/B,IAAI,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAE5C,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAE/B,QAAQ;QACR,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAEvC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEjC,OAAO,KAAK,CAAC;IACjB,CAAC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AC;AAAD,CAAC,AArFD,IAqFC;AArFY,sBAAK"}

6
dist/PlaneExt.d.ts vendored
View File

@@ -1,7 +1,7 @@
import * as THREE from 'three';
import { Vector3, Line3 } from "three";
export declare class PlaneExt extends THREE.Plane {
constructor(normal?: THREE.Vector3, constant?: number);
import { Vector3, Line3, Plane } from "three";
export declare class PlaneExt extends Plane {
constructor(normal?: Vector3, constant?: number);
intersectLine(line: Line3, optionalTarget?: Vector3, extendLine?: boolean): Vector3;
intersectRay(ray: THREE.Ray, optionalTarget?: Vector3, extendLine?: boolean): Vector3;
}

47
dist/PlaneExt.js vendored
View File

@@ -1,16 +1,30 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three");
const three_1 = require("three");
class PlaneExt extends THREE.Plane {
constructor(normal, constant) {
super(normal, constant);
var THREE = require("three");
var three_1 = require("three");
var PlaneExt = /** @class */ (function (_super) {
__extends(PlaneExt, _super);
function PlaneExt(normal, constant) {
return _super.call(this, normal, constant) || this;
}
intersectLine(line, optionalTarget, extendLine) {
let v1 = new three_1.Vector3();
let result = optionalTarget || new three_1.Vector3();
let direction = line.delta(v1);
let denominator = this.normal.dot(direction);
PlaneExt.prototype.intersectLine = function (line, optionalTarget, extendLine) {
var v1 = new three_1.Vector3();
var result = optionalTarget || new three_1.Vector3();
var direction = line.delta(v1);
var denominator = this.normal.dot(direction);
if (denominator === 0) {
// line is coplanar, return origin
if (this.distanceToPoint(line.start) === 0) {
@@ -19,18 +33,19 @@ class PlaneExt extends THREE.Plane {
// Unsure if this is the correct method to handle this case.
return undefined;
}
let t = -(line.start.dot(this.normal) + this.constant) / denominator;
var t = -(line.start.dot(this.normal) + this.constant) / denominator;
//If you not extendLine,check intersect point in Line
if (!extendLine && (t < 0 || t > 1)) {
return undefined;
}
return result.copy(direction).multiplyScalar(t).add(line.start);
}
intersectRay(ray, optionalTarget, extendLine) {
};
PlaneExt.prototype.intersectRay = function (ray, optionalTarget, extendLine) {
// 从射线初始位置
let line = new THREE.Line3(ray.origin.clone(), ray.origin.clone().add(ray.direction));
var line = new THREE.Line3(ray.origin.clone(), ray.origin.clone().add(ray.direction));
return this.intersectLine(line, optionalTarget, extendLine);
}
}
};
return PlaneExt;
}(three_1.Plane));
exports.PlaneExt = PlaneExt;
//# sourceMappingURL=PlaneExt.js.map

View File

@@ -1 +1 @@
{"version":3,"file":"PlaneExt.js","sourceRoot":"","sources":["../src/PlaneExt.ts"],"names":[],"mappings":";;AAAA,+BAA+B;AAC/B,iCAAuC;AAEvC,cAAsB,SAAQ,KAAK,CAAC,KAAK;IAErC,YAAY,MAAsB,EAAE,QAAiB;QAEjD,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC5B,CAAC;IACD,aAAa,CAAC,IAAW,EAAE,cAAwB,EAAE,UAAoB;QAErE,IAAI,EAAE,GAAG,IAAI,eAAO,EAAE,CAAC;QAEvB,IAAI,MAAM,GAAG,cAAc,IAAI,IAAI,eAAO,EAAE,CAAC;QAE7C,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAE/B,IAAI,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAE7C,IAAI,WAAW,KAAK,CAAC,EACrB;YACI,kCAAkC;YAClC,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAC1C;gBACI,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aAClC;Y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,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const three_1 = require("three");
var three_1 = require("three");
/**
* 点选
*
@@ -11,20 +11,21 @@ const three_1 = require("three");
* @returns {(Mesh | undefined)}
*/
function PointPick(view, ptx, pty) {
let raycaster = new three_1.Raycaster();
var raycaster = new three_1.Raycaster();
raycaster.setFromCamera({
x: (ptx / view._Width) * 2 - 1,
y: -(pty / view._Height) * 2 + 1 //y轴相反
}, view.m_Camera.Camera);
//https://github.com/mrdoob/three.js/issues/14128
raycaster.ray.origin.set((ptx / view._Width) * 2 - 1, -(pty / view._Height) * 2 + 1, -1).unproject(view.m_Camera.Camera);
let minDis = Infinity;
let minObj = undefined;
view.m_Scene.children.forEach(obj => {
var minDis = Infinity;
var minObj = undefined;
view.m_Scene.children.forEach(function (obj) {
if (obj instanceof three_1.Mesh) {
let intersects = [];
var intersects = [];
obj.raycast(raycaster, intersects);
for (let i of intersects) {
for (var _i = 0, intersects_1 = intersects; _i < intersects_1.length; _i++) {
var i = intersects_1[_i];
if (i.distance < minDis) {
minObj = obj;
minDis = i.distance;

View File

@@ -1 +1 @@
{"version":3,"file":"PointPick.js","sourceRoot":"","sources":["../src/PointPick.ts"],"names":[],"mappings":";;AAAA,iCAA2E;AAc3E;;;;;;;;GAQG;AACH,mBAA0B,IAAY,EAAE,GAAW,EAAE,GAAW;IAE5D,IAAI,SAAS,GAAG,IAAI,iBAAS,EAAE,CAAC;IAChC,SAAS,CAAC,aAAa,CAAC;QACpB,CAAC,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;QAC9B,CAAC,EAAE,CAAE,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM;KAC3C,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAEzB,iDAAiD;IACjD,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,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AQ,CAAC,MAAM,CAAC,CAAC;IAEzB,iDAAiD;IACjD,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAG1H,IAAI,MAAM,GAAG,QAAQ,CAAC;IACtB,IAAI,MAAM,GAAG,SAAS,CAAC;IAEvB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAA,GAAG;QAE7B,IAAI,GAAG,YAAY,YAAI,EACvB;YACI,IAAI,UAAU,GAAgB,EAAE,CAAC;YACjC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;YAEnC,KAAc,UAAU,EAAV,yBAAU,EAAV,wBAAU,EAAV,IAAU,EACxB;gBADK,IAAI,CAAC,mBAAA;gBAEN,IAAI,CAAC,CAAC,QAAQ,GAAG,MAAM,EACvB;oBACI,MAAM,GAAG,GAAG,CAAC;oBACb,MAAM,GAAG,CAAC,CAAC,QAAQ,CAAC;iBACvB;aACJ;SACJ;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC;AAlCD,8BAkCC"}

4
dist/RotateUV.d.ts vendored
View File

@@ -1,2 +1,2 @@
import * as THREE from 'three';
export declare function RotateUVs(geo: THREE.Geometry): void;
import { Geometry } from 'three';
export declare function RotateUVs(geo: Geometry): void;

17
dist/RotateUV.js vendored
View File

@@ -1,14 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Matrix2_1 = require("./Matrix2");
const THREE = require("three");
var Matrix2_1 = require("./Matrix2");
var three_1 = require("three");
function RotateUVs(geo) {
let roMat = new Matrix2_1.Matrix2();
var roMat = new Matrix2_1.Matrix2();
roMat.set(0, -1, 1, 0);
let addV = new THREE.Vector2(1, 0);
for (let uvs of geo.faceVertexUvs) {
for (let uv of uvs) {
for (let v of uv) {
var addV = new three_1.Vector2(1, 0);
for (var _i = 0, _a = geo.faceVertexUvs; _i < _a.length; _i++) {
var uvs = _a[_i];
for (var _b = 0, uvs_1 = uvs; _b < uvs_1.length; _b++) {
var uv = uvs_1[_b];
for (var _c = 0, uv_1 = uv; _c < uv_1.length; _c++) {
var v = uv_1[_c];
roMat.applyVector(v);
v.add(addV);
}

View File

@@ -1 +1 @@
{"version":3,"file":"RotateUV.js","sourceRoot":"","sources":["../src/RotateUV.ts"],"names":[],"mappings":";;AAAA,uCAAoC;AACpC,+BAA+B;AAG/B,mBAA0B,GAAmB;IAEzC,IAAI,KAAK,GAAG,IAAI,iBAAO,EAAE,CAAC;IAC1B,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EACX,CAAC,EAAE,CAAC,CAAC,CAAC;IAEV,IAAI,IAAI,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEnC,KAAK,IAAI,GAAG,IAAI,GAAG,CAAC,aAAa,EACjC;QACI,KAAK,IAAI,EAAE,IAAI,GAAG,EAClB;YACI,KAAK,IAAI,CAAC,IAAI,EAAE,EAChB;gBACI,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;gBACrB,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;aACf;SACJ;KACJ;IACD,GAAG,CAAC,aAAa,GAAG,IAAI,CAAC;AAC7B,CAAC;AApBD,8BAoBC"}
{"version":3,"file":"RotateUV.js","sourceRoot":"","sources":["../src/RotateUV.ts"],"names":[],"mappings":";;AAAA,qCAAoC;AACpC,+BAA0C;AAG1C,SAAgB,SAAS,CAAC,GAAa;IAEnC,IAAI,KAAK,GAAG,IAAI,iBAAO,EAAE,CAAC;IAC1B,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EACX,CAAC,EAAE,CAAC,CAAC,CAAC;IAEV,IAAI,IAAI,GAAG,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAE7B,KAAgB,UAAiB,EAAjB,KAAA,GAAG,CAAC,aAAa,EAAjB,cAAiB,EAAjB,IAAiB,EACjC;QADK,IAAI,GAAG,SAAA;QAER,KAAe,UAAG,EAAH,WAAG,EAAH,iBAAG,EAAH,IAAG,EAClB;YADK,IAAI,EAAE,YAAA;YAEP,KAAc,UAAE,EAAF,SAAE,EAAF,gBAAE,EAAF,IAAE,EAChB;gBADK,IAAI,CAAC,WAAA;gBAEN,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;gBACrB,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;aACf;SACJ;KACJ;IACD,GAAG,CAAC,aAAa,GAAG,IAAI,CAAC;AAC7B,CAAC;AApBD,8BAoBC"}

57
dist/Text.js vendored
View File

@@ -1,19 +1,36 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const three_1 = require("three");
const ColorPalette_1 = require("./ColorPalette");
const GeUtils_1 = require("./GeUtils");
class FontLoaderUtil {
static Load() {
var three_1 = require("three");
var ColorPalette_1 = require("./ColorPalette");
var GeUtils_1 = require("./GeUtils");
var FontLoaderUtil = /** @class */ (function () {
function FontLoaderUtil() {
}
FontLoaderUtil.Load = function () {
if (!this.defFont) {
const f = require("../resources/fonts/helvetiker_regular.typeface.json");
let loader = new three_1.FontLoader();
var f = require("../resources/fonts/helvetiker_regular.typeface.json");
var loader = new three_1.FontLoader();
this.defFont = loader.parse(f);
}
return this.defFont;
}
}
class DbText extends three_1.Mesh {
};
return FontLoaderUtil;
}());
var DbText = /** @class */ (function (_super) {
__extends(DbText, _super);
/**
*
* 构造一个文本对象,8位点(中心点下面)在0点
@@ -21,15 +38,19 @@ class DbText extends three_1.Mesh {
* @param {number} height 文本高度
* @memberof DbText
*/
constructor(str, height = 5) {
let font = FontLoaderUtil.Load();
let shapes = font.generateShapes(str, height, 0.1);
let geometry = new three_1.ShapeGeometry(shapes);
function DbText(str, height) {
if (height === void 0) { height = 5; }
var _this = this;
var font = FontLoaderUtil.Load();
var shapes = font.generateShapes(str, height);
var geometry = new three_1.ShapeGeometry(shapes);
geometry.computeBoundingBox();
super(geometry, ColorPalette_1.ColorMaterial.GetLineMaterial(5));
let center = geometry.boundingBox.getCenter(new three_1.Vector3());
this.applyMatrix(GeUtils_1.MoveMatrix(new three_1.Vector3(-center.x, 0, 0)));
_this = _super.call(this, geometry, ColorPalette_1.ColorMaterial.GetBasicMaterial(5)) || this;
var center = geometry.boundingBox.getCenter(new three_1.Vector3());
_this.applyMatrix4(GeUtils_1.MoveMatrix(new three_1.Vector3(-center.x, 0, 0)));
return _this;
}
}
return DbText;
}(three_1.Mesh));
exports.DbText = DbText;
//# sourceMappingURL=Text.js.map

2
dist/Text.js.map vendored
View File

@@ -1 +1 @@
{"version":3,"file":"Text.js","sourceRoot":"","sources":["../src/Text.ts"],"names":[],"mappings":";;AAAA,iCAAuE;AACvE,iDAA+C;AAC/C,uCAAuC;AAEvC;IAEE,MAAM,CAAC,IAAI;QACT,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,MAAM,CAAC,GAAG,OAAO,CAAC,qDAAqD,CAAC,CAAC;YACzE,IAAI,MAAM,GAAG,IAAI,kBAAU,EAAE,CAAC;YAC9B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CA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ED;IAA4B,0BAAI;IAE9B;;;;;;OAMG;IACH,gBAAY,GAAW,EAAE,MAAkB;QAAlB,uBAAA,EAAA,UAAkB;QAA3C,iBAaC;QAXC,IAAI,IAAI,GAAG,cAAc,CAAC,IAAI,EAAE,CAAC;QAEjC,IAAI,MAAM,GAAkB,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC7D,IAAI,QAAQ,GAAG,IAAI,qBAAa,CAAC,MAAM,CAAC,CAAC;QAEzC,QAAQ,CAAC,kBAAkB,EAAE,CAAC;QAE9B,QAAA,kBAAM,QAAQ,EAAE,4BAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,SAAC;QAEnD,IAAI,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,eAAO,EAAE,CAAC,CAAC;QAC3D,KAAI,CAAC,YAAY,CAAC,oBAAU,CAAC,IAAI,eAAO,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;;IAC9D,CAAC;IACH,aAAC;AAAD,CAAC,AAvBD,CAA4B,YAAI,GAuB/B;AAvBY,wBAAM"}

4
dist/ThreeCSG.d.ts vendored
View File

@@ -20,8 +20,8 @@ export declare class Polygon {
calculateProperties(): this;
clone(): Polygon;
flip(): this;
classifyVertex(vertex: any): 0 | 1 | 2;
classifySide(polygon: any): 0 | 1 | 2 | 3;
classifyVertex(vertex: any): 1 | 2 | 0;
classifySide(polygon: any): 1 | 3 | 2 | 0;
splitPolygon(polygon: any, coplanar_front: any, coplanar_back: any, front: any, back: any): void;
}
export declare class Vertex {

220
dist/ThreeCSG.js vendored
View File

@@ -1,14 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three");
var THREE = require("three");
/*jshint esversion: 6 */
const EPSILON = 1e-5, COPLANAR = 0, //共面
var EPSILON = 1e-5, COPLANAR = 0, //共面
FRONT = 1, //前
BACK = 2, SPANNING = 3;
class ThreeBSP {
constructor(geometry) {
var ThreeBSP = /** @class */ (function () {
function ThreeBSP(geometry) {
// Convert THREE.Geometry to ThreeBSP
let i, _length_i, face, vertex, faceVertexUvs, uvs, polygon, polygons = [], tree;
var i, _length_i, face, vertex, faceVertexUvs, uvs, polygon, polygons = [], tree;
this.Polygon = Polygon;
this.Vertex = Vertex;
this.Node = Node;
@@ -50,28 +50,6 @@ class ThreeBSP {
vertex.applyMatrix4(this.matrix);
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 {
throw 'Invalid face type at index ' + i;
}
@@ -81,8 +59,8 @@ class ThreeBSP {
this.tree = new Node(polygons);
}
//减
subtract(other_tree) {
let a = this.tree.clone(), b = other_tree.tree.clone();
ThreeBSP.prototype.subtract = function (other_tree) {
var a = this.tree.clone(), b = other_tree.tree.clone();
a.invert();
a.clipTo(b);
b.clipTo(a);
@@ -91,26 +69,26 @@ class ThreeBSP {
b.invert();
a.build(b.allPolygons());
a.invert();
let bsp = new ThreeBSP(a);
var bsp = new ThreeBSP(a);
bsp.matrix = this.matrix;
return bsp;
}
};
//结合
union(other_tree) {
let a = this.tree.clone(), b = other_tree.tree.clone();
ThreeBSP.prototype.union = function (other_tree) {
var a = this.tree.clone(), b = other_tree.tree.clone();
a.clipTo(b);
b.clipTo(a);
b.invert();
b.clipTo(a);
b.invert();
a.build(b.allPolygons());
let bsp = new ThreeBSP(a);
var bsp = new ThreeBSP(a);
bsp.matrix = this.matrix;
return bsp;
}
};
//相交
intersect(other_tree) {
let a = this.tree.clone(), b = other_tree.tree.clone();
ThreeBSP.prototype.intersect = function (other_tree) {
var a = this.tree.clone(), b = other_tree.tree.clone();
a.invert();
b.clipTo(a);
b.invert();
@@ -118,12 +96,12 @@ class ThreeBSP {
b.clipTo(a);
a.build(b.allPolygons());
a.invert();
let bsp = new ThreeBSP(a);
var bsp = new ThreeBSP(a);
bsp.matrix = this.matrix;
return bsp;
}
toGeometry() {
let i, j, matrix = new THREE.Matrix4().getInverse(this.matrix), geometry = new THREE.Geometry(), polygons = this.tree.allPolygons(), polygon_count = polygons.length, polygon, polygon_vertice_count, vertice_dict = {}, vertex_idx_a, vertex_idx_b, vertex_idx_c, vertex, face, verticeUvs;
};
ThreeBSP.prototype.toGeometry = function () {
var i, j, matrix = new THREE.Matrix4().getInverse(this.matrix), geometry = new THREE.Geometry(), polygons = this.tree.allPolygons(), polygon_count = polygons.length, polygon, polygon_vertice_count, vertice_dict = {}, vertex_idx_a, vertex_idx_b, vertex_idx_c, vertex, face, verticeUvs;
for (i = 0; i < polygon_count; i++) {
polygon = polygons[i];
polygon_vertice_count = polygon.vertices.length;
@@ -168,18 +146,19 @@ class ThreeBSP {
}
}
return geometry;
}
toMesh(material) {
let geometry = this.toGeometry(), mesh = new THREE.Mesh(geometry, material);
};
ThreeBSP.prototype.toMesh = function (material) {
var geometry = this.toGeometry(), mesh = new THREE.Mesh(geometry, material);
mesh.position.setFromMatrixPosition(this.matrix);
mesh.rotation.setFromRotationMatrix(this.matrix);
return mesh;
}
}
};
return ThreeBSP;
}());
exports.ThreeBSP = ThreeBSP;
//多边形
class Polygon {
constructor(vertices, normal, w) {
var Polygon = /** @class */ (function () {
function Polygon(vertices, normal, w) {
if (!(vertices instanceof Array)) {
vertices = [];
}
@@ -191,22 +170,22 @@ class Polygon {
this.normal = this.w = undefined;
}
}
calculateProperties() {
let a = this.vertices[0], b = this.vertices[1], c = this.vertices[2];
Polygon.prototype.calculateProperties = function () {
var a = this.vertices[0], b = this.vertices[1], c = this.vertices[2];
this.normal = b.clone().subtract(a).cross(c.clone().subtract(a)).normalize();
this.w = this.normal.clone().dot(a);
return this;
}
clone() {
let i, vertice_count, polygon = new Polygon();
};
Polygon.prototype.clone = function () {
var i, vertice_count, polygon = new Polygon();
for (i = 0, vertice_count = this.vertices.length; i < vertice_count; i++) {
polygon.vertices.push(this.vertices[i].clone());
}
polygon.calculateProperties();
return polygon;
}
flip() {
let i, vertices = [];
};
Polygon.prototype.flip = function () {
var i, vertices = [];
this.normal.multiplyScalar(-1);
this.w *= -1;
for (i = this.vertices.length - 1; i >= 0; i--) {
@@ -214,10 +193,10 @@ class Polygon {
}
this.vertices = vertices;
return this;
}
};
//划分?
classifyVertex(vertex) {
let side_value = this.normal.dot(vertex) - this.w;
Polygon.prototype.classifyVertex = function (vertex) {
var side_value = this.normal.dot(vertex) - this.w;
if (side_value < -EPSILON) {
return BACK;
}
@@ -227,10 +206,10 @@ class Polygon {
else {
return COPLANAR;
}
}
};
//划分边?
classifySide(polygon) {
let i, vertex, classification, num_positive = 0, num_negative = 0, vertice_count = polygon.vertices.length;
Polygon.prototype.classifySide = function (polygon) {
var i, vertex, classification, num_positive = 0, num_negative = 0, vertice_count = polygon.vertices.length;
for (i = 0; i < vertice_count; i++) {
vertex = polygon.vertices[i];
classification = this.classifyVertex(vertex);
@@ -253,10 +232,10 @@ class Polygon {
else {
return SPANNING;
}
}
};
//分解 分离 区域?
splitPolygon(polygon, coplanar_front, coplanar_back, front, back) {
let classification = this.classifySide(polygon);
Polygon.prototype.splitPolygon = function (polygon, coplanar_front, coplanar_back, front, back) {
var classification = this.classifySide(polygon);
if (classification === COPLANAR) {
(this.normal.dot(polygon.normal) > 0 ? coplanar_front : coplanar_back).push(polygon);
}
@@ -267,7 +246,7 @@ class Polygon {
back.push(polygon);
}
else {
let vertice_count, i, j, ti, tj, vi, vj, t, v, f = [], b = [];
var vertice_count = void 0, i = void 0, j = void 0, ti = void 0, tj = void 0, vi = void 0, vj = void 0, t = void 0, v = void 0, f = [], b = [];
for (i = 0, vertice_count = polygon.vertices.length; i < vertice_count; i++) {
j = (i + 1) % vertice_count;
vi = polygon.vertices[i];
@@ -290,82 +269,84 @@ class Polygon {
if (b.length >= 3)
back.push(new Polygon(b).calculateProperties());
}
}
}
};
return Polygon;
}());
exports.Polygon = Polygon;
class Vertex {
constructor(x, y, z, normal, uv) {
var Vertex = /** @class */ (function () {
function Vertex(x, y, z, normal, uv) {
this.x = x;
this.y = y;
this.z = z;
this.normal = normal || new THREE.Vector3();
this.uv = uv || new THREE.Vector2();
}
clone() {
Vertex.prototype.clone = function () {
return new Vertex(this.x, this.y, this.z, this.normal.clone(), this.uv.clone());
}
add(vertex) {
};
Vertex.prototype.add = function (vertex) {
this.x += vertex.x;
this.y += vertex.y;
this.z += vertex.z;
return this;
}
subtract(vertex) {
};
Vertex.prototype.subtract = function (vertex) {
this.x -= vertex.x;
this.y -= vertex.y;
this.z -= vertex.z;
return this;
}
multiplyScalar(scalar) {
};
Vertex.prototype.multiplyScalar = function (scalar) {
this.x *= scalar;
this.y *= scalar;
this.z *= scalar;
return this;
}
};
//×乘
cross(vertex) {
let x = this.x, y = this.y, z = this.z;
Vertex.prototype.cross = function (vertex) {
var x = this.x, y = this.y, z = this.z;
this.x = y * vertex.z - z * vertex.y;
this.y = z * vertex.x - x * vertex.z;
this.z = x * vertex.y - y * vertex.x;
return this;
}
normalize() {
let length = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
};
Vertex.prototype.normalize = function () {
var length = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
this.x /= length;
this.y /= length;
this.z /= length;
return this;
}
};
//点乘
dot(vertex) {
Vertex.prototype.dot = function (vertex) {
return this.x * vertex.x + this.y * vertex.y + this.z * vertex.z;
}
};
//线性插值
lerp(a, t) {
Vertex.prototype.lerp = function (a, t) {
this.add(a.clone().subtract(this).multiplyScalar(t));
this.normal.add(a.normal.clone().sub(this.normal).multiplyScalar(t));
this.uv.add(a.uv.clone().sub(this.uv).multiplyScalar(t));
return this;
}
};
//插值
interpolate(other, t) {
Vertex.prototype.interpolate = function (other, t) {
return this.clone().lerp(other, t);
}
applyMatrix4(m) {
};
Vertex.prototype.applyMatrix4 = function (m) {
// input: THREE.Matrix4 affine matrix
let x = this.x, y = this.y, z = this.z;
let e = m.elements;
var x = this.x, y = this.y, z = this.z;
var e = m.elements;
this.x = e[0] * x + e[4] * y + e[8] * z + e[12];
this.y = e[1] * x + e[5] * y + e[9] * z + e[13];
this.z = e[2] * x + e[6] * y + e[10] * z + e[14];
return this;
}
}
};
return Vertex;
}());
exports.Vertex = Vertex;
class Node {
constructor(polygons) {
let i, polygon_count, front = [], back = [];
var Node = /** @class */ (function () {
function Node(polygons) {
var i, polygon_count, front = [], back = [];
this.polygons = [];
this.front = this.back = undefined;
if (!(polygons instanceof Array) || polygons.length === 0)
@@ -382,8 +363,8 @@ class Node {
}
}
//是凸的? 凸包?
isConvex(polygons) {
let i, j;
Node.prototype.isConvex = function (polygons) {
var i, j;
for (i = 0; i < polygons.length; i++) {
for (j = 0; j < polygons.length; j++) {
if (i !== j && polygons[i].classifySide(polygons[j]) !== BACK) {
@@ -392,9 +373,9 @@ class Node {
}
}
return true;
}
build(polygons) {
let i, polygon_count, front = [], back = [];
};
Node.prototype.build = function (polygons) {
var i, polygon_count, front = [], back = [];
if (!this.divider) {
this.divider = polygons[0].clone();
}
@@ -411,17 +392,17 @@ class Node {
this.back = new Node();
this.back.build(back);
}
}
allPolygons() {
let polygons = this.polygons.slice();
};
Node.prototype.allPolygons = function () {
var polygons = this.polygons.slice();
if (this.front)
polygons = polygons.concat(this.front.allPolygons());
if (this.back)
polygons = polygons.concat(this.back.allPolygons());
return polygons;
}
clone() {
let node = new Node();
};
Node.prototype.clone = function () {
var node = new Node();
node.divider = this.divider.clone();
node.polygons = this.polygons.map(function (polygon) {
return polygon.clone();
@@ -429,10 +410,10 @@ class Node {
node.front = this.front && this.front.clone();
node.back = this.back && this.back.clone();
return node;
}
};
//反转
invert() {
let i, polygon_count, temp;
Node.prototype.invert = function () {
var i, polygon_count, temp;
for (i = 0, polygon_count = this.polygons.length; i < polygon_count; i++) {
this.polygons[i].flip();
}
@@ -445,10 +426,10 @@ class Node {
this.front = this.back;
this.back = temp;
return this;
}
};
//
clipPolygons(polygons) {
let i, polygon_count, front, back;
Node.prototype.clipPolygons = function (polygons) {
var i, polygon_count, front, back;
if (!this.divider)
return polygons.slice();
front = [];
@@ -463,14 +444,15 @@ class Node {
else
back = [];
return front.concat(back);
}
clipTo(node) {
};
Node.prototype.clipTo = function (node) {
this.polygons = node.clipPolygons(this.polygons);
if (this.front)
this.front.clipTo(node);
if (this.back)
this.back.clipTo(node);
}
}
};
return Node;
}());
exports.Node = Node;
//# sourceMappingURL=ThreeCSG.js.map

File diff suppressed because one or more lines are too long

5
dist/Utils.d.ts vendored
View File

@@ -1,2 +1,5 @@
import { Viewer } from ".";
export declare function LoadBoard(view: Viewer, data: any[]): void;
export declare function LoadBoard(view: Viewer, data: any[], clear?: boolean): {
blockMeshMap: Map<number, number>;
meshBlockMap: Map<number, number>;
};

34
dist/Utils.js vendored
View File

@@ -1,23 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require(".");
function LoadBoard(view, data) {
view.m_Scene.children.forEach(obj => {
let geo = obj["geometry"];
if (geo)
geo.dispose();
});
var _1 = require(".");
function dispose(m) {
//@ts-ignore
if (m.geometry)
//@ts-ignore
m.geometry.dispose();
m.children.forEach(function (o) { return dispose(o); });
}
function LoadBoard(view, data, clear) {
var _a, _b, _c;
if (clear === void 0) { clear = true; }
if (clear) {
dispose(view.m_Scene);
view.m_Scene.children.length = 0;
}
if (data.length === 0)
return;
//加板
let { meshs, edgesa } = _1.createTemplateBoard(data);
var _d = _1.createTemplateBoard(data), meshs = _d.meshs, edgesa = _d.edgesa, relations = _d.relations;
//加标注
let dims = _1.DrawDimension(meshs);
view.m_Scene.add(...meshs);
view.m_Scene.add(...edgesa);
view.m_Scene.add(...dims);
var dims = _1.DrawDimension(meshs);
(_a = view.m_Scene).add.apply(_a, meshs);
(_b = view.m_Scene).add.apply(_b, edgesa);
(_c = view.m_Scene).add.apply(_c, dims);
view.ViewToSwiso();
view.ZoomAll();
view.Zoom(1.1);
return relations;
}
exports.LoadBoard = LoadBoard;
//# sourceMappingURL=Utils.js.map

2
dist/Utils.js.map vendored
View File

@@ -1 +1 @@
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../src/Utils.ts"],"names":[],"mappings":";;AAAA,wBAA2E;AAG3E,mBAA0B,IAAY,EAAE,IAAW;IAE/C,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAEhC,IAAI,GAAG,GAAG,GAAG,CAAC,UAAU,CAAa,CAAC;QACtC,IAAI,GAAG;YAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAA;IACF,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAEjC,IAAI;IACJ,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,sBAAmB,CAAC,IAAI,CAAC,CAAC;IAClD,KAAK;IACL,IAAI,IAAI,GAAG,gBAAa,CAAC,KAA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CAAC,OAAO,CAAA,CAAC,GAAG,WAAI,MAAM,EAAE;IAC5B,CAAA,KAAA,IAAI,CAAC,OAAO,CAAA,CAAC,GAAG,WAAI,IAAI,EAAE;IAE1B,IAAI,CAAC,WAAW,EAAE,CAAC;IACnB,IAAI,CAAC,OAAO,EAAE,CAAC;IACf,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEf,OAAO,SAAS,CAAC;AACrB,CAAC;AAxBD,8BAwBC"}

1
dist/ViewSrc/index.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
export {};

70
dist/ViewSrc/index.js vendored Normal file
View File

@@ -0,0 +1,70 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// import { Color, Face3, MeshBasicMaterial, Object3D, Vector2, Vector3 } from "three";
// import "./style.css";
var three_1 = require("three");
var CameraControls_1 = require("../CameraControls");
var data_1 = require("../data");
var GeUtils_1 = require("../GeUtils");
var Utils_1 = require("../Utils");
var Viewer_1 = require("../Viewer");
var btn = document.createElement("button");
btn.innerHTML = "载入";
document.body.appendChild(btn);
var btn2 = document.createElement("button");
btn2.innerHTML = "清理";
document.body.appendChild(btn2);
var btn3 = document.createElement("button");
btn3.innerHTML = "爆炸图";
document.body.appendChild(btn3);
var el = document.createElement("canvas");
el.style.width = "80%";
el.style.height = "80%";
document.body.appendChild(el);
var view = new Viewer_1.Viewer(el);
//修改这个顺序 改变1 2 3 个触摸点时的触发状态.
view.m_CameraCtrl.m_TouthTypeList = [CameraControls_1.CameraControlState.Rotate, CameraControls_1.CameraControlState.Scale, CameraControls_1.CameraControlState.Pan];
//例如,修改单指滑动为平移.
view.m_CameraCtrl.m_TouthTypeList = [CameraControls_1.CameraControlState.Pan, CameraControls_1.CameraControlState.Scale, CameraControls_1.CameraControlState.Rotate];
//加载
btn.onclick = function () {
console.time();
for (var i = 0; i < 1; i++)
Utils_1.LoadBoard(view, data_1.data);
console.timeEnd();
};
btn2.onclick = function () {
// LoadBoard(view, []);
};
btn3.onclick = function () {
var box = GeUtils_1.GetBox(view.m_Scene);
var cen = box.getCenter(new three_1.Vector3());
var m = [];
for (var _i = 0, _a = view.m_Scene.children; _i < _a.length; _i++) {
var obj = _a[_i];
if (obj.userData && obj.userData instanceof three_1.Vector3) {
var objCen = GeUtils_1.GetBox(obj).getCenter(new three_1.Vector3());
var v = objCen.clone().sub(cen);
var zv = obj.userData;
if (zv instanceof three_1.Vector3) {
var d = zv.dot(v);
// m.set(obj, zv.clone().multiplyScalar(d));
m.push([obj, zv.clone().multiplyScalar(d)]);
}
}
}
var count = 0;
var t = setInterval(function () {
for (var _i = 0, m_1 = m; _i < m_1.length; _i++) {
var _a = m_1[_i], o = _a[0], v = _a[1];
o.position.add(v.clone().multiplyScalar(1.5 / 120));
o.updateMatrix();
}
view.ZoomAll();
view.m_bNeedUpdate = true;
count++;
if (count === 60)
clearInterval(t);
}, 16);
};
//# sourceMappingURL=index.js.map

1
dist/ViewSrc/index.js.map vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ViewSrc/index.ts"],"names":[],"mappings":";;AAAA,uFAAuF;AACvF,wBAAwB;AACxB,+BAAgC;AAChC,oDAAuD;AACvD,gCAA+B;AAC/B,sCAAoC;AACpC,kCAAqC;AACrC,oCAAmC;AAEnC,IAAI,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AAC3C,GAAG,CAAC,SAAS,GAAG,IAAI,CAAA;AACpB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;AAE/B,IAAI,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AAC5C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;AACrB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AAEhC,IAAI,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AAC5C,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AA"}

26
dist/Viewer.d.ts vendored
View File

@@ -1,32 +1,42 @@
import * as THREE from "three";
import { Mesh, Scene, Vector3, WebGLRenderer } from "three";
import { CameraControls } from ".";
import { CameraUpdate } from "./CameraUpdate";
export declare class Viewer {
m_LookTarget: any;
m_Camera: CameraUpdate;
m_CameraCtrl: CameraControls;
m_bNeedUpdate: boolean;
m_Render: THREE.WebGLRenderer;
m_Render: WebGLRenderer;
m_DomEl: HTMLElement;
_Height: number;
_Width: number;
m_Scene: THREE.Scene;
m_Scene: Scene;
/**
*
* @param {HTMLElement} canvasContainer 可以传入一个div或者一个画布
* @memberof Viewer
*/
constructor(canvasContainer: HTMLElement);
initRender(canvasContainer: HTMLElement): void;
OnSize: (width?: any, height?: any) => void;
StartRender: () => void;
Render(): void;
ScreenToWorld(pt: THREE.Vector3, planVec?: THREE.Vector3): void;
WorldToScreen(pt: THREE.Vector3): void;
ScreenToWorld(pt: Vector3, planVec?: Vector3): void;
WorldToScreen(pt: Vector3): void;
/**
* 更新视角观测目标(物体中心)
*
* @memberof Viewer
*/
UpdateLockTarget(): void;
Rotate(mouseMove: THREE.Vector3): void;
Pan(mouseMove: THREE.Vector3): void;
Zoom(scale: number, center?: THREE.Vector3): void;
Rotate(mouseMove: Vector3): void;
Pan(mouseMove: Vector3): void;
Zoom(scale: number, center?: Vector3): void;
ZoomAll(): void;
ViewToTop(): void;
ViewToFront(): void;
ViewToSwiso(): void;
oldMesh: Mesh;
SelectByPoint(x: number, y: number): void;
SelectBlock(blockMeshMap: Map<number, number>, dataID: number): void;
}

184
dist/Viewer.js vendored
View File

@@ -1,72 +1,74 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three");
const CameraUpdate_1 = require("./CameraUpdate");
const GeUtils_1 = require("./GeUtils");
const PlaneExt_1 = require("./PlaneExt");
const _1 = require(".");
const three_1 = require("three");
class Viewer {
//构造
constructor(canvasContainer) {
var three_1 = require("three");
var _1 = require(".");
var CameraUpdate_1 = require("./CameraUpdate");
var ColorPalette_1 = require("./ColorPalette");
var GeUtils_1 = require("./GeUtils");
var PlaneExt_1 = require("./PlaneExt");
var Viewer = /** @class */ (function () {
/**
*
* @param {HTMLElement} canvasContainer 可以传入一个div或者一个画布
* @memberof Viewer
*/
function Viewer(canvasContainer) {
var _this = this;
this.m_Camera = new CameraUpdate_1.CameraUpdate();
this.m_bNeedUpdate = true;
this.m_Scene = new THREE.Scene();
this.OnSize = (width, height) => {
this._Width = width ? width : this.m_DomEl.scrollWidth;
this._Height = height ? height : this.m_DomEl.scrollHeight;
this.m_Scene = new three_1.Scene();
this.OnSize = function (width, height) {
_this._Width = width ? width : _this.m_DomEl.clientWidth;
_this._Height = height ? height : _this.m_DomEl.clientHeight;
//校验.成为2的倍数 避免外轮廓错误.
if (this._Width % 2 == 1)
this._Width -= 1;
if (this._Height % 2 == 1)
this._Height -= 1;
this.m_Render.setSize(this._Width, this._Height);
this.m_Camera.SetSize(this._Width, this._Height);
if (_this._Width % 2 == 1)
_this._Width -= 1;
if (_this._Height % 2 == 1)
_this._Height -= 1;
_this.m_Render.setSize(_this._Width, _this._Height);
_this.m_Camera.SetSize(_this._Width, _this._Height);
};
this.StartRender = () => {
requestAnimationFrame(this.StartRender);
if (this.m_Scene != null && this.m_bNeedUpdate) {
this.Render();
this.m_bNeedUpdate = false;
this.StartRender = function () {
requestAnimationFrame(_this.StartRender);
if (_this.m_Scene != null && _this.m_bNeedUpdate) {
_this.Render();
_this.m_bNeedUpdate = false;
}
};
this.m_DomEl = canvasContainer;
this.initRender(canvasContainer);
this.OnSize();
this.StartRender();
new _1.CameraControls(this);
window.addEventListener("resize", () => {
this.OnSize();
this.m_CameraCtrl = new _1.CameraControls(this);
window.addEventListener("resize", function () {
_this.OnSize();
});
//选中
let selectMaterial = new three_1.MeshBasicMaterial({ color: new three_1.Color(0.1, 0.5, 0.5) });
let oldMesh;
this.m_Render.domElement.addEventListener("mousemove", (e) => {
let mesh = _1.PointPick(this, e.offsetX, e.offsetY);
if (oldMesh)
oldMesh.material = _1.boardMaterial;
if (mesh) {
oldMesh = mesh;
mesh.material = selectMaterial;
this.m_bNeedUpdate = true;
}
this.m_Render.domElement.addEventListener("mousemove", function (e) {
_this.SelectByPoint(e.offsetX, e.offsetY);
});
}
//初始化render
initRender(canvasContainer) {
this.m_Render = new THREE.WebGLRenderer({
Viewer.prototype.initRender = function (canvasContainer) {
var params = {
antialias: true,
precision: "highp",
alpha: true,
});
alpha: true //alpha:true/false是否可以设置背景色透明
};
if (canvasContainer instanceof HTMLCanvasElement) {
params.canvas = canvasContainer;
this.m_Render = new three_1.WebGLRenderer(params);
}
else {
this.m_Render = new three_1.WebGLRenderer(params);
//加到画布
canvasContainer.appendChild(this.m_Render.domElement);
}
this.m_Render.autoClear = true;
//如果设置那么它希望所有的纹理和颜色都是预乘的伽玛。默认值为false。
// this.m_Render.gammaInput = true;
// this.m_Render.gammaOutput = true;
// this.m_Render.shadowMap.enabled = true;
// this.m_Render.toneMapping = THREE.ReinhardToneMapping;
// this.m_Render.toneMapping = ReinhardToneMapping;
//设置设备像素比。 这通常用于HiDPI设备以防止模糊输出画布。
this.m_Render.setPixelRatio(window.devicePixelRatio);
this.m_Render.physicallyCorrectLights = true;
@@ -74,69 +76,97 @@ class Viewer {
//设置它的背景色为黑色
this.m_Render.setClearColor(0xffffff, 1);
this.OnSize();
}
Render() {
};
Viewer.prototype.Render = function () {
this.m_Render.render(this.m_Scene, this.m_Camera.Camera);
}
ScreenToWorld(pt, planVec) {
};
Viewer.prototype.ScreenToWorld = function (pt, planVec) {
//变换和求交点
let plan = new PlaneExt_1.PlaneExt(planVec || new THREE.Vector3(0, 0, 1));
let raycaster = new THREE.Raycaster();
var plan = new PlaneExt_1.PlaneExt(planVec || new three_1.Vector3(0, 0, 1));
var raycaster = new three_1.Raycaster();
// 射线从相机射线向屏幕点位置
raycaster.setFromCamera({
x: (pt.x / this._Width) * 2 - 1,
y: -(pt.y / this._Height) * 2 + 1
}, this.m_Camera.Camera);
plan.intersectRay(raycaster.ray, pt, true);
}
WorldToScreen(pt) {
let widthHalf = this._Width * 0.5;
let heightHalf = this._Height * 0.5;
};
Viewer.prototype.WorldToScreen = function (pt) {
var widthHalf = this._Width * 0.5;
var heightHalf = this._Height * 0.5;
pt.project(this.m_Camera.Camera);
pt.x = (pt.x * widthHalf) + widthHalf;
pt.y = -(pt.y * heightHalf) + heightHalf;
}
};
/**
* 更新视角观测目标(物体中心)
*
* @memberof Viewer
*/
UpdateLockTarget() {
let renderList = this.m_Render.renderLists.get(this.m_Scene, this.m_Camera.Camera);
let box = GeUtils_1.GetBoxArr(renderList.opaque.map(o => o.object));
Viewer.prototype.UpdateLockTarget = function () {
var renderList = this.m_Render.renderLists.get(this.m_Scene, this.m_Camera.Camera);
var box = GeUtils_1.GetBoxArr(renderList.opaque.map(function (o) { return o.object; }));
if (box)
this.m_LookTarget = box.getCenter(new THREE.Vector3());
this.m_LookTarget = box.getCenter(new three_1.Vector3());
else
this.m_LookTarget = GeUtils_1.cZeroVec;
}
Rotate(mouseMove) {
};
Viewer.prototype.Rotate = function (mouseMove) {
this.m_Camera.Rotate(mouseMove, this.m_LookTarget);
this.m_bNeedUpdate = true;
}
Pan(mouseMove) {
};
Viewer.prototype.Pan = function (mouseMove) {
this.m_Camera.Pan(mouseMove);
this.m_bNeedUpdate = true;
}
Zoom(scale, center) {
};
Viewer.prototype.Zoom = function (scale, center) {
this.m_Camera.Zoom(scale, center);
this.m_bNeedUpdate = true;
}
ZoomAll() {
};
Viewer.prototype.ZoomAll = function () {
this.m_Camera.ZoomExtensBox3(GeUtils_1.GetBox(this.m_Scene, true));
this.m_bNeedUpdate = true;
}
ViewToTop() {
this.m_Camera.LookAt(new THREE.Vector3(0, 0, -1));
};
Viewer.prototype.ViewToTop = function () {
this.m_Camera.LookAt(new three_1.Vector3(0, 0, -1));
this.m_bNeedUpdate = true;
}
ViewToFront() {
this.m_Camera.LookAt(new THREE.Vector3(0, 1, 0));
};
Viewer.prototype.ViewToFront = function () {
this.m_Camera.LookAt(new three_1.Vector3(0, 1, 0));
this.m_bNeedUpdate = true;
}
ViewToSwiso() {
this.m_Camera.LookAt(new THREE.Vector3(1, 1, -1));
};
Viewer.prototype.ViewToSwiso = function () {
this.m_Camera.LookAt(new three_1.Vector3(1, 1, -1));
this.m_bNeedUpdate = true;
};
Viewer.prototype.SelectByPoint = function (x, y) {
var mesh = _1.PointPick(this, x, y);
if (this.oldMesh)
this.oldMesh.material = _1.boardMaterial;
if (mesh && mesh.material !== ColorPalette_1.ColorMaterial.GetBasicMaterial(1)) {
this.oldMesh = mesh;
mesh.material = _1.selectMaterial;
}
}
this.m_bNeedUpdate = true;
};
Viewer.prototype.SelectBlock = function (blockMeshMap, dataID) {
var _this = this;
if (blockMeshMap.has(dataID)) {
var meshId_1 = blockMeshMap.get(dataID);
if (this.oldMesh)
this.oldMesh.material = _1.boardMaterial;
this.m_Scene.children.forEach(function (obj) {
if (obj instanceof three_1.Mesh) {
if (obj.id == meshId_1) {
_this.oldMesh = obj;
obj.material = _1.selectMaterial;
_this.m_bNeedUpdate = true;
}
}
});
}
};
return Viewer;
}());
exports.Viewer = Viewer;
//# sourceMappingURL=Viewer.js.map

2
dist/Viewer.js.map vendored

File diff suppressed because one or more lines are too long

23
dist/createBoard.d.ts vendored
View File

@@ -1,22 +1,25 @@
import * as THREE from 'three';
import { Geometry, LineSegments } from 'three';
import { Geometry, LineSegments, Mesh, Shape, Vector2, Vector3 } from 'three';
export declare class Arc2d {
m_StartAn: number;
m_EndAn: number;
m_StartPoint: THREE.Vector2;
m_EndPoint: THREE.Vector2;
m_Center: THREE.Vector2;
m_StartPoint: Vector2;
m_EndPoint: Vector2;
m_Center: Vector2;
m_Radius: number;
constructor(p1: THREE.Vector2, p2: THREE.Vector2, bul: number);
constructor(p1: Vector2, p2: Vector2, bul: number);
}
export declare function createPath(pts: THREE.Vector2[], buls: number[], shapeOut?: THREE.Shape): THREE.Shape;
export declare function getVec(data: object): THREE.Vector3;
export declare function createPath(pts: Vector2[], buls: number[], shapeOut?: Shape): Shape;
export declare function getVec(data: object): Vector3;
export declare function createBoard(boardData: object): {
mesh: THREE.Mesh;
edges: THREE.LineSegments[];
mesh: Mesh;
edges: (Mesh | LineSegments)[];
};
export declare function createTemplateBoard(brDataList: any[]): {
meshs: any[];
edgesa: any[];
relations: {
blockMeshMap: Map<number, number>;
meshBlockMap: Map<number, number>;
};
};
export declare function createEdge(geo: Geometry): LineSegments;

176
dist/createBoard.js vendored
View File

@@ -1,23 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three");
const three_1 = require("three");
const GeUtils_1 = require("./GeUtils");
const Material_1 = require("./Material");
const RotateUV_1 = require("./RotateUV");
const ThreeCSG_1 = require("./ThreeCSG");
var three_1 = require("three");
var ColorPalette_1 = require("./ColorPalette");
var GeUtils_1 = require("./GeUtils");
var Material_1 = require("./Material");
var RotateUV_1 = require("./RotateUV");
var ThreeCSG_1 = require("./ThreeCSG");
//解析二维圆弧类.
class Arc2d {
constructor(p1, p2, bul) {
var Arc2d = /** @class */ (function () {
function Arc2d(p1, p2, bul) {
this.m_StartPoint = p1.clone();
this.m_EndPoint = p2.clone();
let vec = p2.clone().sub(p1);
let len = vec.length();
let an = vec.angle();
var vec = p2.clone().sub(p1);
var len = vec.length();
var an = vec.angle();
this.m_Radius = len / Math.sin(2 * Math.atan(bul)) / 2;
let allAngle = Math.atan(bul) * 4;
let delDis = bul * len / 2;
let toDis = this.m_Radius - delDis;
var allAngle = Math.atan(bul) * 4;
var delDis = bul * len / 2;
var toDis = this.m_Radius - delDis;
an += Math.PI * 0.5;
this.m_Center = p1.clone().add(p2);
this.m_Center.multiplyScalar(0.5);
@@ -30,27 +30,28 @@ class Arc2d {
this.m_EndAn -= Math.PI;
}
}
}
return Arc2d;
}());
exports.Arc2d = Arc2d;
//创建轮廓 通过点表和凸度
function createPath(pts, buls, shapeOut) {
let shape = shapeOut || new THREE.Shape();
var shape = shapeOut || new three_1.Shape();
if (pts.length === 0)
return shape;
let firstPt = pts[0];
var firstPt = pts[0];
shape.moveTo(firstPt.x, firstPt.y);
for (let i = 0; i < pts.length - 1; i++) {
let nextPt = pts[i + 1];
for (var i = 0; i < pts.length - 1; i++) {
var nextPt = pts[i + 1];
if (buls[i] == 0) {
shape.lineTo(nextPt.x, nextPt.y);
}
else {
let pt = pts[i];
var pt = pts[i];
//参考
//http://www.dorodnic.com/blog/tag/three-js/ 绘制一个齿轮
//https://www.kirupa.com/html5/drawing_circles_canvas.htm //html5
let arc2 = new Arc2d(pt, nextPt, buls[i]);
let cen = arc2.m_Center;
var arc2 = new Arc2d(pt, nextPt, buls[i]);
var cen = arc2.m_Center;
shape.absarc(cen.x, cen.y, arc2.m_Radius, arc2.m_StartAn, arc2.m_EndAn, buls[i] < 0);
}
}
@@ -58,86 +59,129 @@ function createPath(pts, buls, shapeOut) {
}
exports.createPath = createPath;
function getVec(data) {
return new THREE.Vector3(data["x"], data["y"], data["z"]);
return new three_1.Vector3(data["x"], data["y"], data["z"]);
}
exports.getVec = getVec;
//创建板件 暂时这么写
function createBoard(boardData) {
let pts = new Array();
let buls = new Array();
let boardPts = boardData["Pts"];
let boardBuls = boardData["Buls"];
let boardHeight = boardData["H"];
let boardMat = new THREE.Matrix4();
let matInv = new THREE.Matrix4();
var _a;
var pts = [];
var buls = [];
var boardPts = boardData["Pts"];
var boardBuls = boardData["Buls"];
var boardHeight = boardData["H"];
var boardMat = new three_1.Matrix4();
var matInv = new three_1.Matrix4();
//InitBoardMat
{
let xD = getVec(boardData["XVec"]);
let yD = getVec(boardData["YVec"]);
let ZD = getVec(boardData["ZVec"]);
let pBase = getVec(boardData["BasePoint"]);
var xD = getVec(boardData["XVec"]);
var yD = getVec(boardData["YVec"]);
var ZD = getVec(boardData["ZVec"]);
var pBase = getVec(boardData["BasePoint"]);
boardMat.makeBasis(xD, yD, ZD);
boardMat.setPosition(pBase);
matInv.getInverse(boardMat, true);
}
matInv.getInverse(boardMat);
if (boardPts && boardPts.length !== 0)
for (let i = 0; i < boardPts.length; i++) {
let pt = getVec(boardPts[i]);
if (pt.z !== undefined)
for (var i = 0; i < boardPts.length; i++) {
var pt = getVec(boardPts[i]);
if (boardPts[i].z !== undefined)
pt.applyMatrix4(matInv);
pts.push(new THREE.Vector2(pt.x, pt.y));
pts.push(new three_1.Vector2(pt.x, pt.y));
buls.push(boardBuls[i]);
}
else {
let length = boardData["L"];
let width = boardData["W"];
let height = boardData["H"];
pts.push(new three_1.Vector2(0, 0), new three_1.Vector2(width, 0), new three_1.Vector2(width, length), new three_1.Vector2(0, length), new three_1.Vector2(0, 0));
var length_1 = boardData["L"];
var width = boardData["W"];
var height = boardData["H"];
pts.push(new three_1.Vector2(0, 0), new three_1.Vector2(width, 0), new three_1.Vector2(width, length_1), new three_1.Vector2(0, length_1), new three_1.Vector2(0, 0));
buls.push(0, 0, 0, 0, 0);
}
let sp = createPath(pts, buls);
let extrudeSettings = {
var sp = createPath(pts, buls);
var extrudeSettings = {
steps: 1,
bevelEnabled: false,
amount: boardHeight
depth: boardHeight
};
let ext = new THREE.ExtrudeGeometry(sp, extrudeSettings);
var ext = new three_1.ExtrudeGeometry(sp, extrudeSettings);
ext.computeBoundingSphere();
ext.computeBoundingBox();
ext.translate(0, 0, -boardHeight);
ext.applyMatrix(boardMat);
ext.applyMatrix4(boardMat);
if (!GeUtils_1.equalv3(xD.clone().cross(yD), ZD)) {
for (var _i = 0, _b = ext.faces; _i < _b.length; _i++) {
var f = _b[_i];
_a = [f.c, f.a], f.a = _a[0], f.c = _a[1];
}
}
//外边.
let edges = [createEdge(ext)];
var edges = [createEdge(ext)];
//差集
if (boardData["SubBoardLocal"].length > 0) {
let subBoardList = boardData["SubBoardLocal"].map(d => createBoard(d));
let thisCsg = new ThreeCSG_1.ThreeBSP(ext);
for (let br of subBoardList) {
edges.push(...br.edges);
let subCsg = new ThreeCSG_1.ThreeBSP(br.mesh);
if (checkObjectArray(boardData, "SubBoardLocal")
|| checkObjectArray(boardData, "Drillings")) {
var thisCsg = new ThreeCSG_1.ThreeBSP(ext);
if (boardData["SubBoardLocal"]) {
var subBoardList = boardData["SubBoardLocal"].map(function (d) { return createBoard(d); });
for (var _c = 0, subBoardList_1 = subBoardList; _c < subBoardList_1.length; _c++) {
var br = subBoardList_1[_c];
edges.push.apply(edges, br.edges);
var subCsg = new ThreeCSG_1.ThreeBSP(br.mesh);
thisCsg = thisCsg.subtract(subCsg);
}
}
if (boardData["Drillings"]) {
var dris = boardData["Drillings"];
for (var _d = 0, dris_1 = dris; _d < dris_1.length; _d++) {
var dri = dris_1[_d];
var geo = new three_1.CylinderGeometry(dri.r, dri.r, dri.h, 8);
geo.rotateX(Math.PI * 0.5);
if (dri.f === 0) //0正
geo.translate(dri.x, dri.y, -dri.h * 0.5);
else //1反
geo.translate(dri.x, dri.y, dri.h * 0.5 - boardData["H"]);
geo.applyMatrix4(boardMat);
var mesh_1 = new three_1.Mesh(geo, ColorPalette_1.ColorMaterial.GetBasicMaterial(1));
edges.push(mesh_1);
// let edge = createEdge(geo);
// edge.material = new LineBasicMaterial({ color: new Color(1, 0, 0) });
// edges.push(edge);
// let subCsg = new ThreeBSP(geo);
// thisCsg = thisCsg.subtract(subCsg);
}
}
ext = thisCsg.toGeometry();
}
if (boardData["BoardName"] === "地脚线")
RotateUV_1.RotateUVs(ext);
let mesh = new THREE.Mesh(ext, Material_1.boardMaterial);
return { mesh, edges };
var mesh = new three_1.Mesh(ext, Material_1.boardMaterial);
mesh.userData = ZD;
edges.forEach(function (e) { return e.userData = ZD; });
return { mesh: mesh, edges: edges };
}
exports.createBoard = createBoard;
function checkObjectArray(obj, key) {
return obj[key] && obj[key].length > 0;
}
function createTemplateBoard(brDataList) {
let meshs = [];
let edgesa = [];
for (let d of brDataList) {
let { mesh, edges } = createBoard(d);
var meshs = [];
var edgesa = [];
var relations = {
blockMeshMap: new Map(),
meshBlockMap: new Map()
};
for (var _i = 0, brDataList_1 = brDataList; _i < brDataList_1.length; _i++) {
var d = brDataList_1[_i];
var _a = createBoard(d), mesh = _a.mesh, edges = _a.edges;
meshs.push(mesh);
edgesa.push(...edges);
edgesa.push.apply(edgesa, edges);
if (d['DataID']) {
relations.blockMeshMap.set(d['DataID'], mesh.id);
relations.meshBlockMap.set(mesh.id, d['DataID']);
}
return { meshs, edgesa };
}
return { meshs: meshs, edgesa: edgesa, relations: relations };
}
exports.createTemplateBoard = createTemplateBoard;
function createEdge(geo) {
let edge = new THREE.EdgesGeometry(geo, 1);
var edge = new three_1.EdgesGeometry(geo, 1);
return new three_1.LineSegments(edge, Material_1.edgeMaterial);
}
exports.createEdge = createEdge;

File diff suppressed because one or more lines are too long

114
dist/data.d.ts vendored
View File

@@ -1,75 +1,75 @@
export declare var data: ({
"L": number;
"W": number;
"H": number;
"BasePoint": {
"x": number;
"y": number;
"z": number;
L: number;
W: number;
H: number;
BasePoint: {
x: number;
y: number;
z: number;
};
"XVec": {
"x": number;
"y": number;
"z": number;
XVec: {
x: number;
y: number;
z: number;
};
"YVec": {
"x": number;
"y": number;
"z": number;
YVec: {
x: number;
y: number;
z: number;
};
"ZVec": {
"x": number;
"y": number;
"z": number;
ZVec: {
x: number;
y: number;
z: number;
};
"Pts": {
"x": number;
"y": number;
"z": number;
Pts: {
x: number;
y: number;
z: number;
}[];
"Buls": number[];
"SubBoardLocal": any[];
"SubBoardAssoc": any[];
Buls: number[];
SubBoardLocal: any[];
SubBoardAssoc: any[];
MaterialId?: undefined;
Handle?: undefined;
CabName?: undefined;
BoardName?: undefined;
Grain?: undefined;
} | {
"L": number;
"W": number;
"H": number;
"MaterialId": string;
"BasePoint": {
"x": number;
"y": number;
"z": number;
L: number;
W: number;
H: number;
MaterialId: string;
BasePoint: {
x: number;
y: number;
z: number;
};
"XVec": {
"x": number;
"y": number;
"z": number;
XVec: {
x: number;
y: number;
z: number;
};
"YVec": {
"x": number;
"y": number;
"z": number;
YVec: {
x: number;
y: number;
z: number;
};
"ZVec": {
"x": number;
"y": number;
"z": number;
ZVec: {
x: number;
y: number;
z: number;
};
"Handle": string;
"CabName": string;
"BoardName": string;
"Grain": number;
"Pts": {
"x": number;
"y": number;
"z": number;
Handle: string;
CabName: string;
BoardName: string;
Grain: number;
Pts: {
x: number;
y: number;
z: number;
}[];
"Buls": number[];
"SubBoardLocal": any[];
"SubBoardAssoc": any[];
Buls: number[];
SubBoardLocal: any[];
SubBoardAssoc: any[];
})[];

7046
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,20 +1,46 @@
{
"name": "cadview",
"version": "1.0.3",
"version": "1.2.5",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "src/index.ts",
"private": true,
"scripts": {
"build": "tsc"
"t": "tsc --noEmit -w",
"build": "tsc",
"umd": "webpack --config ./config/webpack.umd.ts",
"dev": "webpack-dev-server --config ./config/webpack.view.ts"
},
"repository": {
"type": "git",
"url": "http://git.cf/cx/CADViewComponent.git"
},
"author": "cx",
"license": "ISC",
"devDependencies": {
"@types/node": "^10.1.2",
"@types/three": "^0.92.0",
"typescript": "^2.8.3"
"@types/hard-source-webpack-plugin": "^1.0.1",
"@types/node": "^13.13.4",
"@types/three": "^0.103.2",
"@types/uglifyjs-webpack-plugin": "^1.1.0",
"@types/webpack": "^4.41.12",
"@types/webpack-dev-server": "^3.10.1",
"@types/webpack-env": "^1.15.2",
"@types/webpack-merge": "^4.1.5",
"awesome-typescript-loader": "^5.2.1",
"cache-loader": "^4.1.0",
"fork-ts-checker-webpack-plugin": "^4.1.3",
"hard-source-webpack-plugin": "^0.13.1",
"html-webpack-plugin": "^4.2.1",
"ts-loader": "^7.0.2",
"ts-node": "^8.9.1",
"typescript": "^3.8.3",
"uglifyjs-webpack-plugin": "^2.2.0",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3",
"webpack-merge": "^4.2.2"
},
"dependencies": {
"three": "^0.92.0"
"three": "^0.120.1",
"wolfy87-eventemitter": "^5.2.9"
}
}

View File

@@ -4,14 +4,6 @@ import { KeyBoard, MouseKey } from './KeyEnum';
import { Vector3 } from 'three';
import { Viewer } from './Viewer';
//控制类型
enum CameraControlsEnabled
{
Rotate = 1,
Zoom = 2,
Pan = 4,
}
//相机控制状态
export enum CameraControlState
{
@@ -64,7 +56,6 @@ export class CameraControls
}
/**
* 窗体失去焦点时.
*
* @memberof CameraControls
*/
onBlur = () =>
@@ -141,6 +132,9 @@ export class CameraControls
this.m_State = CameraControlState.Rotate;
this.m_Viewer.UpdateLockTarget();
}
//最后一次按中键的时间
lastMiddleClickTime = 0;
//鼠标
onMouseDown = (event: MouseEvent) =>
{
@@ -161,6 +155,14 @@ export class CameraControls
}
case MouseKey.Middle:
{
let curTime = Date.now();
let t = curTime - this.lastMiddleClickTime;
this.lastMiddleClickTime = curTime;
if (t < 350)
{
this.m_Viewer.ZoomAll();
return;
}
if (this.m_KeyDown.get(KeyBoard.Control))
{
this.beginRotate();
@@ -222,7 +224,6 @@ export class CameraControls
*/
onMouseWheel = (event: WheelEvent) =>
{
event.preventDefault();
event.stopPropagation();
let pt = new THREE.Vector3(event.offsetX, event.offsetY, 0);

View File

@@ -1,5 +1,4 @@
import * as THREE from 'three';
import { Vector3 } from 'three';
import { Box3, Camera, MathUtils, OrthographicCamera, PerspectiveCamera, Vector3 } from 'three';
import { Orbit } from './Orbit';
/**
@@ -14,8 +13,8 @@ import { Orbit } from './Orbit';
*/
export class CameraUpdate
{
private m_CurCamera: THREE.Camera;
private m_CameraArray: Map<any, THREE.Camera> = new Map<any, THREE.Camera>();
private m_CurCamera: Camera;
private m_CameraArray: Map<any, Camera> = new Map<any, Camera>();
//视口的画布大小
private m_Width: number;
@@ -24,20 +23,23 @@ export class CameraUpdate
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();
m_MinViewHeight = 10;
m_MaxViewHeight = 3e4;
constructor()
{
this.m_CameraArray.set(THREE.OrthographicCamera, new THREE.OrthographicCamera(-2, 2, 2, -2,
-100000, 100000));
this.m_CameraArray.set(OrthographicCamera, new OrthographicCamera(-2, 2, 2, -2,
-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);
@@ -50,7 +52,7 @@ export class CameraUpdate
return this.m_Width / this.m_Height;
}
get Camera(): THREE.Camera
get Camera(): Camera
{
return this.m_CurCamera;
}
@@ -60,7 +62,7 @@ export class CameraUpdate
}
set ViewHeight(height)
{
this.m_ViewHeight = THREE.Math.clamp(height, 1e-8, 1e8);
this.m_ViewHeight = MathUtils.clamp(height, this.m_MinViewHeight, this.m_MaxViewHeight);
}
SetSize(width: number, height: number)
@@ -72,10 +74,10 @@ export class CameraUpdate
/**
* 平移相机.
*
* @param {THREE.Vector3} mouseMove
* @param {Vector3} mouseMove
* @memberof CameraControl
*/
Pan(mouseMove: THREE.Vector3)
Pan(mouseMove: Vector3)
{
mouseMove.y *= -1;
mouseMove.multiplyScalar(-this.m_ViewHeight / this.m_Height);
@@ -83,7 +85,7 @@ export class CameraUpdate
this.m_Target.add(mouseMove);
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.RoZ -= mouseMove.x * 0.003;
@@ -109,19 +111,19 @@ export class CameraUpdate
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;
if (scaleCenter)
if (scaleCenter && this.m_ViewHeight < this.m_MaxViewHeight)
{
this.m_Target.sub(scaleCenter);
this.m_Target.multiplyScalar(scale);
this.m_Target.add(scaleCenter);
}
}
else if (this.Camera instanceof THREE.PerspectiveCamera)
else if (this.Camera instanceof PerspectiveCamera)
{
let add = scale > 1 ? 1 : -1;
add *= this.Camera.position.distanceTo(this.m_Target) / 10;
@@ -129,9 +131,9 @@ export class CameraUpdate
}
this.Update();
}
ZoomExtensBox3(box3: THREE.Box3)
ZoomExtensBox3(box3: Box3)
{
if (!box3) return;
if (!box3 || box3.isEmpty()) return;
this.Camera.updateMatrixWorld(false);
//变换到相机坐标系
box3.applyMatrix4(this.Camera.matrixWorldInverse);
@@ -156,7 +158,7 @@ export class CameraUpdate
}
this.Update();
}
LookAt(dir: THREE.Vector3)
LookAt(dir: Vector3)
{
this.m_Orbit.UpdateRoValue(dir);
this.m_Direction.copy(dir);
@@ -178,7 +180,7 @@ export class CameraUpdate
{
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.right = this.Aspect * this.m_ViewHeight / 2;
@@ -187,10 +189,10 @@ export class CameraUpdate
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;
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));
}
@@ -206,13 +208,13 @@ export class CameraUpdate
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
{
this.m_CurCamera = this.m_CameraArray.get(THREE.OrthographicCamera);
this.m_CurCamera = this.m_CameraArray.get(OrthographicCamera);
}
this.UpdateUp();
this.Update();

View File

@@ -1,4 +1,5 @@
import * as THREE from 'three';
import { LineBasicMaterial, MeshBasicMaterial, Color } from 'three';
const ColorPalette = [
[255, 0, 0, 255], //----- 0 - lets make it red for an example
//[255, 255, 255, 255],//----- 0 - ByBlock - White
@@ -12,256 +13,256 @@ const ColorPalette = [
// [255, 0, 0, 255], //----- 7 - More red Red
// [255, 0, 0, 255], //----- 8 - More red Red
// [255, 0, 0, 255], //----- 9 - More red Red
[255, 255, 255, 255],//----- 7 - White
[255, 255, 255, 255],//----- 8
[255, 255, 255, 255],//----- 9
[255, 0, 0, 255], //----- 10
[255, 127, 127, 255],//----- 11
[165, 0, 0, 255], //----- 12
[165, 82, 82, 255], //----- 13
[127, 0, 0, 255], //----- 14
[127, 63, 63, 255], //----- 15
[76, 0, 0, 255], //----- 16
[76, 38, 38, 255], //----- 17
[38, 0, 0, 255], //----- 18
[38, 19, 19, 255], //----- 19
[255, 63, 0, 255], //----- 20
[255, 159, 127, 255],//----- 21
[165, 41, 0, 255], //----- 22
[165, 103, 82, 255], //----- 23
[127, 31, 0, 255], //----- 24
[127, 79, 63, 255], //----- 25
[76, 19, 0, 255], //----- 26
[76, 47, 38, 255], //----- 27
[38, 9, 0, 255], //----- 28
[38, 23, 19, 255], //----- 29
[255, 127, 0, 255], //----- 30
[255, 191, 127, 255],//----- 31
[165, 82, 0, 255], //----- 32
[165, 124, 82, 255], //----- 33
[127, 63, 0, 255], //----- 34
[127, 95, 63, 255], //----- 35
[76, 38, 0, 255], //----- 36
[76, 57, 38, 255], //----- 37
[38, 19, 0, 255], //----- 38
[38, 28, 19, 255], //----- 39
[255, 191, 0, 255], //----- 40
[255, 223, 127, 255],//----- 41
[165, 124, 0, 255], //----- 42
[165, 145, 82, 255], //----- 43
[127, 95, 0, 255], //----- 44
[127, 111, 63, 255], //----- 45
[76, 57, 0, 255], //----- 46
[76, 66, 38, 255], //----- 47
[38, 28, 0, 255], //----- 48
[38, 33, 19, 255], //----- 49
[255, 255, 0, 255], //----- 50
[255, 255, 127, 255],//----- 51
[165, 165, 0, 255], //----- 52
[165, 165, 82, 255], //----- 53
[127, 127, 0, 255], //----- 54
[127, 127, 63, 255], //----- 55
[76, 76, 0, 255], //----- 56
[76, 76, 38, 255], //----- 57
[38, 38, 0, 255], //----- 58
[38, 38, 19, 255], //----- 59
[191, 255, 0, 255], //----- 60
[223, 255, 127, 255],//----- 61
[124, 165, 0, 255], //----- 62
[145, 165, 82, 255], //----- 63
[95, 127, 0, 255], //----- 64
[111, 127, 63, 255], //----- 65
[57, 76, 0, 255], //----- 66
[66, 76, 38, 255], //----- 67
[28, 38, 0, 255], //----- 68
[33, 38, 19, 255], //----- 69
[127, 255, 0, 255], //----- 70
[191, 255, 127, 255],//----- 71
[82, 165, 0, 255], //----- 72
[124, 165, 82, 255], //----- 73
[63, 127, 0, 255], //----- 74
[95, 127, 63, 255], //----- 75
[38, 76, 0, 255], //----- 76
[57, 76, 38, 255], //----- 77
[19, 38, 0, 255], //----- 78
[28, 38, 19, 255], //----- 79
[63, 255, 0, 255], //----- 80
[159, 255, 127, 255],//----- 81
[41, 165, 0, 255], //----- 82
[103, 165, 82, 255], //----- 83
[31, 127, 0, 255], //----- 84
[79, 127, 63, 255], //----- 85
[19, 76, 0, 255], //----- 86
[47, 76, 38, 255], //----- 87
[9, 38, 0, 255], //----- 88
[23, 38, 19, 255], //----- 89
[0, 255, 0, 255], //----- 90
[127, 255, 127, 255],//----- 91
[0, 165, 0, 255], //----- 92
[82, 165, 82, 255], //----- 93
[0, 127, 0, 255], //----- 94
[63, 127, 63, 255], //----- 95
[0, 76, 0, 255], //----- 96
[38, 76, 38, 255], //----- 97
[0, 38, 0, 255], //----- 98
[19, 38, 19, 255], //----- 99
[0, 255, 63, 255], //----- 100
[127, 255, 159, 255],//----- 101
[0, 165, 41, 255], //----- 102
[82, 165, 103, 255], //----- 103
[0, 127, 31, 255], //----- 104
[63, 127, 79, 255], //----- 105
[0, 76, 19, 255], //----- 106
[38, 76, 47, 255], //----- 107
[0, 38, 9, 255], //----- 108
[19, 38, 23, 255], //----- 109
[0, 255, 127, 255], //----- 110
[127, 255, 191, 255],//----- 111
[0, 165, 82, 255], //----- 112
[82, 165, 124, 255], //----- 113
[0, 127, 63, 255], //----- 114
[63, 127, 95, 255], //----- 115
[0, 76, 38, 255], //----- 116
[38, 76, 57, 255], //----- 117
[0, 38, 19, 255], //----- 118
[19, 38, 28, 255], //----- 119
[0, 255, 191, 255], //----- 120
[127, 255, 223, 255],//----- 121
[0, 165, 124, 255], //----- 122
[82, 165, 145, 255], //----- 123
[0, 127, 95, 255], //----- 124
[63, 127, 111, 255], //----- 125
[0, 76, 57, 255], //----- 126
[38, 76, 66, 255], //----- 127
[0, 38, 28, 255], //----- 128
[19, 38, 33, 255], //----- 129
[0, 255, 255, 255], //----- 130
[127, 255, 255, 255],//----- 131
[0, 165, 165, 255], //----- 132
[82, 165, 165, 255], //----- 133
[0, 127, 127, 255], //----- 134
[63, 127, 127, 255], //----- 135
[0, 76, 76, 255], //----- 136
[38, 76, 76, 255], //----- 137
[0, 38, 38, 255], //----- 138
[19, 38, 38, 255], //----- 139
[0, 191, 255, 255], //----- 140
[127, 223, 255, 255],//----- 141
[0, 124, 165, 255], //----- 142
[82, 145, 165, 255], //----- 143
[0, 95, 127, 255], //----- 144
[63, 111, 127, 255], //----- 145
[0, 57, 76, 255], //----- 146
[38, 66, 76, 255], //----- 147
[0, 28, 38, 255], //----- 148
[19, 33, 38, 255], //----- 149
[0, 127, 255, 255], //----- 150
[127, 191, 255, 255],//----- 151
[0, 82, 165, 255], //----- 152
[82, 124, 165, 255], //----- 153
[0, 63, 127, 255], //----- 154
[63, 95, 127, 255], //----- 155
[0, 38, 76, 255], //----- 156
[38, 57, 76, 255], //----- 157
[0, 19, 38, 255], //----- 158
[19, 28, 38, 255], //----- 159
[0, 63, 255, 255], //----- 160
[127, 159, 255, 255],//----- 161
[0, 41, 165, 255], //----- 162
[82, 103, 165, 255], //----- 163
[0, 31, 127, 255], //----- 164
[63, 79, 127, 255], //----- 165
[0, 19, 76, 255], //----- 166
[38, 47, 76, 255], //----- 167
[0, 9, 38, 255], //----- 168
[19, 23, 38, 255], //----- 169
[0, 0, 255, 255], //----- 170
[127, 127, 255, 255],//----- 171
[0, 0, 165, 255], //----- 172
[82, 82, 165, 255], //----- 173
[0, 0, 127, 255], //----- 174
[63, 63, 127, 255], //----- 175
[0, 0, 76, 255], //----- 176
[38, 38, 76, 255], //----- 177
[0, 0, 38, 255], //----- 178
[19, 19, 38, 255], //----- 179
[63, 0, 255, 255], //----- 180
[159, 127, 255, 255],//----- 181
[41, 0, 165, 255], //----- 182
[103, 82, 165, 255], //----- 183
[31, 0, 127, 255], //----- 184
[79, 63, 127, 255], //----- 185
[19, 0, 76, 255], //----- 186
[47, 38, 76, 255], //----- 187
[9, 0, 38, 255], //----- 188
[23, 19, 38, 255], //----- 189
[127, 0, 255, 255], //----- 190
[191, 127, 255, 255],//----- 191
[82, 0, 165, 255], //----- 192
[124, 82, 165, 255], //----- 193
[63, 0, 127, 255], //----- 194
[95, 63, 127, 255], //----- 195
[38, 0, 76, 255], //----- 196
[57, 38, 76, 255], //----- 197
[19, 0, 38, 255], //----- 198
[28, 19, 38, 255], //----- 199
[191, 0, 255, 255], //----- 200
[223, 127, 255, 255],//----- 201
[124, 0, 165, 255], //----- 202
[145, 82, 165, 255], //----- 203
[95, 0, 127, 255], //----- 204
[111, 63, 127, 255], //----- 205
[57, 0, 76, 255], //----- 206
[66, 38, 76, 255], //----- 207
[28, 0, 38, 255], //----- 208
[33, 19, 38, 255], //----- 209
[255, 0, 255, 255], //----- 210
[255, 127, 255, 255],//----- 211
[165, 0, 165, 255], //----- 212
[165, 82, 165, 255], //----- 213
[127, 0, 127, 255], //----- 214
[127, 63, 127, 255], //----- 215
[76, 0, 76, 255], //----- 216
[76, 38, 76, 255], //----- 217
[38, 0, 38, 255], //----- 218
[38, 19, 38, 255], //----- 219
[255, 0, 191, 255], //----- 220
[255, 127, 223, 255],//----- 221
[165, 0, 124, 255], //----- 222
[165, 82, 145, 255], //----- 223
[127, 0, 95, 255], //----- 224
[127, 63, 111, 255], //----- 225
[76, 0, 57, 255], //----- 226
[76, 38, 66, 255], //----- 227
[38, 0, 28, 255], //----- 228
[38, 19, 33, 255], //----- 229
[255, 0, 127, 255], //----- 230
[255, 127, 191, 255],//----- 231
[165, 0, 82, 255], //----- 232
[165, 82, 124, 255], //----- 233
[127, 0, 63, 255], //----- 234
[127, 63, 95, 255], //----- 235
[76, 0, 38, 255], //----- 236
[76, 38, 57, 255], //----- 237
[38, 0, 19, 255], //----- 238
[38, 19, 28, 255], //----- 239
[255, 0, 63, 255], //----- 240
[255, 127, 159, 255],//----- 241
[165, 0, 41, 255], //----- 242
[165, 82, 103, 255], //----- 243
[127, 0, 31, 255], //----- 244
[127, 63, 79, 255], //----- 245
[76, 0, 19, 255], //----- 246
[76, 38, 47, 255], //----- 247
[38, 0, 9, 255], //----- 248
[38, 19, 23, 255], //----- 249
[84, 84, 84, 255], //----- 250
[118, 118, 118, 255],//----- 251
[152, 152, 152, 255],//----- 252
[186, 186, 186, 255],//----- 253
[220, 220, 220, 255],//----- 254
[255, 255, 255, 255],//----- 255
[255, 255, 255, 255] //----- ByLayer - White
// [255, 255, 255, 255],//----- 7 - White
// [255, 255, 255, 255],//----- 8
// [255, 255, 255, 255],//----- 9
// [255, 0, 0, 255], //----- 10
// [255, 127, 127, 255],//----- 11
// [165, 0, 0, 255], //----- 12
// [165, 82, 82, 255], //----- 13
// [127, 0, 0, 255], //----- 14
// [127, 63, 63, 255], //----- 15
// [76, 0, 0, 255], //----- 16
// [76, 38, 38, 255], //----- 17
// [38, 0, 0, 255], //----- 18
// [38, 19, 19, 255], //----- 19
// [255, 63, 0, 255], //----- 20
// [255, 159, 127, 255],//----- 21
// [165, 41, 0, 255], //----- 22
// [165, 103, 82, 255], //----- 23
// [127, 31, 0, 255], //----- 24
// [127, 79, 63, 255], //----- 25
// [76, 19, 0, 255], //----- 26
// [76, 47, 38, 255], //----- 27
// [38, 9, 0, 255], //----- 28
// [38, 23, 19, 255], //----- 29
// [255, 127, 0, 255], //----- 30
// [255, 191, 127, 255],//----- 31
// [165, 82, 0, 255], //----- 32
// [165, 124, 82, 255], //----- 33
// [127, 63, 0, 255], //----- 34
// [127, 95, 63, 255], //----- 35
// [76, 38, 0, 255], //----- 36
// [76, 57, 38, 255], //----- 37
// [38, 19, 0, 255], //----- 38
// [38, 28, 19, 255], //----- 39
// [255, 191, 0, 255], //----- 40
// [255, 223, 127, 255],//----- 41
// [165, 124, 0, 255], //----- 42
// [165, 145, 82, 255], //----- 43
// [127, 95, 0, 255], //----- 44
// [127, 111, 63, 255], //----- 45
// [76, 57, 0, 255], //----- 46
// [76, 66, 38, 255], //----- 47
// [38, 28, 0, 255], //----- 48
// [38, 33, 19, 255], //----- 49
// [255, 255, 0, 255], //----- 50
// [255, 255, 127, 255],//----- 51
// [165, 165, 0, 255], //----- 52
// [165, 165, 82, 255], //----- 53
// [127, 127, 0, 255], //----- 54
// [127, 127, 63, 255], //----- 55
// [76, 76, 0, 255], //----- 56
// [76, 76, 38, 255], //----- 57
// [38, 38, 0, 255], //----- 58
// [38, 38, 19, 255], //----- 59
// [191, 255, 0, 255], //----- 60
// [223, 255, 127, 255],//----- 61
// [124, 165, 0, 255], //----- 62
// [145, 165, 82, 255], //----- 63
// [95, 127, 0, 255], //----- 64
// [111, 127, 63, 255], //----- 65
// [57, 76, 0, 255], //----- 66
// [66, 76, 38, 255], //----- 67
// [28, 38, 0, 255], //----- 68
// [33, 38, 19, 255], //----- 69
// [127, 255, 0, 255], //----- 70
// [191, 255, 127, 255],//----- 71
// [82, 165, 0, 255], //----- 72
// [124, 165, 82, 255], //----- 73
// [63, 127, 0, 255], //----- 74
// [95, 127, 63, 255], //----- 75
// [38, 76, 0, 255], //----- 76
// [57, 76, 38, 255], //----- 77
// [19, 38, 0, 255], //----- 78
// [28, 38, 19, 255], //----- 79
// [63, 255, 0, 255], //----- 80
// [159, 255, 127, 255],//----- 81
// [41, 165, 0, 255], //----- 82
// [103, 165, 82, 255], //----- 83
// [31, 127, 0, 255], //----- 84
// [79, 127, 63, 255], //----- 85
// [19, 76, 0, 255], //----- 86
// [47, 76, 38, 255], //----- 87
// [9, 38, 0, 255], //----- 88
// [23, 38, 19, 255], //----- 89
// [0, 255, 0, 255], //----- 90
// [127, 255, 127, 255],//----- 91
// [0, 165, 0, 255], //----- 92
// [82, 165, 82, 255], //----- 93
// [0, 127, 0, 255], //----- 94
// [63, 127, 63, 255], //----- 95
// [0, 76, 0, 255], //----- 96
// [38, 76, 38, 255], //----- 97
// [0, 38, 0, 255], //----- 98
// [19, 38, 19, 255], //----- 99
// [0, 255, 63, 255], //----- 100
// [127, 255, 159, 255],//----- 101
// [0, 165, 41, 255], //----- 102
// [82, 165, 103, 255], //----- 103
// [0, 127, 31, 255], //----- 104
// [63, 127, 79, 255], //----- 105
// [0, 76, 19, 255], //----- 106
// [38, 76, 47, 255], //----- 107
// [0, 38, 9, 255], //----- 108
// [19, 38, 23, 255], //----- 109
// [0, 255, 127, 255], //----- 110
// [127, 255, 191, 255],//----- 111
// [0, 165, 82, 255], //----- 112
// [82, 165, 124, 255], //----- 113
// [0, 127, 63, 255], //----- 114
// [63, 127, 95, 255], //----- 115
// [0, 76, 38, 255], //----- 116
// [38, 76, 57, 255], //----- 117
// [0, 38, 19, 255], //----- 118
// [19, 38, 28, 255], //----- 119
// [0, 255, 191, 255], //----- 120
// [127, 255, 223, 255],//----- 121
// [0, 165, 124, 255], //----- 122
// [82, 165, 145, 255], //----- 123
// [0, 127, 95, 255], //----- 124
// [63, 127, 111, 255], //----- 125
// [0, 76, 57, 255], //----- 126
// [38, 76, 66, 255], //----- 127
// [0, 38, 28, 255], //----- 128
// [19, 38, 33, 255], //----- 129
// [0, 255, 255, 255], //----- 130
// [127, 255, 255, 255],//----- 131
// [0, 165, 165, 255], //----- 132
// [82, 165, 165, 255], //----- 133
// [0, 127, 127, 255], //----- 134
// [63, 127, 127, 255], //----- 135
// [0, 76, 76, 255], //----- 136
// [38, 76, 76, 255], //----- 137
// [0, 38, 38, 255], //----- 138
// [19, 38, 38, 255], //----- 139
// [0, 191, 255, 255], //----- 140
// [127, 223, 255, 255],//----- 141
// [0, 124, 165, 255], //----- 142
// [82, 145, 165, 255], //----- 143
// [0, 95, 127, 255], //----- 144
// [63, 111, 127, 255], //----- 145
// [0, 57, 76, 255], //----- 146
// [38, 66, 76, 255], //----- 147
// [0, 28, 38, 255], //----- 148
// [19, 33, 38, 255], //----- 149
// [0, 127, 255, 255], //----- 150
// [127, 191, 255, 255],//----- 151
// [0, 82, 165, 255], //----- 152
// [82, 124, 165, 255], //----- 153
// [0, 63, 127, 255], //----- 154
// [63, 95, 127, 255], //----- 155
// [0, 38, 76, 255], //----- 156
// [38, 57, 76, 255], //----- 157
// [0, 19, 38, 255], //----- 158
// [19, 28, 38, 255], //----- 159
// [0, 63, 255, 255], //----- 160
// [127, 159, 255, 255],//----- 161
// [0, 41, 165, 255], //----- 162
// [82, 103, 165, 255], //----- 163
// [0, 31, 127, 255], //----- 164
// [63, 79, 127, 255], //----- 165
// [0, 19, 76, 255], //----- 166
// [38, 47, 76, 255], //----- 167
// [0, 9, 38, 255], //----- 168
// [19, 23, 38, 255], //----- 169
// [0, 0, 255, 255], //----- 170
// [127, 127, 255, 255],//----- 171
// [0, 0, 165, 255], //----- 172
// [82, 82, 165, 255], //----- 173
// [0, 0, 127, 255], //----- 174
// [63, 63, 127, 255], //----- 175
// [0, 0, 76, 255], //----- 176
// [38, 38, 76, 255], //----- 177
// [0, 0, 38, 255], //----- 178
// [19, 19, 38, 255], //----- 179
// [63, 0, 255, 255], //----- 180
// [159, 127, 255, 255],//----- 181
// [41, 0, 165, 255], //----- 182
// [103, 82, 165, 255], //----- 183
// [31, 0, 127, 255], //----- 184
// [79, 63, 127, 255], //----- 185
// [19, 0, 76, 255], //----- 186
// [47, 38, 76, 255], //----- 187
// [9, 0, 38, 255], //----- 188
// [23, 19, 38, 255], //----- 189
// [127, 0, 255, 255], //----- 190
// [191, 127, 255, 255],//----- 191
// [82, 0, 165, 255], //----- 192
// [124, 82, 165, 255], //----- 193
// [63, 0, 127, 255], //----- 194
// [95, 63, 127, 255], //----- 195
// [38, 0, 76, 255], //----- 196
// [57, 38, 76, 255], //----- 197
// [19, 0, 38, 255], //----- 198
// [28, 19, 38, 255], //----- 199
// [191, 0, 255, 255], //----- 200
// [223, 127, 255, 255],//----- 201
// [124, 0, 165, 255], //----- 202
// [145, 82, 165, 255], //----- 203
// [95, 0, 127, 255], //----- 204
// [111, 63, 127, 255], //----- 205
// [57, 0, 76, 255], //----- 206
// [66, 38, 76, 255], //----- 207
// [28, 0, 38, 255], //----- 208
// [33, 19, 38, 255], //----- 209
// [255, 0, 255, 255], //----- 210
// [255, 127, 255, 255],//----- 211
// [165, 0, 165, 255], //----- 212
// [165, 82, 165, 255], //----- 213
// [127, 0, 127, 255], //----- 214
// [127, 63, 127, 255], //----- 215
// [76, 0, 76, 255], //----- 216
// [76, 38, 76, 255], //----- 217
// [38, 0, 38, 255], //----- 218
// [38, 19, 38, 255], //----- 219
// [255, 0, 191, 255], //----- 220
// [255, 127, 223, 255],//----- 221
// [165, 0, 124, 255], //----- 222
// [165, 82, 145, 255], //----- 223
// [127, 0, 95, 255], //----- 224
// [127, 63, 111, 255], //----- 225
// [76, 0, 57, 255], //----- 226
// [76, 38, 66, 255], //----- 227
// [38, 0, 28, 255], //----- 228
// [38, 19, 33, 255], //----- 229
// [255, 0, 127, 255], //----- 230
// [255, 127, 191, 255],//----- 231
// [165, 0, 82, 255], //----- 232
// [165, 82, 124, 255], //----- 233
// [127, 0, 63, 255], //----- 234
// [127, 63, 95, 255], //----- 235
// [76, 0, 38, 255], //----- 236
// [76, 38, 57, 255], //----- 237
// [38, 0, 19, 255], //----- 238
// [38, 19, 28, 255], //----- 239
// [255, 0, 63, 255], //----- 240
// [255, 127, 159, 255],//----- 241
// [165, 0, 41, 255], //----- 242
// [165, 82, 103, 255], //----- 243
// [127, 0, 31, 255], //----- 244
// [127, 63, 79, 255], //----- 245
// [76, 0, 19, 255], //----- 246
// [76, 38, 47, 255], //----- 247
// [38, 0, 9, 255], //----- 248
// [38, 19, 23, 255], //----- 249
// [84, 84, 84, 255], //----- 250
// [118, 118, 118, 255],//----- 251
// [152, 152, 152, 255],//----- 252
// [186, 186, 186, 255],//----- 253
// [220, 220, 220, 255],//----- 254
// [255, 255, 255, 255],//----- 255
// [255, 255, 255, 255] //----- ByLayer - White
];
@@ -270,19 +271,28 @@ export class ColorMaterial
{
private constructor() { }
private static m_LineMaterialMap = new Map<number, THREE.LineBasicMaterial>();
static GetLineMaterial(index): THREE.LineBasicMaterial
static GetLineMaterial(index): LineBasicMaterial
{
if (this.m_LineMaterialMap.has(index))
return this.m_LineMaterialMap.get(index);
let mat = new THREE.LineBasicMaterial({ color: this.GetColor(index) });
let mat = new LineBasicMaterial({ color: this.GetColor(index) });
this.m_LineMaterialMap.set(index, mat);
return mat;
}
private static m_BasicMaterialMap = new Map<number, MeshBasicMaterial>();
static GetBasicMaterial(index: number): MeshBasicMaterial
{
if (this.m_BasicMaterialMap.has(index))
return this.m_BasicMaterialMap.get(index);
let mat = new MeshBasicMaterial({ color: this.GetColor(index) });
this.m_BasicMaterialMap.set(index, mat);
return mat;
}
static GetColor(index: number)
{
let rgb = ColorPalette[index];
if (rgb)
return new THREE.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255);
return new Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255);
}
}

View File

@@ -5,7 +5,6 @@ import { MoveMatrix } from "./GeUtils";
/**
* 标注实体
*
* @export
* @class Dimension
* @extends {Group}
@@ -42,12 +41,12 @@ export class Dimension extends Group
if (mirror)
{
let roMat = new Matrix4().makeRotationZ(Math.PI);
text.applyMatrix(roMat);
text.applyMatrix(MoveMatrix(new Vector3(length * 0.5, footLength - textHeight * 0.1)));
text.applyMatrix4(roMat);
text.applyMatrix4(MoveMatrix(new Vector3(length * 0.5, footLength - textHeight * 0.1)));
}
else
{
text.applyMatrix(MoveMatrix(new Vector3(length * 0.5, footLength * 1.1)));
text.applyMatrix4(MoveMatrix(new Vector3(length * 0.5, footLength * 1.1)));
}

View File

@@ -1,4 +1,4 @@
import { Box3, Vector3, Matrix4, Mesh } from "three";
import { Box3, Matrix4, Mesh, Vector3 } from "three";
import { Dimension, GetBoxArr } from ".";
@@ -24,7 +24,7 @@ export function DrawDimension(brList: Mesh[]): Dimension[]
let textHeight = 45;
let dimx = new Dimension(size.x, textHeight, true);
dimx.applyMatrix(mat4);
dimx.applyMatrix4(mat4);
let dimz = new Dimension(size.z, textHeight);
mat4.makeBasis(
@@ -33,7 +33,7 @@ export function DrawDimension(brList: Mesh[]): Dimension[]
new Vector3(0, -1, 0)
)
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);
mat4.makeBasis(
@@ -42,7 +42,7 @@ export function DrawDimension(brList: Mesh[]): Dimension[]
new Vector3(0, 0, 1)
)
mat4.setPosition(box.max.clone().add(new Vector3(30, -size.y)));
dimy.applyMatrix(mat4);
dimy.applyMatrix4(mat4);
return [dimx, dimy, dimz];

View File

@@ -1,12 +1,11 @@
import * as THREE from 'three';
import { Geometry, Vector, Vector2, Vector3 } from 'three';
import { Geometry, Vector, Vector2, Vector3, Box3, Matrix4, Object3D, Line, Mesh } from 'three';
import { Matrix2 } from './Matrix2';
export const cZeroVec = new THREE.Vector3();
export const cXAxis = new THREE.Vector3(1, 0, 0);
export const cYAxis = new THREE.Vector3(0, 1, 0);
export const cZAxis = new THREE.Vector3(0, 0, 1);
export const cZeroVec = new Vector3();
export const cXAxis = new Vector3(1, 0, 0);
export const cYAxis = new Vector3(0, 1, 0);
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;
}
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)
{
return v1.distanceToSquared(v2) < 1e-8;
@@ -77,21 +82,21 @@ export function angle(v: Vector3 | Vector2)
/**
* 求两个向量的夹角,顺时针为负,逆时针为正
*
* @param {THREE.Vector3} v1
* @param {THREE.Vector3} v2
* @param {THREE.Vector3} [ref] 参考向量,如果为世界坐标系则为0,0,1
* @param {Vector3} v1
* @param {Vector3} v2
* @param {Vector3} [ref] 参考向量,如果为世界坐标系则为0,0,1
* @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)))
{
//任意轴坐标系. 使用相机的构造矩阵.
ref.multiplyScalar(-1);
let up = getLoocAtUpVec(ref);
let refOcs = new THREE.Matrix4();
let refOcs = new Matrix4();
refOcs.lookAt(cZeroVec, ref, up);
let refOcsInv = new THREE.Matrix4().getInverse(refOcs);
let refOcsInv = new Matrix4().getInverse(refOcs);
v1.applyMatrix4(refOcsInv);
v2.applyMatrix4(refOcsInv);
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;
}
export function getLoocAtUpVec(dir: THREE.Vector3): THREE.Vector3
export function getLoocAtUpVec(dir: Vector3): Vector3
{
if (dir.equals(cZeroVec))
{
@@ -112,37 +117,37 @@ export function getLoocAtUpVec(dir: THREE.Vector3): THREE.Vector3
let norm = dir.clone().normalize();
if (norm.equals(cZAxis))
{
return new THREE.Vector3(0, 1, 0);
return new Vector3(0, 1, 0);
}
else if (norm.equals(cZAxis.clone().negate()))
{
return new THREE.Vector3(0, -1, 0);
return new Vector3(0, -1, 0);
}
else
{
let xv: THREE.Vector3 = new THREE.Vector3();
let xv: Vector3 = new Vector3();
xv.crossVectors(cZAxis, norm);
let up = new THREE.Vector3();
let up = new Vector3();
up.crossVectors(norm, xv);
return up;
}
}
export function createLookAtMat4(dir: THREE.Vector3): THREE.Matrix4
export function createLookAtMat4(dir: Vector3): Matrix4
{
let up = getLoocAtUpVec(dir);
let mat = new THREE.Matrix4();
let mat = new Matrix4();
mat.lookAt(cZeroVec, dir, up);
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;
}
export function ptToString(v: THREE.Vector3, fractionDigits: number = 3): string
export function ptToString(v: Vector3, fractionDigits: number = 3): string
{
return v.toArray().map(o =>
{
@@ -150,16 +155,16 @@ export function ptToString(v: THREE.Vector3, fractionDigits: number = 3): string
}).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);
}
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);
}
export function midPtCir(v1: THREE.Vector3, v2: THREE.Vector3)
export function midPtCir(v1: Vector3, v2: Vector3)
{
let baseline = new Vector3(1, 0, 0);
let outLine = v2.clone().sub(v1);
@@ -168,56 +173,52 @@ export function midPtCir(v1: THREE.Vector3, v2: THREE.Vector3)
return v1.clone().add(midLine);
}
export function GetBox(obj: THREE.Object3D, updateMatrix?: boolean): THREE.Box3
/**
* 获得Three对象的包围盒.
* @param obj
* @param [updateMatrix] 是否应该更新对象矩阵
* @returns box
*/
export function GetBox(obj: Object3D, updateMatrix?: boolean): Box3
{
let box = new Box3();
if (updateMatrix) obj.updateMatrixWorld(false);
if (obj.hasOwnProperty("geometry"))
if (!obj.visible) return box;
obj.traverse(o =>
{
let geo = obj["geometry"];
if (geo instanceof THREE.Geometry || geo instanceof THREE.BufferGeometry)
//因为实体Erase时,实体仍然保存在Scene中.
if (o.visible === false)
return;
//@ts-ignore
let geo = o.geometry as BufferGeometry;
if (geo)
{
if (!geo.boundingBox)
geo.computeBoundingBox();
return geo.boundingBox.clone().applyMatrix4(obj.matrixWorld);
box.union(geo.boundingBox.clone().applyMatrix4(o.matrixWorld));
}
}
else if (obj.children.length > 0)
{
let box = obj.children.reduce((sumBox, itemObj) =>
{
let itemBox = GetBox(itemObj);
if (itemBox)
sumBox.union(itemBox);
return sumBox;
}, new THREE.Box3())
// if (box) box.applyMatrix4(obj.matrixWorld);
});
return box;
}
else
return null;
}
export function GetBoxArr(arr: Array<THREE.Object3D>): THREE.Box3
export function GetBoxArr(arr: Array<Object3D>): Box3
{
if (arr.length == 0)
let box = new Box3();
for (let o of arr)
{
return null;
let b = GetBox(o);
if (!b.isEmpty())
box.union(b);
}
return arr.map(o =>
{
return GetBox(o);
}).filter(o =>
{
return o;
}).reduce((sumBox: THREE.Box3, objBox: THREE.Box3) =>
{
return sumBox.union(objBox)
}, new THREE.Box3());
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);
return mat;
}
@@ -279,9 +280,9 @@ export function angleTo2Pi(an: number)
if (an < 0) an += Math.PI * 2
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();
l.geometry = geometry;
geometry.verticesNeedUpdate = true;

View File

@@ -8,6 +8,13 @@ export let boardMaterial = new MeshBasicMaterial({
polygonOffsetUnits: 1
});
export let selectMaterial = new MeshBasicMaterial({
color: new Color(0.1, 0.5, 0.5),
polygonOffset: true,
polygonOffsetFactor: 1, // positive value pushes polygon further away
polygonOffsetUnits: 1
});
//线框的材质
export let edgeMaterial = new LineBasicMaterial({ linewidth: 2, color: new Color(0, 0, 0) });

View File

@@ -1,4 +1,4 @@
import * as THREE from "three";
import { MathUtils, Vector3 } from "three";
/**
* 轨道控制的数学类,观察向量和角度的互相转换
@@ -20,19 +20,19 @@ export class Orbit
}
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] 引用传入,如果传入,那么就不构造新的向量
* @returns {THREE.Vector3} 返回观察向量
* @param {Vector3} [dir] 引用传入,如果传入,那么就不构造新的向量
* @returns {Vector3} 返回观察向量
* @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);
@@ -48,10 +48,10 @@ export class Orbit
/**
* 使用观察向量,计算旋转角度
*
* @param {THREE.Vector3} dir
* @param {Vector3} dir
* @memberof Orbit
*/
UpdateRoValue(dir: THREE.Vector3)
UpdateRoValue(dir: Vector3)
{
dir.normalize();
this.m_RoX = Math.asin(dir.z);
@@ -66,26 +66,26 @@ export class Orbit
* 根据观察向量 求头部的向量.
*
* @static
* @param {THREE.Vector3} dir
* @param {THREE.Vector3} [up]
* @returns {THREE.Vector3}
* @param {Vector3} dir
* @param {Vector3} [up]
* @returns {Vector3}
* @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();
if (dir.equals(new THREE.Vector3(0, 0, -1)))
let upRes = up ? up : new Vector3();
if (dir.equals(new Vector3(0, 0, -1)))
{
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);
}
else
{
let xv = new THREE.Vector3();
xv.crossVectors(new THREE.Vector3(0, 0, 1), dir);
let xv = new Vector3();
xv.crossVectors(new Vector3(0, 0, 1), dir);
upRes.crossVectors(dir, xv);
upRes.normalize();
}

View File

@@ -1,9 +1,9 @@
import * as THREE from 'three';
import { Vector3, Line3 } from "three";
import { Vector3, Line3, Plane } from "three";
export class PlaneExt extends THREE.Plane
export class PlaneExt extends Plane
{
constructor(normal?: THREE.Vector3, constant?: number)
constructor(normal?: Vector3, constant?: number)
{
super(normal, constant);
}

View File

@@ -1,14 +1,14 @@
import { Matrix2 } from './Matrix2';
import * as THREE from 'three';
import { Geometry, Vector2 } from 'three';
export function RotateUVs(geo: THREE.Geometry)
export function RotateUVs(geo: Geometry)
{
let roMat = new Matrix2();
roMat.set(0, -1,
1, 0);
let addV = new THREE.Vector2(1, 0);
let addV = new Vector2(1, 0);
for (let uvs of geo.faceVertexUvs)
{

View File

@@ -1,11 +1,14 @@
import { Font, FontLoader, Mesh, ShapeGeometry, Vector3 } from "three";
import { Font, FontLoader, Mesh, ShapeGeometry, Vector3, Shape } from "three";
import { ColorMaterial } from "./ColorPalette";
import { MoveMatrix } from "./GeUtils";
class FontLoaderUtil {
class FontLoaderUtil
{
private static defFont: Font;
static Load(): Font {
if (!this.defFont) {
static Load(): Font
{
if (!this.defFont)
{
const f = require("../resources/fonts/helvetiker_regular.typeface.json");
let loader = new FontLoader();
this.defFont = loader.parse(f);
@@ -14,7 +17,8 @@ class FontLoaderUtil {
}
}
export class DbText extends Mesh {
export class DbText extends Mesh
{
/**
*
* 构造一个文本对象,8位点(中心点下面)在0点
@@ -22,17 +26,18 @@ export class DbText extends Mesh {
* @param {number} height 文本高度
* @memberof DbText
*/
constructor(str: string, height: number = 5) {
constructor(str: string, height: number = 5)
{
let font = FontLoaderUtil.Load();
let shapes: THREE.Shape[] = font.generateShapes(str, height, 0.1);
let shapes: Shape[] = font.generateShapes(str, height);
let geometry = new ShapeGeometry(shapes);
geometry.computeBoundingBox();
super(geometry, ColorMaterial.GetLineMaterial(5));
super(geometry, ColorMaterial.GetBasicMaterial(5));
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)));
}
}

View File

@@ -71,32 +71,8 @@ export class ThreeBSP
vertex = new Vertex(vertex.x, vertex.y, vertex.z, face.vertexNormals[2], uvs);
vertex.applyMatrix4(this.matrix);
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;
}

View File

@@ -1,17 +1,28 @@
import { Viewer, createTemplateBoard, createEdge, DrawDimension } from ".";
import { Geometry } from "three";
import { Object3D, Mesh } from "three";
import { createTemplateBoard, DrawDimension, Viewer } from ".";
export function LoadBoard(view: Viewer, data: any[])
function dispose(m: Object3D)
{
view.m_Scene.children.forEach(obj =>
{
let geo = obj["geometry"] as Geometry;
if (geo) geo.dispose();
})
view.m_Scene.children.length = 0;
//@ts-ignore
if (m.geometry)
//@ts-ignore
m.geometry.dispose();
m.children.forEach(o => dispose(o));
}
export function LoadBoard(view: Viewer, data: any[], clear: boolean = true)
{
if (clear)
{
dispose(view.m_Scene);
view.m_Scene.children.length = 0;
}
if (data.length === 0) return;
//加板
let { meshs, edgesa } = createTemplateBoard(data);
let { meshs, edgesa, relations } = createTemplateBoard(data, view._Settings.boardMaterial);
//加标注
let dims = DrawDimension(meshs);
@@ -22,4 +33,6 @@ export function LoadBoard(view: Viewer, data: any[])
view.ViewToSwiso();
view.ZoomAll();
view.Zoom(1.1);
return relations;
}

444
src/ViewSrc/data.json Normal file
View File

@@ -0,0 +1,444 @@
[
{
"L": 4408.678960586129,
"W": 4408.678960586129,
"H": 18,
"CabName": "主卧",
"BoardName": "",
"BasePoint": {
"x": -82.91743119266054,
"y": 73.39449541284404,
"z": 0
},
"XVec": {
"x": 0,
"y": 1,
"z": 0
},
"YVec": {
"x": 0,
"y": 0,
"z": 1
},
"ZVec": {
"x": 1,
"y": 0,
"z": 0
},
"Grain": 0,
"Pts": [
{
"x": 4408.678960586129,
"y": 2204.3394802930643
},
{
"x": 0,
"y": 2204.3394802930648
},
{
"x": 4408.678960586129,
"y": 2204.3394802930643
}
],
"Buls": [
-0.9999999999999999,
-0.9999999999999999,
0
],
"SubBoardLocal": [
{
"L": 633.2307692307686,
"W": 633.2307692307686,
"H": 5,
"CabName": "",
"BoardName": "",
"BasePoint": {
"x": -95.91743119266054,
"y": 2910.9647449366785,
"z": 1405.2625572161414
},
"XVec": {
"x": 0,
"y": 1,
"z": 0
},
"YVec": {
"x": 0,
"y": 0,
"z": 1
},
"ZVec": {
"x": 1,
"y": 0,
"z": 0
},
"Grain": 0,
"Pts": [
{
"x": 633.2307692307686,
"y": 316.6153846153843
},
{
"x": 0,
"y": 316.61538461538436
},
{
"x": 633.2307692307686,
"y": 316.6153846153843
}
],
"Buls": [
-0.9999999999999999,
-0.9999999999999999,
0
],
"SubBoardLocal": [],
"SubBoardAssoc": null,
"Drillings": null
},
{
"L": 557.8461538461524,
"W": 557.8461538461524,
"H": 5,
"CabName": "",
"BoardName": "",
"BasePoint": {
"x": -82.91743119266054,
"y": 3016.50320647514,
"z": 2257.1087110622957
},
"XVec": {
"x": 0,
"y": 1,
"z": 0
},
"YVec": {
"x": 0,
"y": 0,
"z": 1
},
"ZVec": {
"x": 1,
"y": 0,
"z": 0
},
"Grain": 0,
"Pts": [
{
"x": 557.8461538461524,
"y": 278.9230769230762
},
{
"x": 0,
"y": 278.9230769230763
},
{
"x": 557.8461538461524,
"y": 278.9230769230762
}
],
"Buls": [
-0.9999999999999999,
-0.9999999999999999,
0
],
"SubBoardLocal": [],
"SubBoardAssoc": null,
"Drillings": null
},
{
"L": 444.76923076923117,
"W": 686,
"H": 5,
"CabName": "",
"BoardName": "",
"BasePoint": {
"x": -95.91743119266054,
"y": 1689.7339757059085,
"z": 1556.0317879853721
},
"XVec": {
"x": 0,
"y": 1,
"z": 0
},
"YVec": {
"x": 0,
"y": 0,
"z": 1
},
"ZVec": {
"x": 1,
"y": 0,
"z": 0
},
"Grain": 0,
"Pts": [
{
"x": 0,
"y": 0
},
{
"x": 686,
"y": 0
},
{
"x": 686,
"y": 444.76923076923117
},
{
"x": 0,
"y": 444.76923076923117
},
{
"x": 0,
"y": 0
}
],
"Buls": [
0,
0,
0,
0,
0
],
"SubBoardLocal": [],
"SubBoardAssoc": null,
"Drillings": null
},
{
"L": 625.6923076923076,
"W": 1349.3846153846157,
"H": 5,
"CabName": "",
"BoardName": "",
"BasePoint": {
"x": -82.91743119266054,
"y": 1177.1185910905238,
"z": 2626.493326446911
},
"XVec": {
"x": 0,
"y": 1,
"z": 0
},
"YVec": {
"x": 0,
"y": 0,
"z": 1
},
"ZVec": {
"x": 1,
"y": 0,
"z": 0
},
"Grain": 0,
"Pts": [
{
"x": 0,
"y": 0
},
{
"x": 1349.3846153846157,
"y": 0
},
{
"x": 1349.3846153846157,
"y": 625.6923076923076
},
{
"x": 0,
"y": 625.6923076923076
},
{
"x": 0,
"y": 0
}
],
"Buls": [
0,
0,
0,
0,
0
],
"SubBoardLocal": [],
"SubBoardAssoc": null,
"Drillings": null
}
],
"SubBoardAssoc": null,
"Drillings": null
},
{
"L": 2000,
"W": 600,
"H": 18,
"CabName": "主卧",
"BoardName": "",
"BasePoint": {
"x": 1099.0825688073396,
"y": 73.39449541284404,
"z": 0
},
"XVec": {
"x": 0,
"y": 1,
"z": 0
},
"YVec": {
"x": 0,
"y": 0,
"z": 1
},
"ZVec": {
"x": 1,
"y": 0,
"z": 0
},
"Grain": 0,
"Pts": [
{
"x": 0,
"y": 0
},
{
"x": 600,
"y": 0
},
{
"x": 600,
"y": 2000
},
{
"x": 0,
"y": 2000
},
{
"x": 0,
"y": 0
}
],
"Buls": [
0,
0,
0,
0,
0
],
"SubBoardLocal": [
{
"L": 144.00000000000023,
"W": 170.42201834862385,
"H": 5,
"CabName": "",
"BoardName": "",
"BasePoint": {
"x": 1099.0825688073396,
"y": 288.2935779816515,
"z": 1001.247706422018
},
"XVec": {
"x": 0,
"y": 1,
"z": 0
},
"YVec": {
"x": 0,
"y": 0,
"z": 1
},
"ZVec": {
"x": 1,
"y": 0,
"z": 0
},
"Grain": 0,
"Pts": [
{
"x": 0,
"y": 0
},
{
"x": 170.42201834862385,
"y": 0
},
{
"x": 170.42201834862385,
"y": 144.00000000000023
},
{
"x": 0,
"y": 144.00000000000023
},
{
"x": 0,
"y": 0
}
],
"Buls": [
0,
0,
0,
0,
0
],
"SubBoardLocal": [],
"SubBoardAssoc": null,
"Drillings": null
},
{
"L": 189.0974955047293,
"W": 189.0974955047293,
"H": 18,
"CabName": "",
"BoardName": "",
"BasePoint": {
"x": 1099.0825688073396,
"y": 234.6989586696538,
"z": 1267.3595091283692
},
"XVec": {
"x": 0,
"y": 1,
"z": 0
},
"YVec": {
"x": 0,
"y": 0,
"z": 1
},
"ZVec": {
"x": 1,
"y": 0,
"z": 0
},
"Grain": 0,
"Pts": [
{
"x": 189.0974955047293,
"y": 94.54874775236476
},
{
"x": -1.4210854715202004e-14,
"y": 94.54874775236478
},
{
"x": 189.0974955047293,
"y": 94.54874775236476
}
],
"Buls": [
-0.9999999999999999,
-0.9999999999999999,
0
],
"SubBoardLocal": [],
"SubBoardAssoc": null,
"Drillings": null
}
],
"SubBoardAssoc": null,
"Drillings": null
}
]

14
src/ViewSrc/index.html Normal file
View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>WebCAD</title>
</head>
<body>
</body>
</html>

105
src/ViewSrc/index.ts Normal file
View File

@@ -0,0 +1,105 @@
// import { Color, Face3, MeshBasicMaterial, Object3D, Vector2, Vector3 } from "three";
// import "./style.css";
import { Color, MeshBasicMaterial, Vector3 } from "three";
import { CameraControlState } from "../CameraControls";
import { data } from "../data";
import { GetBox } from "../GeUtils";
import { LoadBoard } from "../Utils";
import { Viewer } from "../Viewer";
let btn = document.createElement("button");
btn.innerHTML = "载入"
document.body.appendChild(btn);
let btn2 = document.createElement("button");
btn2.innerHTML = "清理"
document.body.appendChild(btn2);
let btn3 = document.createElement("button");
btn3.innerHTML = "爆炸图"
document.body.appendChild(btn3);
let el = document.createElement("canvas");
el.style.width = "80%";
el.style.height = "80%";
document.body.appendChild(el);
let view = new Viewer(el, (settings) =>
{
settings.boardMaterial = new MeshBasicMaterial({
color: new Color(0.8, 0.8, 0.8),
polygonOffset: true,
polygonOffsetFactor: 1, // positive value pushes polygon further away
polygonOffsetUnits: 1,
transparent: true,
opacity: 0.5
});
});
//修改这个顺序 改变1 2 3 个触摸点时的触发状态.
view.m_CameraCtrl.m_TouthTypeList = [CameraControlState.Rotate, CameraControlState.Scale, CameraControlState.Pan];
//例如,修改单指滑动为平移.
view.m_CameraCtrl.m_TouthTypeList = [CameraControlState.Pan, CameraControlState.Scale, CameraControlState.Rotate];
//加载
btn.onclick = () =>
{
console.time();
for (let i = 0; i < 1; i++)
LoadBoard(view, data);
console.timeEnd();
}
btn2.onclick = () =>
{
// LoadBoard(view, []);
}
btn3.onclick = () =>
{
let box = GetBox(view.m_Scene);
let cen = box.getCenter(new Vector3());
let m = [];
for (let obj of view.m_Scene.children)
{
if (obj.userData && obj.userData instanceof Vector3)
{
let objCen = GetBox(obj).getCenter(new Vector3());
let v = objCen.clone().sub(cen);
let zv = obj.userData as Vector3;
if (zv instanceof Vector3)
{
let d = zv.dot(v);
// m.set(obj, zv.clone().multiplyScalar(d));
m.push([obj, zv.clone().multiplyScalar(d)]);
}
}
}
let count = 0;
let t = setInterval(() =>
{
for (let [o, v] of m)
{
o.position.add(
v.clone().multiplyScalar(1.5 / 120)
);
o.updateMatrix();
}
view.ZoomAll();
view.m_bNeedUpdate = true;
count++;
if (count === 60)
clearInterval(t);
}, 16)
}

12
src/ViewSrc/style.css Normal file
View File

@@ -0,0 +1,12 @@
body {
font-size: 11px;
overflow: hidden;
}
html,
body {
background: #5C7080;
height: 100%;
padding: 0;
margin: 0;
}

View File

@@ -1,71 +1,80 @@
import * as THREE from "three";
import { Mesh, MeshBasicMaterial, Raycaster, Scene, Vector3, WebGLRenderer, WebGLRendererParameters } from "three";
import { boardMaterial, CameraControls, PointPick, selectMaterial } from ".";
import { CameraUpdate } from "./CameraUpdate";
import { GetBox, GetBoxArr, cZeroVec } from "./GeUtils";
import { ColorMaterial } from "./ColorPalette";
import { cZeroVec, GetBox, GetBoxArr } from "./GeUtils";
import { PlaneExt } from "./PlaneExt";
import { PointPick, boardMaterial, CameraControls } from ".";
import { MeshBasicMaterial, Color, Mesh } from "three";
export class ViewerSettings
{
boardMaterial: MeshBasicMaterial = boardMaterial;
selectMaterial: MeshBasicMaterial = selectMaterial;
selectByPointCallback: (meshId: number) => void = () => { };
}
export class Viewer
{
m_LookTarget: any;
m_Camera: CameraUpdate = new CameraUpdate();
m_CameraCtrl: CameraControls;
m_bNeedUpdate: boolean = true;
m_Render: THREE.WebGLRenderer;//渲染器 //暂时只用这个类型
m_Render: WebGLRenderer;//渲染器 //暂时只用这个类型
m_DomEl: HTMLElement; //画布容器
_Height: number;
_Width: number;
m_Scene: THREE.Scene = new THREE.Scene();
m_Scene: Scene = new Scene();
//构造
constructor(canvasContainer: HTMLElement)
_Settings = new ViewerSettings();
/**
*
* @param {HTMLElement} canvasContainer 可以传入一个div或者一个画布
* @memberof Viewer
*/
constructor(canvasContainer: HTMLElement, setupAction: (settings: ViewerSettings) => void = null)
{
if (setupAction)
{
setupAction(this._Settings);
}
this.m_DomEl = canvasContainer;
this.initRender(canvasContainer);
this.OnSize();
this.StartRender();
new CameraControls(this);
this.m_CameraCtrl = new CameraControls(this);
window.addEventListener("resize", () =>
{
this.OnSize();
});
//选中
let selectMaterial = new MeshBasicMaterial({ color: new Color(0.1, 0.5, 0.5) });
let oldMesh: Mesh;
this.m_Render.domElement.addEventListener("mousemove", (e: MouseEvent) =>
{
let mesh = PointPick(this, e.offsetX, e.offsetY);
if (oldMesh)
oldMesh.material = boardMaterial;
if (mesh)
{
oldMesh = mesh;
mesh.material = selectMaterial;
this.m_bNeedUpdate = true;
}
this.SelectByPoint(e.offsetX, e.offsetY);
})
}
//初始化render
initRender(canvasContainer: HTMLElement)
{
this.m_Render = new THREE.WebGLRenderer(
{
let params: WebGLRendererParameters = {
antialias: true,//antialias:true/false是否开启反锯齿
precision: "highp",//precision:highp/mediump/lowp着色精度选择
alpha: true,//alpha:true/false是否可以设置背景色透明
// premultipliedAlpha: false,//?
// stencil: false,//?
// preserveDrawingBuffer: true,//preserveDrawingBuffer:true/false是否保存绘图缓冲
// maxLights: 1//maxLights:最大灯光数
alpha: true//alpha:true/false是否可以设置背景色透明
};
if (canvasContainer instanceof HTMLCanvasElement)
{
params.canvas = canvasContainer;
this.m_Render = new WebGLRenderer(params);
}
);
else
{
this.m_Render = new WebGLRenderer(params);
//加到画布
canvasContainer.appendChild(this.m_Render.domElement);
}
this.m_Render.autoClear = true;
@@ -73,7 +82,7 @@ export class Viewer
// this.m_Render.gammaInput = true;
// this.m_Render.gammaOutput = true;
// this.m_Render.shadowMap.enabled = true;
// this.m_Render.toneMapping = THREE.ReinhardToneMapping;
// this.m_Render.toneMapping = ReinhardToneMapping;
//设置设备像素比。 这通常用于HiDPI设备以防止模糊输出画布。
this.m_Render.setPixelRatio(window.devicePixelRatio);
this.m_Render.physicallyCorrectLights = true;
@@ -88,8 +97,8 @@ export class Viewer
OnSize = (width?, height?) =>
{
this._Width = width ? width : this.m_DomEl.scrollWidth;
this._Height = height ? height : this.m_DomEl.scrollHeight;
this._Width = width ? width : this.m_DomEl.clientWidth;
this._Height = height ? height : this.m_DomEl.clientHeight;
//校验.成为2的倍数 避免外轮廓错误.
if (this._Width % 2 == 1)
@@ -115,11 +124,11 @@ export class Viewer
this.m_Render.render(this.m_Scene, this.m_Camera.Camera);
}
ScreenToWorld(pt: THREE.Vector3, planVec?: THREE.Vector3)
ScreenToWorld(pt: Vector3, planVec?: Vector3)
{
//变换和求交点
let plan = new PlaneExt(planVec || new THREE.Vector3(0, 0, 1));
let raycaster = new THREE.Raycaster();
let plan = new PlaneExt(planVec || new Vector3(0, 0, 1));
let raycaster = new Raycaster();
// 射线从相机射线向屏幕点位置
raycaster.setFromCamera(
{
@@ -130,7 +139,7 @@ export class Viewer
)
plan.intersectRay(raycaster.ray, pt, true);
}
WorldToScreen(pt: THREE.Vector3)
WorldToScreen(pt: Vector3)
{
let widthHalf = this._Width * 0.5;
let heightHalf = this._Height * 0.5;
@@ -151,21 +160,21 @@ export class Viewer
let renderList = this.m_Render.renderLists.get(this.m_Scene, this.m_Camera.Camera);
let box = GetBoxArr(renderList.opaque.map(o => o.object));
if (box)
this.m_LookTarget = box.getCenter(new THREE.Vector3());
this.m_LookTarget = box.getCenter(new Vector3());
else
this.m_LookTarget = cZeroVec;
}
Rotate(mouseMove: THREE.Vector3)
Rotate(mouseMove: Vector3)
{
this.m_Camera.Rotate(mouseMove, this.m_LookTarget);
this.m_bNeedUpdate = true;
}
Pan(mouseMove: THREE.Vector3)
Pan(mouseMove: Vector3)
{
this.m_Camera.Pan(mouseMove);
this.m_bNeedUpdate = true;
}
Zoom(scale: number, center?: THREE.Vector3)
Zoom(scale: number, center?: Vector3)
{
this.m_Camera.Zoom(scale, center);
this.m_bNeedUpdate = true;
@@ -178,17 +187,57 @@ export class Viewer
ViewToTop()
{
this.m_Camera.LookAt(new THREE.Vector3(0, 0, -1));
this.m_Camera.LookAt(new Vector3(0, 0, -1));
this.m_bNeedUpdate = true;
}
ViewToFront()
{
this.m_Camera.LookAt(new THREE.Vector3(0, 1, 0));
this.m_Camera.LookAt(new Vector3(0, 1, 0));
this.m_bNeedUpdate = true;
}
ViewToSwiso()
{
this.m_Camera.LookAt(new THREE.Vector3(1, 1, -1));
this.m_Camera.LookAt(new Vector3(1, 1, -1));
this.m_bNeedUpdate = true;
}
oldMesh: Mesh;
SelectByPoint(x: number, y: number)
{
let mesh = PointPick(this, x, y);
if (this.oldMesh)
this.oldMesh.material = this._Settings.boardMaterial;
if (mesh && mesh.material !== ColorMaterial.GetBasicMaterial(1))
{
this.oldMesh = mesh;
mesh.material = this._Settings.selectMaterial;
if (this._Settings.selectByPointCallback)
{
this._Settings.selectByPointCallback(mesh.id);
}
}
this.m_bNeedUpdate = true;
}
SelectBlock(blockMeshMap: Map<number, number>, dataID: number)
{
if (blockMeshMap.has(dataID))
{
let meshId = blockMeshMap.get(dataID);
if (this.oldMesh)
this.oldMesh.material = this._Settings.boardMaterial;
this.m_Scene.children.forEach(obj =>
{
if (obj instanceof Mesh)
{
if (obj.id == meshId)
{
this.oldMesh = obj;
obj.material = this._Settings.selectMaterial;
this.m_bNeedUpdate = true;
}
}
})
}
}
}

View File

@@ -1,7 +1,7 @@
import * as THREE from 'three';
import { Geometry, LineSegments, Vector2 } from 'three';
import { polar } from './GeUtils';
import { boardMaterial, edgeMaterial } from './Material';
import { CylinderGeometry, Geometry, LineSegments, Mesh, Shape, Vector2, Vector3, Matrix4, ExtrudeGeometry, EdgesGeometry, MeshBasicMaterial } from 'three';
import { ColorMaterial } from './ColorPalette';
import { equalv3, polar } from './GeUtils';
import { edgeMaterial } from './Material';
import { RotateUVs } from './RotateUV';
import { ThreeBSP } from './ThreeCSG';
//解析二维圆弧类.
@@ -9,16 +9,16 @@ export class Arc2d
{
m_StartAn: number;
m_EndAn: number;
m_StartPoint: THREE.Vector2;
m_EndPoint: THREE.Vector2;
m_Center: THREE.Vector2;
m_StartPoint: Vector2;
m_EndPoint: Vector2;
m_Center: Vector2;
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_EndPoint = p2.clone();
let vec: THREE.Vector2 = p2.clone().sub(p1);
let vec: Vector2 = p2.clone().sub(p1);
let len = vec.length();
let an = vec.angle();
this.m_Radius = len / Math.sin(2 * Math.atan(bul)) / 2;
@@ -44,9 +44,9 @@ export class Arc2d
}
//创建轮廓 通过点表和凸度
export function createPath(pts: THREE.Vector2[], buls: number[], shapeOut?: THREE.Shape): THREE.Shape
export function createPath(pts: Vector2[], buls: number[], shapeOut?: Shape): Shape
{
let shape = shapeOut || new THREE.Shape();
let shape = shapeOut || new Shape();
if (pts.length === 0) return shape;
let firstPt = pts[0];
@@ -71,26 +71,24 @@ export function createPath(pts: THREE.Vector2[], buls: number[], shapeOut?: THRE
}
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, material: MeshBasicMaterial)
{
let pts: THREE.Vector2[] = new Array();
let buls: number[] = new Array();
let pts: Vector2[] = [];
let buls: number[] = [];
let boardPts = boardData["Pts"];
let boardBuls = boardData["Buls"];
let boardHeight = boardData["H"];
let boardMat = new THREE.Matrix4();
let matInv: THREE.Matrix4 = new THREE.Matrix4();
let boardMat = new Matrix4();
let matInv: Matrix4 = new Matrix4();
//InitBoardMat
{
let xD = getVec(boardData["XVec"]);
let yD = getVec(boardData["YVec"]);
let ZD = getVec(boardData["ZVec"]);
@@ -98,16 +96,15 @@ export function createBoard(boardData: object)
boardMat.makeBasis(xD, yD, ZD);
boardMat.setPosition(pBase);
matInv.getInverse(boardMat, true);
}
matInv.getInverse(boardMat);
if (boardPts && boardPts.length !== 0)
for (let i = 0; i < boardPts.length; i++)
{
let pt = getVec(boardPts[i]);
if (pt.z !== undefined)
if (boardPts[i].z !== undefined)
pt.applyMatrix4(matInv);
pts.push(new THREE.Vector2(pt.x, pt.y));
pts.push(new Vector2(pt.x, pt.y));
buls.push(boardBuls[i]);
}
else
@@ -128,54 +125,108 @@ export function createBoard(boardData: object)
let extrudeSettings = {
steps: 1,
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.computeBoundingBox();
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 = [createEdge(ext)];
let edges: (LineSegments | Mesh)[] = [createEdge(ext)];
//差集
if (boardData["SubBoardLocal"].length > 0)
if (checkObjectArray(boardData, "SubBoardLocal")
|| checkObjectArray(boardData, "Drillings"))
{
let subBoardList = boardData["SubBoardLocal"].map(d => createBoard(d));
let thisCsg = new ThreeBSP(ext);
if (boardData["SubBoardLocal"])
{
let subBoardList = boardData["SubBoardLocal"].map(d => createBoard(d, material));
for (let br of subBoardList)
{
edges.push(...br.edges);
let subCsg = new ThreeBSP(br.mesh);
thisCsg = thisCsg.subtract(subCsg);
}
}
if (boardData["Drillings"])
{
let dris = boardData["Drillings"];
for (let dri of dris)
{
let geo = new CylinderGeometry(dri.r, dri.r, dri.h, 8);
geo.rotateX(Math.PI * 0.5);
if (dri.f === 0) //0正
geo.translate(dri.x, dri.y, -dri.h * 0.5);
else //1反
geo.translate(dri.x, dri.y, dri.h * 0.5 - boardData["H"]);
geo.applyMatrix4(boardMat);
let mesh = new Mesh(geo, ColorMaterial.GetBasicMaterial(1));
edges.push(mesh);
// let edge = createEdge(geo);
// edge.material = new LineBasicMaterial({ color: new Color(1, 0, 0) });
// edges.push(edge);
// let subCsg = new ThreeBSP(geo);
// thisCsg = thisCsg.subtract(subCsg);
}
}
ext = thisCsg.toGeometry();
}
if (boardData["BoardName"] === "地脚线")
RotateUVs(ext);
let mesh = new THREE.Mesh(ext, boardMaterial);
let mesh = new Mesh(ext, material);
mesh.userData = ZD;
edges.forEach(e => e.userData = ZD);
return { mesh, edges };
}
export function createTemplateBoard(brDataList: any[])
function checkObjectArray(obj: any, key: string)
{
return obj[key] && obj[key].length > 0;
}
export function createTemplateBoard(brDataList: any[], material: MeshBasicMaterial)
{
let meshs = [];
let edgesa = [];
let relations = {
blockMeshMap: new Map<number, number>(),
meshBlockMap: new Map<number, number>()
};
for (let d of brDataList)
{
let { mesh, edges } = createBoard(d);
let { mesh, edges } = createBoard(d, material);
meshs.push(mesh);
edgesa.push(...edges);
if (d['DataID'])
{
relations.blockMeshMap.set(d['DataID'], mesh.id);
relations.meshBlockMap.set(mesh.id, d['DataID']);
}
return { meshs, edgesa };
}
return { meshs, edgesa, relations };
}
export function createEdge(geo: Geometry): LineSegments
{
let edge = new THREE.EdgesGeometry(geo, 1);
let edge = new EdgesGeometry(geo, 1);
return new LineSegments(edge, edgeMaterial);
}

View File

@@ -6,16 +6,19 @@
"outDir": "./dist",
"target": "esnext",
"lib": [
"es2017",
"esnext",
"dom"
],
"types": [
"node"
"node",
"webpack-env",
"webpack-dev-server"
],
"module": "commonjs",
"experimentalDecorators": true
},
"include": [
"./src/**/*"
"./src/**/*",
// "./config/**/*"
]
}

112
utils/copy_type.ts Normal file
View File

@@ -0,0 +1,112 @@
import * as path from 'path';
import * as http from 'https';
import * as fs from "fs";
//修正d.ts中类型定义出现错误的问题,临时修复,因为d.ts并不能完全快速的合并我们的类型修复PR.
/**
* 下载文件到指定的文件地址
*
* @param {string} url
* @param {string} filePath
*/
function downLoadFile(url: string, filePath: string)
{
if (fs.existsSync(filePath))
fs.unlinkSync(filePath);
else
fs.mkdirSync(path.dirname(filePath));
let file = fs.createWriteStream(filePath);
http.get(url, function (response)
{
response.pipe(file);
});
}
/**
* 拷贝文件.
*
* @param {*} source 目标文件的地址
* @param {*} targetFile 拷贝到新的地址
*/
function copyFileSync(source: string, targetFile: string)
{
//if target is a directory a new file with the same name will be created
if (fs.existsSync(targetFile))
{
if (fs.lstatSync(targetFile).isDirectory())
{
targetFile = path.join(targetFile, path.basename(source));
}
}
fs.writeFileSync(targetFile, fs.readFileSync(source));
console.log('targetFile: ', targetFile);
}
function copyFolderRecursiveSync(source, target)
{
let files = [];
//check if folder needs to be created or integrated
let targetFolder = path.join(target, path.basename(source));
if (!fs.existsSync(targetFolder))
{
fs.mkdirSync(targetFolder);
}
//copy
if (fs.lstatSync(source).isDirectory())
{
files = fs.readdirSync(source);
files.forEach(function (file)
{
let curSource = path.join(source, file);
if (fs.lstatSync(curSource).isDirectory())
{
copyFolderRecursiveSync(curSource, targetFolder);
} else
{
copyFileSync(curSource, targetFolder);
}
});
}
}
// copyFolderRecursiveSync("./@types/", "./node_modules/");
function downloadTypes(downFiles)
{
let filePath = path.resolve("./node_modules/@types/" + downFiles.name) + "\\";
console.log('filePath: ', filePath);
for (let file of downFiles.files)
{
console.log(downFiles.urlPath + file);
try
{
downLoadFile(downFiles.urlPath + file, filePath + file);
}
catch (error)
{
console.log('error: ', error);
}
}
}
downloadTypes({
name: "three",
urlPath: "https://gitee.com/BearCAD/DefinitelyType2/raw/master/three/",
files: [
// "index.d.ts",
// "three-core.d.ts",
// "three-outlinepass.d.ts",
// "three-smaapass.d.ts"
]
});
downloadTypes({
name: "jquery",
urlPath: "https://gitee.com/BearCAD/DefinitelyType2/raw/master/jquery/",
files: [
"index.d.ts"
]
});