53 Commits

Author SHA1 Message Date
xief
f60054ca19 修改自定义编号判断 2023-07-31 17:57:16 +08:00
xief
a55986761e 修复autocad显示错误 2023-07-27 11:22:48 +08:00
xief
e5b944539e 修复双面编号问题 2023-07-18 09:19:03 +08:00
xief
27dd548309 替换问题数据源 2023-07-17 16:17:32 +08:00
xief
965ae43070 修复标注错误 2023-07-14 18:00:21 +08:00
xief
36541f1617 更新测试数据 2023-07-14 16:32:07 +08:00
xief
fba276362c 修复自定义编号不显示,添加双面显示 2023-07-14 10:41:41 +08:00
xief
66dbe5869e 修改自定义编号 2023-07-13 14:13:40 +08:00
xief
e70354267b 调整板初始化代码,新增自定义编号 2023-07-13 11:57:28 +08:00
xief
eb736bce84 更新配置 2022-03-04 10:27:23 +08:00
xief
40258eeaf4 Merge branch 'v2' into upgrade 2022-02-16 14:18:01 +08:00
xief
623fa9ac9a 使用新的webcad api进行建模 2022-02-16 13:48:57 +08:00
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
88 changed files with 13886 additions and 2364 deletions

2
.gitignore vendored
View File

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

2
.vscode/launch.json vendored
View File

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

42
.vscode/settings.json vendored
View File

@@ -1,3 +1,43 @@
// 将设置放入此文件中以覆盖默认值和用户设置。
{ {
"editor.formatOnSave": true "typescript.tsdk": "node_modules\\typescript\\lib",
//格式化设置
"editor.tabSize": 4,
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
//格式设置
"typescript.format.placeOpenBraceOnNewLineForFunctions": true,
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": true,
"typescript.referencesCodeLens.enabled": true,
"javascript.format.placeOpenBraceOnNewLineForFunctions": true,
"javascript.format.enable": true,
"files.insertFinalNewline": true,
"typescript.format.semicolons": "insert",
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
//保存时
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
"gitlens.remotes": [
{
"domain": "gitee.com",
"type": "Custom",
"name": "码云",
"protocol": "https",
"urls": {
"repository": "https://gitee.com/cf-fz/${repoPath}",
"branches": "https://gitee.com/cf-fz/${repoPath}/branches",
"branch": "https://gitee.com/cf-fz/${repoPath}/commits/${branch}",
"commit": "https://gitee.com/cf-fz/${repoPath}/commit/${id}",
"file": "https://gitee.com/cf-fz/${repoPath}?path=${file}${line}",
"fileInBranch": "https://gitee.com/cf-fz/${repoPath}/blob/${branch}/${file}${line}",
"fileInCommit": "https://gitee.com/cf-fz/${repoPath}/blob/${id}/${file}${line}",
"fileLine": "#L${line}",
"fileRange": "#L${start}-L${end}"
}
}
],
} }

View File

@@ -1,3 +1,6 @@
# 显示板件的控件 # 显示板件的控件
使用例子请参照项目:[CADViewSample](http://git.cf/cx/CADViewSample) 使用例子请参照项目:[CADViewSample](http://git.cf/cx/CADViewSample)
删除"@types/webpack-merge" 下的 node_modules/webpack 定义 坑爹导致项目跑不起来

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

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

@@ -0,0 +1,93 @@
import * as webpack from 'webpack';
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: /\.worker\.ts$/,
exclude: /node_modules/,
use: [
{ loader: 'worker-loader', },
...TS_LOADER
]
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: TS_LOADER,
},
{
test: /\.[(png)|(obj)|(json)]$/,
loader: "file-loader"
},
//样式加载 css
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
//样式加载 less
{
test: /\.less$/,
use: [
{ loader: "style-loader" },
{ loader: 'css-loader', options: { sourceMap: false } },
{
loader: "less-loader",
options: {
lessOptions: {
strictMath: true,
noIeCompat: true
}
}
}
]
},
//字体加载 blueprint
{
test: /\.(ttf|eot|svg|FBX)$/,
use: {
loader: 'file-loader',
options: { name: 'fonts/[contenthash].[ext]' }
}
},
//字体加载 blueprint
{
test: /\.(woff|woff2|jpg|png)$/,
use: {
loader: 'url-loader',
options: {
name: 'fonts/[contenthash].[ext]',
limit: 5000,
mimetype: 'application/font-woff'
}
}
},
{
test: /\.(glsl|vs|fs)$/,
loader: 'shader-loader'
}
]
},
plugins: [
]
};
export default config;

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

@@ -0,0 +1,24 @@
import path from 'path';
import * as webpack from 'webpack';
import merge from 'webpack-merge';
import common from './webpack.common';
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;

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

@@ -0,0 +1,31 @@
import HtmlWebPackPlugin from "html-webpack-plugin";
import * as webpack from 'webpack';
import merge from 'webpack-merge';
import common from './webpack.common';
const config: webpack.Configuration = merge(
common,
{
mode: "development",
entry: "./src/ViewSrc/index.ts",
output: { pathinfo: false },
devtool: "eval-source-map",
devServer: {
// contentBase: "./dist/",
static: false,
port: 7776,
host: "0.0.0.0",
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, Null = 0,
Pan = 1, Pan = 1,
Rotate = 2, Rotate = 2,
Scale = 3, Scale = 3
} }
export declare class CameraControls { export declare class CameraControls {
m_TouthTypeList: CameraControlState[]; m_TouthTypeList: CameraControlState[];
@@ -31,6 +31,7 @@ export declare class CameraControls {
onTouchEnd: (event: TouchEvent) => void; onTouchEnd: (event: TouchEvent) => void;
onTouchMove: (event: TouchEvent) => void; onTouchMove: (event: TouchEvent) => void;
beginRotate(): void; beginRotate(): void;
lastMiddleClickTime: number;
onMouseDown: (event: MouseEvent) => void; onMouseDown: (event: MouseEvent) => void;
onMouseUp: (event: MouseEvent) => void; onMouseUp: (event: MouseEvent) => void;
onMouseMove: (event: MouseEvent) => void; onMouseMove: (event: MouseEvent) => void;

146
dist/CameraControls.js vendored
View File

@@ -1,15 +1,8 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three"); var THREE = require("three");
const KeyEnum_1 = require("./KeyEnum"); var KeyEnum_1 = require("./KeyEnum");
const three_1 = require("three"); var 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 CameraControlState; var CameraControlState;
(function (CameraControlState) { (function (CameraControlState) {
@@ -18,8 +11,9 @@ var CameraControlState;
CameraControlState[CameraControlState["Rotate"] = 2] = "Rotate"; CameraControlState[CameraControlState["Rotate"] = 2] = "Rotate";
CameraControlState[CameraControlState["Scale"] = 3] = "Scale"; CameraControlState[CameraControlState["Scale"] = 3] = "Scale";
})(CameraControlState = exports.CameraControlState || (exports.CameraControlState = {})); })(CameraControlState = exports.CameraControlState || (exports.CameraControlState = {}));
class CameraControls { var CameraControls = /** @class */ (function () {
constructor(viewer) { function CameraControls(viewer) {
var _this = this;
this.m_TouthTypeList = [CameraControlState.Rotate, CameraControlState.Scale, CameraControlState.Pan]; this.m_TouthTypeList = [CameraControlState.Rotate, CameraControlState.Scale, CameraControlState.Pan];
//起始点击 //起始点击
this.m_StartClickPoint = new THREE.Vector3(); this.m_StartClickPoint = new THREE.Vector3();
@@ -37,36 +31,36 @@ class CameraControls {
* *
* @memberof CameraControls * @memberof CameraControls
*/ */
this.onBlur = () => { this.onBlur = function () {
this.m_KeyDown.clear(); _this.m_KeyDown.clear();
this.m_MouseDown.clear(); _this.m_MouseDown.clear();
}; };
//触屏开始事件 //触屏开始事件
this.onTouchStart = (event) => { this.onTouchStart = function (event) {
this.m_Viewer.UpdateLockTarget(); _this.m_Viewer.UpdateLockTarget();
this.m_StartClickPoint.set(event.touches[0].pageX, event.touches[0].pageY, 0); _this.m_StartClickPoint.set(event.touches[0].pageX, event.touches[0].pageY, 0);
if (event.touches.length < 4) { if (event.touches.length < 4) {
if (event.touches.length == 2) { if (event.touches.length == 2) {
var dx = event.touches[0].pageX - event.touches[1].pageX; var dx = event.touches[0].pageX - event.touches[1].pageX;
var dy = event.touches[0].pageY - event.touches[1].pageY; var dy = event.touches[0].pageY - event.touches[1].pageY;
var distance = Math.sqrt(dx * dx + dy * dy); 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.onTouchEnd = function (event) {
this.m_State = CameraControlState.Null; _this.m_State = CameraControlState.Null;
}; };
this.onTouchMove = (event) => { this.onTouchMove = function (event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
this.m_EndClickPoint.set(event.touches[0].pageX, event.touches[0].pageY, 0); _this.m_EndClickPoint.set(event.touches[0].pageX, event.touches[0].pageY, 0);
let vec = this.m_EndClickPoint.clone().sub(this.m_StartClickPoint); var vec = _this.m_EndClickPoint.clone().sub(_this.m_StartClickPoint);
switch (this.m_State) { switch (_this.m_State) {
case CameraControlState.Pan: case CameraControlState.Pan:
{ {
this.m_Viewer.Pan(vec); _this.m_Viewer.Pan(vec);
break; break;
} }
case CameraControlState.Scale: case CameraControlState.Scale:
@@ -74,46 +68,55 @@ class CameraControls {
var dx = event.touches[0].pageX - event.touches[1].pageX; var dx = event.touches[0].pageX - event.touches[1].pageX;
var dy = event.touches[0].pageY - event.touches[1].pageY; var dy = event.touches[0].pageY - event.touches[1].pageY;
var distance = Math.sqrt(dx * dx + dy * dy); var distance = Math.sqrt(dx * dx + dy * dy);
this.m_DollyEnd.set(0, distance); _this.m_DollyEnd.set(0, distance);
if (distance > this.m_DollyStart.y) { if (distance > _this.m_DollyStart.y) {
this.m_Viewer.Zoom(0.95); _this.m_Viewer.Zoom(0.95);
} }
else { 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; break;
} }
case CameraControlState.Rotate: case CameraControlState.Rotate:
{ {
this.m_Viewer.Rotate(vec.multiplyScalar(2)); _this.m_Viewer.Rotate(vec.multiplyScalar(2));
break; break;
} }
} }
this.m_StartClickPoint.copy(this.m_EndClickPoint); _this.m_StartClickPoint.copy(_this.m_EndClickPoint);
this.m_Viewer.m_bNeedUpdate = true; _this.m_Viewer.m_bNeedUpdate = true;
}; };
//最后一次按中键的时间
this.lastMiddleClickTime = 0;
//鼠标 //鼠标
this.onMouseDown = (event) => { this.onMouseDown = function (event) {
event.preventDefault(); event.preventDefault();
let key = event.button; var key = event.button;
this.m_MouseDown.set(key, true); _this.m_MouseDown.set(key, true);
this.m_StartClickPoint.set(event.offsetX, event.offsetY, 0); _this.m_StartClickPoint.set(event.offsetX, event.offsetY, 0);
switch (key) { switch (key) {
case KeyEnum_1.MouseKey.Left: case KeyEnum_1.MouseKey.Left:
{ {
if (this.m_LeftUseRotate) { if (_this.m_LeftUseRotate) {
this.beginRotate(); _this.beginRotate();
} }
break; break;
} }
case KeyEnum_1.MouseKey.Middle: case KeyEnum_1.MouseKey.Middle:
{ {
if (this.m_KeyDown.get(KeyEnum_1.KeyBoard.Control)) { var curTime = Date.now();
this.beginRotate(); 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 { else {
this.m_State = CameraControlState.Pan; _this.m_State = CameraControlState.Pan;
} }
break; break;
} }
@@ -123,25 +126,25 @@ class CameraControls {
} }
} }
}; };
this.onMouseUp = (event) => { this.onMouseUp = function (event) {
event.preventDefault(); event.preventDefault();
this.m_State = CameraControlState.Null; _this.m_State = CameraControlState.Null;
this.m_MouseDown.set(event.button, false); _this.m_MouseDown.set(event.button, false);
}; };
this.onMouseMove = (event) => { this.onMouseMove = function (event) {
event.preventDefault(); event.preventDefault();
this.m_EndClickPoint.set(event.offsetX, event.offsetY, 0); _this.m_EndClickPoint.set(event.offsetX, event.offsetY, 0);
let changeVec = this.m_EndClickPoint.clone().sub(this.m_StartClickPoint); var changeVec = _this.m_EndClickPoint.clone().sub(_this.m_StartClickPoint);
this.m_StartClickPoint.copy(this.m_EndClickPoint); _this.m_StartClickPoint.copy(_this.m_EndClickPoint);
if ((this.m_LeftUseRotate || if ((_this.m_LeftUseRotate ||
(this.m_KeyDown.get(KeyEnum_1.KeyBoard.Control))) (_this.m_KeyDown.get(KeyEnum_1.KeyBoard.Control)))
&& this.m_State == CameraControlState.Rotate) { && _this.m_State == CameraControlState.Rotate) {
this.m_Viewer.Rotate(changeVec); _this.m_Viewer.Rotate(changeVec);
} }
switch (this.m_State) { switch (_this.m_State) {
case CameraControlState.Pan: case CameraControlState.Pan:
{ {
this.m_Viewer.Pan(changeVec); _this.m_Viewer.Pan(changeVec);
break; break;
} }
case CameraControlState.Rotate: case CameraControlState.Rotate:
@@ -159,30 +162,30 @@ class CameraControls {
* *
* @memberof CameraControls * @memberof CameraControls
*/ */
this.onMouseWheel = (event) => { this.onMouseWheel = function (event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
let pt = new THREE.Vector3(event.offsetX, event.offsetY, 0); 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)); _this.m_Viewer.ScreenToWorld(pt, new three_1.Vector3().setFromMatrixColumn(_this.m_Viewer.m_Camera.Camera.matrixWorld, 2));
if (event.deltaY < 0) { if (event.deltaY < 0) {
this.m_Viewer.Zoom(0.6, pt); _this.m_Viewer.Zoom(0.6, pt);
} }
else if (event.deltaY > 0) { else if (event.deltaY > 0) {
this.m_Viewer.Zoom(1.4, pt); _this.m_Viewer.Zoom(1.4, pt);
} }
}; };
//按键 //按键
this.onKeyDown = (event) => { this.onKeyDown = function (event) {
this.m_KeyDown.set(event.keyCode, true); _this.m_KeyDown.set(event.keyCode, true);
}; };
this.onKeyUp = (event) => { this.onKeyUp = function (event) {
this.m_KeyDown.set(event.keyCode, false); _this.m_KeyDown.set(event.keyCode, false);
}; };
this.m_Viewer = viewer; this.m_Viewer = viewer;
this.m_domElement = viewer.m_Render.domElement.parentElement; this.m_domElement = viewer.m_Render.domElement.parentElement;
this.RegisterEvent(); this.RegisterEvent();
} }
RegisterEvent() { CameraControls.prototype.RegisterEvent = function () {
if (this.m_domElement) { if (this.m_domElement) {
this.m_domElement.addEventListener("mousedown", this.onMouseDown, false); this.m_domElement.addEventListener("mousedown", this.onMouseDown, false);
this.m_domElement.addEventListener("mousemove", this.onMouseMove, false); this.m_domElement.addEventListener("mousemove", this.onMouseMove, false);
@@ -195,11 +198,12 @@ class CameraControls {
this.m_domElement.addEventListener('touchmove', this.onTouchMove, false); this.m_domElement.addEventListener('touchmove', this.onTouchMove, false);
window.addEventListener("blur", this.onBlur, false); window.addEventListener("blur", this.onBlur, false);
} }
} };
beginRotate() { CameraControls.prototype.beginRotate = function () {
this.m_State = CameraControlState.Rotate; this.m_State = CameraControlState.Rotate;
this.m_Viewer.UpdateLockTarget(); this.m_Viewer.UpdateLockTarget();
} };
} return CameraControls;
}());
exports.CameraControls = CameraControls; exports.CameraControls = CameraControls;
//# sourceMappingURL=CameraControls.js.map //# 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_Target;
private m_Direction; private m_Direction;
private m_Orbit; private m_Orbit;
m_MinViewHeight: number;
m_MaxViewHeight: number;
constructor(); constructor();
readonly Aspect: number; get Aspect(): number;
readonly Camera: THREE.Camera; get Camera(): Camera;
ViewHeight: number; get ViewHeight(): number;
set ViewHeight(height: number);
SetSize(width: number, height: number): void; SetSize(width: number, height: number): void;
/** /**
* 平移相机. * 平移相机.
* *
* @param {THREE.Vector3} mouseMove * @param {Vector3} mouseMove
* @memberof CameraControl * @memberof CameraControl
*/ */
Pan(mouseMove: THREE.Vector3): void; Pan(mouseMove: Vector3): void;
Rotate(mouseMove: THREE.Vector3, target: THREE.Vector3): void; Rotate(mouseMove: Vector3, target: Vector3): void;
Zoom(scale: number, scaleCenter?: THREE.Vector3): void; Zoom(scale: number, scaleCenter?: Vector3): void;
ZoomExtensBox3(box3: THREE.Box3): void; ZoomExtensBox3(box3: Box3): void;
LookAt(dir: THREE.Vector3): void; LookAt(dir: Vector3): void;
UpdateUp(): void; UpdateUp(): void;
/** /**
* 根据视口大小,设置相机视口范围. * 根据视口大小,设置相机视口范围.

130
dist/CameraUpdate.js vendored
View File

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

289
dist/ColorPalette.js vendored
View File

@@ -1,7 +1,7 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three"); var three_1 = require("three");
const ColorPalette = [ var ColorPalette = [
[255, 0, 0, 255], [255, 0, 0, 255],
//[255, 255, 255, 255],//----- 0 - ByBlock - White //[255, 255, 255, 255],//----- 0 - ByBlock - White
[255, 0, 0, 255], [255, 0, 0, 255],
@@ -11,276 +11,33 @@ const ColorPalette = [
[0, 255, 255, 255], [0, 255, 255, 255],
[0, 0, 255, 255], [0, 0, 255, 255],
[255, 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 { var ColorMaterial = /** @class */ (function () {
constructor() { } function ColorMaterial() {
static GetLineMaterial(index) { }
ColorMaterial.GetLineMaterial = function (index) {
if (this.m_LineMaterialMap.has(index)) if (this.m_LineMaterialMap.has(index))
return this.m_LineMaterialMap.get(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); this.m_LineMaterialMap.set(index, mat);
return mat; return mat;
} };
static GetColor(index) { ColorMaterial.GetBasicMaterial = function (index) {
let rgb = ColorPalette[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) if (rgb)
return new THREE.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255); return new three_1.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255);
} };
} ColorMaterial.m_LineMaterialMap = new Map();
ColorMaterial.m_LineMaterialMap = new Map(); ColorMaterial.m_BasicMaterialMap = new Map();
return ColorMaterial;
}());
exports.ColorMaterial = ColorMaterial; exports.ColorMaterial = ColorMaterial;
//# sourceMappingURL=ColorPalette.js.map //# 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"; import { Group } from "three";
/** /**
* 标注实体 * 标注实体
*
* @export * @export
* @class Dimension * @class Dimension
* @extends {Group} * @extends {Group}

64
dist/Dimension.js vendored
View File

@@ -1,46 +1,64 @@
"use strict"; "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 }); Object.defineProperty(exports, "__esModule", { value: true });
const three_1 = require("three"); var three_1 = require("three");
const ColorPalette_1 = require("./ColorPalette"); var ColorPalette_1 = require("./ColorPalette");
const Text_1 = require("./Text"); var Text_1 = require("./Text");
const GeUtils_1 = require("./GeUtils"); var GeUtils_1 = require("./GeUtils");
/** /**
* 标注实体 * 标注实体
*
* @export * @export
* @class Dimension * @class Dimension
* @extends {Group} * @extends {Group}
*/ */
class Dimension extends three_1.Group { var Dimension = /** @class */ (function (_super) {
constructor(length, textHeight = 25, mirror = false, mirrorFoot = false) { __extends(Dimension, _super);
super(); function Dimension(length, textHeight, mirror, mirrorFoot) {
let footLength = 60; 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) { if (mirrorFoot) {
footLength = -footLength; 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)); 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)); lineGeo2.vertices.push(new three_1.Vector3(0, footLength), new three_1.Vector3(length, footLength, 0));
let material = ColorPalette_1.ColorMaterial.GetLineMaterial(5); var material = ColorPalette_1.ColorMaterial.GetLineMaterial(5);
let line1 = new three_1.Line(lineGeo, material); var line1 = new three_1.Line(lineGeo, material);
let line2 = new three_1.Line(lineGeo, material); var line2 = new three_1.Line(lineGeo, material);
line2.position.x = length; line2.position.x = length;
let line3 = new three_1.Line(lineGeo2, material); var line3 = new three_1.Line(lineGeo2, material);
let text = new Text_1.DbText(parseFloat(length.toFixed(2)).toString(), textHeight); var text = new Text_1.DbText(parseFloat(length.toFixed(2)).toString(), textHeight);
if (mirror) { if (mirror) {
let roMat = new three_1.Matrix4().makeRotationZ(Math.PI); var roMat = new three_1.Matrix4().makeRotationZ(Math.PI);
text.applyMatrix(roMat); text.applyMatrix4(roMat);
text.applyMatrix(GeUtils_1.MoveMatrix(new three_1.Vector3(length * 0.5, footLength - textHeight * 0.1))); text.applyMatrix4(GeUtils_1.MoveMatrix(new three_1.Vector3(length * 0.5, footLength - textHeight * 0.1)));
} }
else { 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(text);
this.add(line1, line2, line3); _this.add(line1, line2, line3);
return _this;
} }
} return Dimension;
}(three_1.Group));
exports.Dimension = Dimension; exports.Dimension = Dimension;
//# sourceMappingURL=Dimension.js.map //# sourceMappingURL=Dimension.js.map

View File

@@ -1 +1 @@
{"version":3,"file":"Dimension.js","sourceRoot":"","sources":["../src/Dimension.ts"],"names":[],"mappings":";;AAAA,iCAAgE;AAChE,iDAA+C;AAC/C,iCAAgC;AAChC,uCAAuC;AAEvC;;;;;;GAMG;AACH,eAAuB,SAAQ,aAAK;IAGhC,YAAY,MAAc,EAAE,aAAqB,EAAE,EAAE,SAAkB,KAAK,EAAE,aAAsB,KAAK;QAErG,KAAK,EAAE,CAAC;QACR,IAAI,UAAU,GAAG,EAAE,CAAC;QACpB,IAAI,UAAU,EACd;YACI,UAAU,GAAG,CAAC,UAAU,CAAC;SAC5B;QAED,OAAO;QACP,IAAI,OAAO,GAAG,IAAI,gBAAQ,EAAE,CAAC;QAC7B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,eAAO,EAAE,EAAE,IAAI,eAAO,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;QAEpE,OAAO;QACP,IAAI,QAAQ,GAAG,IAAI,gBAAQ,EAAE,CAAC;QAC9B,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,eAAO,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,IAAI,eAAO,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;QAEvF,IAAI,QAAQ,GAAG,4BAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;QAE/C,IAAI,KAAK,GAAG,IAAI,YAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACxC,IAAI,KAAK,GAAG,IAAI,YAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACxC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,MAAM,CAAC;QAE1B,IAAI,KAAK,GAAG,IAAI,YAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAEzC,IAAI,IAAI,GAAG,IAAI,aAAM,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,UAAU,CAAC,CAAC;QAC5E,IAAI,MAAM,EACV;YACI,IAAI,KAAK,GAAG,IAAI,eAAO,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACjD,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YACxB,IAAI,CAAC,WAAW,CAAC,oBAAU,CAAC,IAAI,eAAO,CAAC,MAAM,GAAG,GAAG,EAAE,UAAU,GAAG,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;SAC1F;aAED;YACI,IAAI,CAAC,WAAW,CAAC,oBAAU,CAAC,IAAI,eAAO,CAAC,MAAM,GAAG,GAAG,EAAE,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;SAC7E;QAGD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAEf,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAClC,CAAC;CACJ;AA7CD,8BA6CC"} {"version":3,"file":"Dimension.js","sourceRoot":"","sources":["../src/Dimension.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAAgE;AAChE,+CAA+C;AAC/C,+BAAgC;AAChC,qCAAuC;AAEvC;;;;;GAKG;AACH;IAA+B,6BAAK;IAGhC,mBAAY,MAAc,EAAE,UAAuB,EAAE,MAAuB,EAAE,UAA2B;QAA7E,2BAAA,EAAA,eAAuB;QAAE,uBAAA,EAAA,cAAuB;QAAE,2BAAA,EAAA,kBAA2B;QAAzG,YAEI,iBAAO,SAuCV;QAtCG,IAAI,UAAU,GAAG,EAAE,CAAC;QACpB,IAAI,UAAU,EACd;YACI,UAAU,GAAG,CAAC,UAAU,CAAC;SAC5B;QAED,OAAO;QACP,IAAI,OAAO,GAAG,IAAI,gBAAQ,EAAE,CAAC;QAC7B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,eAAO,EAAE,EAAE,IAAI,eAAO,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;QAEpE,OAAO;QACP,IAAI,QAAQ,GAAG,IAAI,gBAAQ,EAAE,CAAC;QAC9B,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,eAAO,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,IAAI,eAAO,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;QAEvF,IAAI,QAAQ,GAAG,4BAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;QAE/C,IAAI,KAAK,GAAG,IAAI,YAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACxC,IAAI,KAAK,GAAG,IAAI,YAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACxC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,MAAM,CAAC;QAE1B,IAAI,KAAK,GAAG,IAAI,YAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAEzC,IAAI,IAAI,GAAG,IAAI,aAAM,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,UAAU,CAAC,CAAC;QAC5E,IAAI,MAAM,EACV;YACI,IAAI,KAAK,GAAG,IAAI,eAAO,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACjD,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YACzB,IAAI,CAAC,YAAY,CAAC,oBAAU,CAAC,IAAI,eAAO,CAAC,MAAM,GAAG,GAAG,EAAE,UAAU,GAAG,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;SAC3F;aAED;YACI,IAAI,CAAC,YAAY,CAAC,oBAAU,CAAC,IAAI,eAAO,CAAC,MAAM,GAAG,GAAG,EAAE,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;SAC9E;QAGD,KAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAEf,KAAI,CAAC,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"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const three_1 = require("three"); var three_1 = require("three");
const _1 = require("."); var _1 = require(".");
/** /**
* 绘制标注实体 * 绘制标注实体
* *
@@ -10,22 +10,22 @@ const _1 = require(".");
* @returns 标注实体列表 * @returns 标注实体列表
*/ */
function DrawDimension(brList) { function DrawDimension(brList) {
let box = _1.GetBoxArr(brList); var box = _1.GetBoxArr(brList);
let size = box.getSize(new three_1.Vector3()); var size = box.getSize(new three_1.Vector3());
let mat4 = new three_1.Matrix4(); 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.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))); mat4.setPosition(box.min.clone().add(new three_1.Vector3(size.x, -30)));
let textHeight = 45; var textHeight = 45;
let dimx = new _1.Dimension(size.x, textHeight, true); var dimx = new _1.Dimension(size.x, textHeight, true);
dimx.applyMatrix(mat4); dimx.applyMatrix4(mat4);
let dimz = new _1.Dimension(size.z, textHeight); 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.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))); mat4.setPosition(box.max.clone().add(new three_1.Vector3(30, -size.y)));
dimz.applyMatrix(mat4); dimz.applyMatrix4(mat4);
let dimy = new _1.Dimension(size.y, textHeight, true, true); 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.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))); mat4.setPosition(box.max.clone().add(new three_1.Vector3(30, -size.y)));
dimy.applyMatrix(mat4); dimy.applyMatrix4(mat4);
return [dimx, dimy, dimz]; return [dimx, dimy, dimz];
} }
exports.DrawDimension = DrawDimension; exports.DrawDimension = DrawDimension;

View File

@@ -1 +1 @@
{"version":3,"file":"DrawDimension.js","sourceRoot":"","sources":["../src/DrawDimension.ts"],"names":[],"mappings":";;AAAA,iCAAqD;AACrD,wBAAyC;AAGzC;;;;;;GAMG;AACH,uBAA8B,MAAc;IAExC,IAAI,GAAG,GAAG,YAAS,CAAC,MAAM,CAAC,CAAC;IAC5B,IAAI,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,eAAO,EAAE,CAAC,CAAC;IAEtC,IAAI,IAAI,GAAG,IAAI,eAAO,EAAE,CAAC;IACzB,IAAI,CAAC,SAAS,CACV,IAAI,eAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACrB,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,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,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEhE,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,IAAI,IAAI,GAAG,IAAI,YAAS,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;IACnD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAEvB,IAAI,IAAI,GAAG,IAAI,YAAS,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC7C,IAAI,CAAC,SAAS,CACV,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EACrB,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACpB,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CACxB,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,WAAW,CAAC,IAAI,CAAC,CAAC;IAEvB,IAAI,IAAI,GAAG,IAAI,YAAS,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACzD,IAAI,CAAC,SAAS,CACV,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACpB,IAAI,eAAO,CAAC,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,WAAW,CAAC,IAAI,CAAC,CAAC;IAGvB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC;AArCD,sCAqCC"} {"version":3,"file":"DrawDimension.js","sourceRoot":"","sources":["../src/DrawDimension.ts"],"names":[],"mappings":";;AAAA,+BAAqD;AACrD,sBAAyC;AAGzC;;;;;;GAMG;AACH,SAAgB,aAAa,CAAC,MAAc;IAExC,IAAI,GAAG,GAAG,YAAS,CAAC,MAAM,CAAC,CAAC;IAC5B,IAAI,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,eAAO,EAAE,CAAC,CAAC;IAEtC,IAAI,IAAI,GAAG,IAAI,eAAO,EAAE,CAAC;IACzB,IAAI,CAAC,SAAS,CACV,IAAI,eAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACrB,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,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,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEhE,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,IAAI,IAAI,GAAG,IAAI,YAAS,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;IACnD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAExB,IAAI,IAAI,GAAG,IAAI,YAAS,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC7C,IAAI,CAAC,SAAS,CACV,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EACrB,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACpB,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CACxB,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;IAExB,IAAI,IAAI,GAAG,IAAI,YAAS,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACzD,IAAI,CAAC,SAAS,CACV,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACpB,IAAI,eAAO,CAAC,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, Box3, Matrix4, Object3D, Line, Mesh } from 'three';
import { Geometry, Vector, Vector2, Vector3 } from 'three'; export declare const cZeroVec: Vector3;
export declare const cZeroVec: THREE.Vector3; export declare const cXAxis: Vector3;
export declare const cXAxis: THREE.Vector3; export declare const cYAxis: Vector3;
export declare const cYAxis: THREE.Vector3; export declare const cZAxis: Vector3;
export declare const cZAxis: THREE.Vector3;
/** /**
* 旋转一个点,旋转中心在原点 * 旋转一个点,旋转中心在原点
* *
@@ -14,6 +13,7 @@ export declare const cZAxis: THREE.Vector3;
*/ */
export declare function rotatePoint(pt: Vector3, ang: number): Vector3; export declare function rotatePoint(pt: Vector3, ang: number): Vector3;
export declare function equaln(v1: number, v2: number, fuzz?: number): boolean; 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 equal<T extends Vector>(v1: T, v2: T): boolean;
export declare function fixAngle(an: number, fixAngle: number, fuzz?: number): number; 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 {Vector3} v1
* @param {THREE.Vector3} v2 * @param {Vector3} v2
* @param {THREE.Vector3} [ref] 参考向量,如果为世界坐标系则为0,0,1 * @param {Vector3} [ref] 参考向量,如果为世界坐标系则为0,0,1
* @returns * @returns
*/ */
export declare function angleTo(v1: THREE.Vector3, v2: THREE.Vector3, ref?: THREE.Vector3): number; export declare function angleTo(v1: Vector3, v2: Vector3, ref?: Vector3): number;
export declare function getLoocAtUpVec(dir: THREE.Vector3): THREE.Vector3; export declare function getLoocAtUpVec(dir: Vector3): Vector3;
export declare function createLookAtMat4(dir: THREE.Vector3): THREE.Matrix4; export declare function createLookAtMat4(dir: Vector3): Matrix4;
export declare function isParallelTo(v1: THREE.Vector3, v2: THREE.Vector3): boolean; export declare function isParallelTo(v1: Vector3, v2: Vector3): boolean;
export declare function ptToString(v: THREE.Vector3, fractionDigits?: number): string; export declare function ptToString(v: Vector3, fractionDigits?: number): string;
export declare function midPoint(v1: THREE.Vector3, v2: THREE.Vector3): THREE.Vector3; export declare function midPoint(v1: Vector3, v2: Vector3): Vector3;
export declare function midPoint2(v1: THREE.Vector2, v2: THREE.Vector2): THREE.Vector2; export declare function midPoint2(v1: Vector2, v2: Vector2): Vector2;
export declare function midPtCir(v1: THREE.Vector3, v2: THREE.Vector3): THREE.Vector3; export declare function midPtCir(v1: Vector3, v2: Vector3): Vector3;
export declare function GetBox(obj: THREE.Object3D, updateMatrix?: boolean): THREE.Box3; /**
export declare function GetBoxArr(arr: Array<THREE.Object3D>): THREE.Box3; * 获得Three对象的包围盒.
export declare function MoveMatrix(v: THREE.Vector3): THREE.Matrix4; * @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): { export declare function getProjectDist(v1: Vector3, v2: Vector3): {
h: number; h: number;
v: number; v: number;
}; };
export declare function getPtPostion(sp: Vector3, ep: Vector3, c: Vector3, inPt: Vector3): { export declare function getPtPostion(sp: Vector3, ep: Vector3, c: Vector3, inPt: Vector3): {
sp: THREE.Vector3; sp: Vector3;
ep: THREE.Vector3; ep: Vector3;
}; };
export declare function angleAndX(v: Vector3 | Vector2): number; export declare function angleAndX(v: Vector3 | Vector2): number;
/** /**
@@ -63,4 +69,4 @@ export declare function angleAndX(v: Vector3 | Vector2): number;
* @param {number} an * @param {number} an
*/ */
export declare function angleTo2Pi(an: number): number; 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;

156
dist/GeUtils.js vendored
View File

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

1
dist/Material.d.ts vendored
View File

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

8
dist/Material.js vendored
View File

@@ -1,6 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const three_1 = require("three"); var three_1 = require("three");
//板件的材质,使用这个材质避免板件将线覆盖. //板件的材质,使用这个材质避免板件将线覆盖.
exports.boardMaterial = new three_1.MeshBasicMaterial({ exports.boardMaterial = new three_1.MeshBasicMaterial({
color: new three_1.Color(0.8, 0.8, 0.8), color: new three_1.Color(0.8, 0.8, 0.8),
@@ -8,6 +8,12 @@ exports.boardMaterial = new three_1.MeshBasicMaterial({
polygonOffsetFactor: 1, polygonOffsetFactor: 1,
polygonOffsetUnits: 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) }); exports.edgeMaterial = new three_1.LineBasicMaterial({ linewidth: 2, color: new three_1.Color(0, 0, 0) });
//# sourceMappingURL=Material.js.map //# 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"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
class Matrix2 { var Matrix2 = /** @class */ (function () {
constructor() { function Matrix2() {
this.el = [1, 0, 0, 1]; this.el = [1, 0, 0, 1];
} }
set(n11, n12, n21, n22) { Matrix2.prototype.set = function (n11, n12, n21, n22) {
let te = this.el; var te = this.el;
te[0] = n11; te[0] = n11;
te[1] = n21; te[1] = n21;
te[2] = n12; te[2] = n12;
te[3] = n22; te[3] = n22;
return this; return this;
} };
applyVector(vec) { Matrix2.prototype.applyVector = function (vec) {
let x = vec.x, y = vec.y; var x = vec.x, y = vec.y;
let e = this.el; var e = this.el;
vec.x = e[0] * x + e[2] * y; vec.x = e[0] * x + e[2] * y;
vec.y = e[1] * x + e[3] * y; vec.y = e[1] * x + e[3] * y;
return this; return this;
} };
setRotate(theta) { Matrix2.prototype.setRotate = function (theta) {
let el = this.el; var el = this.el;
let c = Math.cos(theta), s = Math.sin(theta); var c = Math.cos(theta), s = Math.sin(theta);
this.set(c, -s, s, c); this.set(c, -s, s, c);
return this; return this;
} };
} return Matrix2;
}());
exports.Matrix2 = Matrix2; exports.Matrix2 = Matrix2;
//# sourceMappingURL=Matrix2.js.map //# 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,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,WAAW,CAAC,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,SAAS,CAAC,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;CACJ;AA9BD,0BA8BC"} {"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,qBAAG,GAAH,UAAI,GAAW,EAAE,GAAW,EAAE,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度时,触发万向锁. * 当x当抬头或者低头到90度时,触发万向锁.
@@ -8,31 +8,32 @@ import * as THREE from "three";
export declare class Orbit { export declare class Orbit {
private m_RoX; private m_RoX;
RoZ: number; RoZ: number;
RoX: number; get RoX(): number;
set RoX(v: number);
/** /**
* 使用旋转角度 计算观察向量 * 使用旋转角度 计算观察向量
* *
* @param {THREE.Vector3} [dir] 引用传入,如果传入,那么就不构造新的向量 * @param {Vector3} [dir] 引用传入,如果传入,那么就不构造新的向量
* @returns {THREE.Vector3} 返回观察向量 * @returns {Vector3} 返回观察向量
* @memberof Orbit * @memberof Orbit
*/ */
UpdateDirection(dir?: THREE.Vector3): THREE.Vector3; UpdateDirection(dir?: Vector3): Vector3;
/** /**
* 使用观察向量,计算旋转角度 * 使用观察向量,计算旋转角度
* *
* @param {THREE.Vector3} dir * @param {Vector3} dir
* @memberof Orbit * @memberof Orbit
*/ */
UpdateRoValue(dir: THREE.Vector3): void; UpdateRoValue(dir: Vector3): void;
/** /**
* *
* 根据观察向量 求头部的向量. * 根据观察向量 求头部的向量.
* *
* @static * @static
* @param {THREE.Vector3} dir * @param {Vector3} dir
* @param {THREE.Vector3} [up] * @param {Vector3} [up]
* @returns {THREE.Vector3} * @returns {Vector3}
* @memberof Orbit * @memberof Orbit
*/ */
static ComputUpDirection(dir: THREE.Vector3, up?: THREE.Vector3): THREE.Vector3; static ComputUpDirection(dir: Vector3, up?: Vector3): Vector3;
} }

63
dist/Orbit.js vendored
View File

@@ -1,81 +1,86 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three"); var three_1 = require("three");
/** /**
* 轨道控制的数学类,观察向量和角度的互相转换 * 轨道控制的数学类,观察向量和角度的互相转换
* 当x当抬头或者低头到90度时,触发万向锁. * 当x当抬头或者低头到90度时,触发万向锁.
* *
* @class Orbit * @class Orbit
*/ */
class Orbit { var Orbit = /** @class */ (function () {
constructor() { function Orbit() {
//抬头低头 正数抬头 负数低头 //抬头低头 正数抬头 负数低头
this.m_RoX = 0; this.m_RoX = 0;
//身体旋转 0为正右边 逆时针旋转 //身体旋转 0为正右边 逆时针旋转
this.RoZ = 0; this.RoZ = 0;
} }
get RoX() { Object.defineProperty(Orbit.prototype, "RoX", {
return this.m_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] 引用传入,如果传入,那么就不构造新的向量 * @param {Vector3} [dir] 引用传入,如果传入,那么就不构造新的向量
* @returns {THREE.Vector3} 返回观察向量 * @returns {Vector3} 返回观察向量
* @memberof Orbit * @memberof Orbit
*/ */
UpdateDirection(dir) { Orbit.prototype.UpdateDirection = function (dir) {
let rtDir = dir ? dir : new THREE.Vector3(); var rtDir = dir ? dir : new three_1.Vector3();
rtDir.z = Math.sin(this.m_RoX); 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.x = Math.cos(this.RoZ) * d;
rtDir.y = Math.sin(this.RoZ) * d; rtDir.y = Math.sin(this.RoZ) * d;
return rtDir; return rtDir;
} };
/** /**
* 使用观察向量,计算旋转角度 * 使用观察向量,计算旋转角度
* *
* @param {THREE.Vector3} dir * @param {Vector3} dir
* @memberof Orbit * @memberof Orbit
*/ */
UpdateRoValue(dir) { Orbit.prototype.UpdateRoValue = function (dir) {
dir.normalize(); dir.normalize();
this.m_RoX = Math.asin(dir.z); this.m_RoX = Math.asin(dir.z);
if (dir.x < 1e-4 && dir.y < 1e-4) if (dir.x < 1e-4 && dir.y < 1e-4)
this.RoZ = Math.PI * 0.5; this.RoZ = Math.PI * 0.5;
else else
this.RoZ = Math.atan2(dir.y, dir.x); this.RoZ = Math.atan2(dir.y, dir.x);
} };
/** /**
* *
* 根据观察向量 求头部的向量. * 根据观察向量 求头部的向量.
* *
* @static * @static
* @param {THREE.Vector3} dir * @param {Vector3} dir
* @param {THREE.Vector3} [up] * @param {Vector3} [up]
* @returns {THREE.Vector3} * @returns {Vector3}
* @memberof Orbit * @memberof Orbit
*/ */
static ComputUpDirection(dir, up) { Orbit.ComputUpDirection = function (dir, up) {
let upRes = up ? up : new THREE.Vector3(); var upRes = up ? up : new three_1.Vector3();
if (dir.equals(new THREE.Vector3(0, 0, -1))) { if (dir.equals(new three_1.Vector3(0, 0, -1))) {
upRes.set(0, 1, 0); upRes.set(0, 1, 0);
} }
else if (dir.equals(new THREE.Vector3(0, 0, 1))) { else if (dir.equals(new three_1.Vector3(0, 0, 1))) {
upRes.set(0, -1, 0); upRes.set(0, -1, 0);
} }
else { else {
let xv = new THREE.Vector3(); var xv = new three_1.Vector3();
xv.crossVectors(new THREE.Vector3(0, 0, 1), dir); xv.crossVectors(new three_1.Vector3(0, 0, 1), dir);
upRes.crossVectors(dir, xv); upRes.crossVectors(dir, xv);
upRes.normalize(); upRes.normalize();
} }
return upRes; return upRes;
} };
} return Orbit;
}());
exports.Orbit = Orbit; exports.Orbit = Orbit;
//# sourceMappingURL=Orbit.js.map //# 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;IAED;;;;;OAKG;IACH,aAAa,CAAC,GAAkB;QAE5B,GAAG,CAAC,SAAS,EAAE,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI;YAC5B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC;;YAEzB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,iBAAiB,CAAC,GAAkB,EAAE,EAAkB;QAE3D,IAAI,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAC1C,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAC3C;YACI,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;SACtB;aACI,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAC/C;YACI,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SACvB;aAED;YACI,IAAI,EAAE,GAAG,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YAC7B,EAAE,CAAC,YAAY,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YACjD,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC5B,KAAK,CAAC,SAAS,EAAE,CAAC;SACrB;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AArFD,sBAqFC"} {"version":3,"file":"Orbit.js","sourceRoot":"","sources":["../src/Orbit.ts"],"names":[],"mappings":";;AAAA,+BAA2C;AAE3C;;;;;GAKG;AACH;IAAA;QAEI,gBAAgB;QACR,UAAK,GAAW,CAAC,CAAC;QAE1B,kBAAkB;QAClB,QAAG,GAAW,CAAC,CAAC;IA+EpB,CAAC;IA7EG,sBAAI,sBAAG;aAAP;YAEI,OAAO,IAAI,CAAC,KAAK,CAAC;QACtB,CAAC;aACD,UAAQ,CAAC;YAEL,IAAI,CAAC,KAAK,GAAG,iBAAS,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC;QACnE,CAAC;;;OAJA;IAMD;;;;;;OAMG;IACH,+BAAe,GAAf,UAAgB,GAAa;QAEzB,IAAI,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,eAAO,EAAE,CAAC;QAEtC,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;IAED;;;;;OAKG;IACH,6BAAa,GAAb,UAAc,GAAY;QAEtB,GAAG,CAAC,SAAS,EAAE,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI;YAC5B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC;;YAEzB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;;;;OASG;IACI,uBAAiB,GAAxB,UAAyB,GAAY,EAAE,EAAY;QAE/C,IAAI,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,eAAO,EAAE,CAAC;QACpC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EACrC;YACI,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;SACtB;aACI,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EACzC;YACI,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SACvB;aAED;YACI,IAAI,EAAE,GAAG,IAAI,eAAO,EAAE,CAAC;YACvB,EAAE,CAAC,YAAY,CAAC,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YAC3C,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC5B,KAAK,CAAC,SAAS,EAAE,CAAC;SACrB;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IACL,YAAC;AAAD,CAAC,AArFD,IAqFC;AArFY,sBAAK"}

6
dist/PlaneExt.d.ts vendored
View File

@@ -1,7 +1,7 @@
import * as THREE from 'three'; import * as THREE from 'three';
import { Vector3, Line3 } from "three"; import { Vector3, Line3, Plane } from "three";
export declare class PlaneExt extends THREE.Plane { export declare class PlaneExt extends Plane {
constructor(normal?: THREE.Vector3, constant?: number); constructor(normal?: Vector3, constant?: number);
intersectLine(line: Line3, optionalTarget?: Vector3, extendLine?: boolean): Vector3; intersectLine(line: Line3, optionalTarget?: Vector3, extendLine?: boolean): Vector3;
intersectRay(ray: THREE.Ray, 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"; "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 }); Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three"); var THREE = require("three");
const three_1 = require("three"); var three_1 = require("three");
class PlaneExt extends THREE.Plane { var PlaneExt = /** @class */ (function (_super) {
constructor(normal, constant) { __extends(PlaneExt, _super);
super(normal, constant); function PlaneExt(normal, constant) {
return _super.call(this, normal, constant) || this;
} }
intersectLine(line, optionalTarget, extendLine) { PlaneExt.prototype.intersectLine = function (line, optionalTarget, extendLine) {
let v1 = new three_1.Vector3(); var v1 = new three_1.Vector3();
let result = optionalTarget || new three_1.Vector3(); var result = optionalTarget || new three_1.Vector3();
let direction = line.delta(v1); var direction = line.delta(v1);
let denominator = this.normal.dot(direction); var denominator = this.normal.dot(direction);
if (denominator === 0) { if (denominator === 0) {
// line is coplanar, return origin // line is coplanar, return origin
if (this.distanceToPoint(line.start) === 0) { 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. // Unsure if this is the correct method to handle this case.
return undefined; 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 you not extendLine,check intersect point in Line
if (!extendLine && (t < 0 || t > 1)) { if (!extendLine && (t < 0 || t > 1)) {
return undefined; return undefined;
} }
return result.copy(direction).multiplyScalar(t).add(line.start); 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 this.intersectLine(line, optionalTarget, extendLine);
} };
} return PlaneExt;
}(three_1.Plane));
exports.PlaneExt = PlaneExt; exports.PlaneExt = PlaneExt;
//# sourceMappingURL=PlaneExt.js.map //# 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;YACD,4DAA4D;YAC5D,OAAO,SAAS,CAAC;SACpB;QAED,IAAI,CAAC,GAAG,CAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,WAAW,CAAC;QACtE,qDAAqD;QACrD,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EACnC;YACI,OAAO,SAAS,CAAC;SACpB;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpE,CAAC;IACD,YAAY,CAAC,GAAc,EAAE,cAAwB,EAAE,UAAoB;QAEvE,UAAU;QACV,IAAI,IAAI,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;QACtF,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;IAChE,CAAC;CACJ;AA1CD,4BA0CC"} {"version":3,"file":"PlaneExt.js","sourceRoot":"","sources":["../src/PlaneExt.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6BAA+B;AAC/B,+BAA8C;AAE9C;IAA8B,4BAAK;IAE/B,kBAAY,MAAgB,EAAE,QAAiB;eAE3C,kBAAM,MAAM,EAAE,QAAQ,CAAC;IAC3B,CAAC;IACD,gCAAa,GAAb,UAAc,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;YACD,4DAA4D;YAC5D,OAAO,SAAS,CAAC;SACpB;QAED,IAAI,CAAC,GAAG,CAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,WAAW,CAAC;QACtE,qDAAqD;QACrD,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EACnC;YACI,OAAO,SAAS,CAAC;SACpB;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpE,CAAC;IACD,+BAAY,GAAZ,UAAa,GAAc,EAAE,cAAwB,EAAE,UAAoB;QAEvE,UAAU;QACV,IAAI,IAAI,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;QACtF,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;IAChE,CAAC;IACL,eAAC;AAAD,CAAC,AA1CD,CAA8B,aAAK,GA0ClC;AA1CY,4BAAQ"}

15
dist/PointPick.js vendored
View File

@@ -1,6 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); 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)} * @returns {(Mesh | undefined)}
*/ */
function PointPick(view, ptx, pty) { function PointPick(view, ptx, pty) {
let raycaster = new three_1.Raycaster(); var raycaster = new three_1.Raycaster();
raycaster.setFromCamera({ raycaster.setFromCamera({
x: (ptx / view._Width) * 2 - 1, x: (ptx / view._Width) * 2 - 1,
y: -(pty / view._Height) * 2 + 1 //y轴相反 y: -(pty / view._Height) * 2 + 1 //y轴相反
}, view.m_Camera.Camera); }, view.m_Camera.Camera);
//https://github.com/mrdoob/three.js/issues/14128 //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); raycaster.ray.origin.set((ptx / view._Width) * 2 - 1, -(pty / view._Height) * 2 + 1, -1).unproject(view.m_Camera.Camera);
let minDis = Infinity; var minDis = Infinity;
let minObj = undefined; var minObj = undefined;
view.m_Scene.children.forEach(obj => { view.m_Scene.children.forEach(function (obj) {
if (obj instanceof three_1.Mesh) { if (obj instanceof three_1.Mesh) {
let intersects = []; var intersects = [];
obj.raycast(raycaster, 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) { if (i.distance < minDis) {
minObj = obj; minObj = obj;
minDis = i.distance; 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,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,GAAG,CAAC,EAAE;QAEhC,IAAI,GAAG,YAAY,YAAI,EACvB;YACI,IAAI,UAAU,GAAgB,EAAE,CAAC;YACjC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;YAEnC,KAAK,IAAI,CAAC,IAAI,UAAU,EACxB;gBACI,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"} {"version":3,"file":"PointPick.js","sourceRoot":"","sources":["../src/PointPick.ts"],"names":[],"mappings":";;AAAA,+BAA2E;AAc3E;;;;;;;;GAQG;AACH,SAAgB,SAAS,CAAC,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,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'; import { Geometry } from 'three';
export declare function RotateUVs(geo: THREE.Geometry): void; export declare function RotateUVs(geo: Geometry): void;

17
dist/RotateUV.js vendored
View File

@@ -1,14 +1,17 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const Matrix2_1 = require("./Matrix2"); var Matrix2_1 = require("./Matrix2");
const THREE = require("three"); var three_1 = require("three");
function RotateUVs(geo) { function RotateUVs(geo) {
let roMat = new Matrix2_1.Matrix2(); var roMat = new Matrix2_1.Matrix2();
roMat.set(0, -1, 1, 0); roMat.set(0, -1, 1, 0);
let addV = new THREE.Vector2(1, 0); var addV = new three_1.Vector2(1, 0);
for (let uvs of geo.faceVertexUvs) { for (var _i = 0, _a = geo.faceVertexUvs; _i < _a.length; _i++) {
for (let uv of uvs) { var uvs = _a[_i];
for (let v of uv) { 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); roMat.applyVector(v);
v.add(addV); 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"; "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 }); Object.defineProperty(exports, "__esModule", { value: true });
const three_1 = require("three"); var three_1 = require("three");
const ColorPalette_1 = require("./ColorPalette"); var ColorPalette_1 = require("./ColorPalette");
const GeUtils_1 = require("./GeUtils"); var GeUtils_1 = require("./GeUtils");
class FontLoaderUtil { var FontLoaderUtil = /** @class */ (function () {
static Load() { function FontLoaderUtil() {
}
FontLoaderUtil.Load = function () {
if (!this.defFont) { if (!this.defFont) {
const f = require("../resources/fonts/helvetiker_regular.typeface.json"); var f = require("../resources/fonts/helvetiker_regular.typeface.json");
let loader = new three_1.FontLoader(); var loader = new three_1.FontLoader();
this.defFont = loader.parse(f); this.defFont = loader.parse(f);
} }
return this.defFont; return this.defFont;
} };
} return FontLoaderUtil;
class DbText extends three_1.Mesh { }());
var DbText = /** @class */ (function (_super) {
__extends(DbText, _super);
/** /**
* *
* 构造一个文本对象,8位点(中心点下面)在0点 * 构造一个文本对象,8位点(中心点下面)在0点
@@ -21,15 +38,19 @@ class DbText extends three_1.Mesh {
* @param {number} height 文本高度 * @param {number} height 文本高度
* @memberof DbText * @memberof DbText
*/ */
constructor(str, height = 5) { function DbText(str, height) {
let font = FontLoaderUtil.Load(); if (height === void 0) { height = 5; }
let shapes = font.generateShapes(str, height, 0.1); var _this = this;
let geometry = new three_1.ShapeGeometry(shapes); var font = FontLoaderUtil.Load();
var shapes = font.generateShapes(str, height);
var geometry = new three_1.ShapeGeometry(shapes);
geometry.computeBoundingBox(); geometry.computeBoundingBox();
super(geometry, ColorPalette_1.ColorMaterial.GetLineMaterial(5)); _this = _super.call(this, geometry, ColorPalette_1.ColorMaterial.GetBasicMaterial(5)) || this;
let center = geometry.boundingBox.getCenter(new three_1.Vector3()); var center = geometry.boundingBox.getCenter(new three_1.Vector3());
this.applyMatrix(GeUtils_1.MoveMatrix(new three_1.Vector3(-center.x, 0, 0))); _this.applyMatrix4(GeUtils_1.MoveMatrix(new three_1.Vector3(-center.x, 0, 0)));
return _this;
} }
} return DbText;
}(three_1.Mesh));
exports.DbText = DbText; exports.DbText = DbText;
//# sourceMappingURL=Text.js.map //# 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,CAAC,CAAC,CAAC,CAAC;SAChC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAED,YAAoB,SAAQ,YAAI;IAC9B;;;;;;OAMG;IACH,YAAY,GAAW,EAAE,SAAiB,CAAC;QACzC,IAAI,IAAI,GAAG,cAAc,CAAC,IAAI,EAAE,CAAC;QAEjC,IAAI,MAAM,GAAkB,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAClE,IAAI,QAAQ,GAAG,IAAI,qBAAa,CAAC,MAAM,CAAC,CAAC;QAEzC,QAAQ,CAAC,kBAAkB,EAAE,CAAC;QAE9B,KAAK,CAAC,QAAQ,EAAE,4BAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;QAElD,IAAI,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,eAAO,EAAE,CAAC,CAAC;QAC3D,IAAI,CAAC,WAAW,CAAC,oBAAU,CAAC,IAAI,eAAO,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,CAAC;CACF;AArBD,wBAqBC"} {"version":3,"file":"Text.js","sourceRoot":"","sources":["../src/Text.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAA8E;AAC9E,+CAA+C;AAC/C,qCAAuC;AAEvC;IAAA;IAaA,CAAC;IAVQ,mBAAI,GAAX;QAEE,IAAI,CAAC,IAAI,CAAC,OAAO,EACjB;YACE,IAAM,CAAC,GAAG,OAAO,CAAC,qDAAqD,CAAC,CAAC;YACzE,IAAI,MAAM,GAAG,IAAI,kBAAU,EAAE,CAAC;YAC9B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAChC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IACH,qBAAC;AAAD,CAAC,AAbD,IAaC;AAED;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; calculateProperties(): this;
clone(): Polygon; clone(): Polygon;
flip(): this; flip(): this;
classifyVertex(vertex: any): 0 | 1 | 2; classifyVertex(vertex: any): 1 | 2 | 0;
classifySide(polygon: any): 0 | 1 | 2 | 3; classifySide(polygon: any): 1 | 3 | 2 | 0;
splitPolygon(polygon: any, coplanar_front: any, coplanar_back: any, front: any, back: any): void; splitPolygon(polygon: any, coplanar_front: any, coplanar_back: any, front: any, back: any): void;
} }
export declare class Vertex { export declare class Vertex {

220
dist/ThreeCSG.js vendored
View File

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

36
dist/Utils.js vendored
View File

@@ -1,23 +1,33 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require("."); var _1 = require(".");
function LoadBoard(view, data) { function dispose(m) {
view.m_Scene.children.forEach(obj => { //@ts-ignore
let geo = obj["geometry"]; if (m.geometry)
if (geo) //@ts-ignore
geo.dispose(); m.geometry.dispose();
}); m.children.forEach(function (o) { return dispose(o); });
view.m_Scene.children.length = 0; }
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); var dims = _1.DrawDimension(meshs);
view.m_Scene.add(...meshs); (_a = view.m_Scene).add.apply(_a, meshs);
view.m_Scene.add(...edgesa); (_b = view.m_Scene).add.apply(_b, edgesa);
view.m_Scene.add(...dims); (_c = view.m_Scene).add.apply(_c, dims);
view.ViewToSwiso(); view.ViewToSwiso();
view.ZoomAll(); view.ZoomAll();
view.Zoom(1.1); view.Zoom(1.1);
return relations;
} }
exports.LoadBoard = LoadBoard; exports.LoadBoard = LoadBoard;
//# sourceMappingURL=Utils.js.map //# 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,KAAK,CAAC,CAAC;IAEhC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IAC3B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;IAC5B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IAE1B,IAAI,CAAC,WAAW,EAAE,CAAC;IACnB,IAAI,CAAC,OAAO,EAAE,CAAC;IACf,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnB,CAAC;AArBD,8BAqBC"} {"version":3,"file":"Utils.js","sourceRoot":"","sources":["../src/Utils.ts"],"names":[],"mappings":";;AACA,sBAA+E;AAE/E,SAAS,OAAO,CAAC,CAAW;IAExB,YAAY;IACZ,IAAI,CAAC,CAAC,QAAQ;QACV,YAAY;QACZ,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAEzB,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,OAAO,CAAC,CAAC,CAAC,EAAV,CAAU,CAAC,CAAC;AACxC,CAAC;AAED,SAAgB,SAAS,CAAC,IAAY,EAAE,IAAW,EAAE,KAAqB;;IAArB,sBAAA,EAAA,YAAqB;IAEtE,IAAI,KAAK,EACT;QACI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;KACpC;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAC9B,IAAI;IACA,IAAA,iCAAwD,EAAtD,gBAAK,EAAE,kBAAM,EAAE,wBAAuC,CAAC;IAE7D,KAAK;IACL,IAAI,IAAI,GAAG,gBAAa,CAAC,KAAK,CAAC,CAAC;IAEhC,CAAA,KAAA,IAAI,CAAC,OAAO,CAAA,CAAC,GAAG,WAAI,KAAK,EAAE;IAC3B,CAAA,KAAA,IAAI,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,IAAI,CAAC,SAAS,GAAG,KAAK,CAAA;AACtB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AAEhC,IAAI,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AAE1C,EAAE,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;AACvB,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC;AACxB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;AAE9B,IAAI,IAAI,GAAG,IAAI,eAAM,CAAC,EAAE,CAAC,CAAC;AAE1B,4BAA4B;AAC5B,IAAI,CAAC,YAAY,CAAC,eAAe,GAAG,CAAC,mCAAkB,CAAC,MAAM,EAAE,mCAAkB,CAAC,KAAK,EAAE,mCAAkB,CAAC,GAAG,CAAC,CAAC;AAClH,eAAe;AACf,IAAI,CAAC,YAAY,CAAC,eAAe,GAAG,CAAC,mCAAkB,CAAC,GAAG,EAAE,mCAAkB,CAAC,KAAK,EAAE,mCAAkB,CAAC,MAAM,CAAC,CAAC;AAElH,IAAI;AACJ,GAAG,CAAC,OAAO,GAAG;IAEV,OAAO,CAAC,IAAI,EAAE,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QACtB,iBAAS,CAAC,IAAI,EAAE,WAAI,CAAC,CAAC;IAC1B,OAAO,CAAC,OAAO,EAAE,CAAC;AACtB,CAAC,CAAA;AAED,IAAI,CAAC,OAAO,GAAG;IAEX,uBAAuB;AAC3B,CAAC,CAAA;AAED,IAAI,CAAC,OAAO,GAAG;IAEX,IAAI,GAAG,GAAG,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAE/B,IAAI,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC,IAAI,eAAO,EAAE,CAAC,CAAC;IACvC,IAAI,CAAC,GAAG,EAAE,CAAC;IACX,KAAgB,UAAqB,EAArB,KAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,EAArB,cAAqB,EAArB,IAAqB,EACrC;QADK,IAAI,GAAG,SAAA;QAER,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ,YAAY,eAAO,EACnD;YACI,IAAI,MAAM,GAAG,gBAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,IAAI,eAAO,EAAE,CAAC,CAAC;YAElD,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAEhC,IAAI,EAAE,GAAG,GAAG,CAAC,QAAmB,CAAC;YACjC,IAAI,EAAE,YAAY,eAAO,EACzB;gBACI,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAClB,4CAA4C;gBAC5C,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aAC/C;SACJ;KACJ;IAGD,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,IAAI,CAAC,GAAG,WAAW,CAAC;QAEhB,KAAmB,UAAC,EAAD,OAAC,EAAD,eAAC,EAAD,IAAC,EACpB;YADS,IAAA,YAAM,EAAL,SAAC,EAAE,SAAC;YAEV,CAAC,CAAC,QAAQ,CAAC,GAAG,CACV,CAAC,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,GAAG,GAAG,GAAG,CAAC,CACtC,CAAC;YACF,CAAC,CAAC,YAAY,EAAE,CAAC;SACpB;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;QAEf,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAE1B,KAAK,EAAE,CAAC;QAER,IAAI,KAAK,KAAK,EAAE;YACZ,aAAa,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,EAAE,EAAE,CAAC,CAAA;AACV,CAAC,CAAA"}

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

190
dist/Viewer.js vendored
View File

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

184
dist/createBoard.js vendored
View File

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

7046
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,20 +1,50 @@
{ {
"name": "cadview", "name": "cadview",
"version": "1.0.3", "version": "1.1.9",
"description": "", "description": "",
"main": "dist/index.js", "main": "src/index.ts",
"types": "dist/index.d.ts", "private": true,
"scripts": { "scripts": {
"build": "tsc" "t": "tsc --noEmit -w",
}, "build": "tsc",
"author": "cx", "umd": "webpack --config ./config/webpack.umd.ts",
"license": "ISC", "dev": "webpack-dev-server --config ./config/webpack.view.ts",
"devDependencies": { "rmtype": "ts-node ./utils/rmtype.ts"
"@types/node": "^10.1.2", },
"@types/three": "^0.92.0", "repository": {
"typescript": "^2.8.3" "type": "git",
}, "url": "http://git.cf/cx/CADViewComponent.git"
"dependencies": { },
"three": "^0.92.0" "author": "cx",
} "license": "ISC",
"devDependencies": {
"@types/hard-source-webpack-plugin": "^1.0.1",
"@types/node": "^13.13.52",
"@types/three": "^0.103.2",
"@types/uglifyjs-webpack-plugin": "^1.1.0",
"@types/webpack": "^4.41.32",
"@types/webpack-env": "^1.18.0",
"awesome-typescript-loader": "^5.2.1",
"cache-loader": "^4.1.0",
"fork-ts-checker-webpack-plugin": "^4.1.6",
"hard-source-webpack-plugin": "^0.13.1",
"html-webpack-plugin": "^4.5.2",
"ts-loader": "^7.0.5",
"ts-node": "^8.10.2",
"typescript": "^4.5.5",
"uglifyjs-webpack-plugin": "^2.2.0",
"webpack": "^5.75.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.11.1",
"webpack-merge": "^5.8.0"
},
"dependencies": {
"@jscad/modeling": "^2.11.0",
"flatbush": "^3.3.0",
"three": "npm:three-cf@0.122.5",
"js-angusj-clipper": "^1.2.1",
"polylabel": "^1.1.0",
"xaop": "^2.0.0",
"webcad_ue4_api": "http://gitea.cf/cx/webcad-ue4-api/archive/3.2.4.tar.gz"
}
} }

View File

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

View File

@@ -1,21 +1,20 @@
import * as THREE from 'three'; import { Box3, Camera, MathUtils, OrthographicCamera, PerspectiveCamera, Vector3 } from 'three';
import { Vector3 } from 'three';
import { Orbit } from './Orbit'; import { Orbit } from './Orbit';
/** /**
* *
* 相机的控制. * 相机的控制.
* ->切换相机 * ->切换相机
* ->设置视口大小 * ->设置视口大小
* ->旋转和移动相机. * ->旋转和移动相机.
* *
* @export * @export
* @class ViewCameraManage * @class ViewCameraManage
*/ */
export class CameraUpdate export class CameraUpdate
{ {
private m_CurCamera: THREE.Camera; private m_CurCamera: Camera;
private m_CameraArray: Map<any, THREE.Camera> = new Map<any, THREE.Camera>(); private m_CameraArray: Map<any, Camera> = new Map<any, Camera>();
//视口的画布大小 //视口的画布大小
private m_Width: number; private m_Width: number;
@@ -24,20 +23,23 @@ export class CameraUpdate
private m_ViewHeight: number = 10; private m_ViewHeight: number = 10;
//观察的位置 //观察的位置
private m_Target: THREE.Vector3 = new THREE.Vector3(); private m_Target: Vector3 = new Vector3();
//观察向量 //观察向量
private m_Direction: THREE.Vector3 = new THREE.Vector3(0, 0, -1); private m_Direction: Vector3 = new Vector3(0, 0, -1);
//观察的轨道. //观察的轨道.
private m_Orbit: Orbit = new Orbit(); private m_Orbit: Orbit = new Orbit();
m_MinViewHeight = 10;
m_MaxViewHeight = 3e4;
constructor() constructor()
{ {
this.m_CameraArray.set(THREE.OrthographicCamera, new THREE.OrthographicCamera(-2, 2, 2, -2, this.m_CameraArray.set(OrthographicCamera, new OrthographicCamera(-2, 2, 2, -2,
-100000, 100000)); -1e6, 1e6));
this.m_CameraArray.set(THREE.PerspectiveCamera, new THREE.PerspectiveCamera(50, 1, 0.01, 10000)); this.m_CameraArray.set(PerspectiveCamera, new PerspectiveCamera(50, 1, 0.01, 10000));
this.m_CurCamera = this.m_CameraArray.get(THREE.OrthographicCamera); this.m_CurCamera = this.m_CameraArray.get(OrthographicCamera);
this.m_Orbit.UpdateRoValue(this.m_Direction); this.m_Orbit.UpdateRoValue(this.m_Direction);
@@ -50,7 +52,7 @@ export class CameraUpdate
return this.m_Width / this.m_Height; return this.m_Width / this.m_Height;
} }
get Camera(): THREE.Camera get Camera(): Camera
{ {
return this.m_CurCamera; return this.m_CurCamera;
} }
@@ -60,7 +62,7 @@ export class CameraUpdate
} }
set ViewHeight(height) 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) SetSize(width: number, height: number)
@@ -71,11 +73,11 @@ export class CameraUpdate
/** /**
* 平移相机. * 平移相机.
* *
* @param {THREE.Vector3} mouseMove * @param {Vector3} mouseMove
* @memberof CameraControl * @memberof CameraControl
*/ */
Pan(mouseMove: THREE.Vector3) Pan(mouseMove: Vector3)
{ {
mouseMove.y *= -1; mouseMove.y *= -1;
mouseMove.multiplyScalar(-this.m_ViewHeight / this.m_Height); mouseMove.multiplyScalar(-this.m_ViewHeight / this.m_Height);
@@ -83,7 +85,7 @@ export class CameraUpdate
this.m_Target.add(mouseMove); this.m_Target.add(mouseMove);
this.Update(); this.Update();
} }
Rotate(mouseMove: THREE.Vector3, target: THREE.Vector3) Rotate(mouseMove: Vector3, target: Vector3)
{ {
this.m_Orbit.RoX -= mouseMove.y * 0.003; this.m_Orbit.RoX -= mouseMove.y * 0.003;
this.m_Orbit.RoZ -= mouseMove.x * 0.003; this.m_Orbit.RoZ -= mouseMove.x * 0.003;
@@ -109,19 +111,19 @@ export class CameraUpdate
this.Update(); this.Update();
} }
Zoom(scale: number, scaleCenter?: THREE.Vector3) Zoom(scale: number, scaleCenter?: Vector3)
{ {
if (this.Camera instanceof THREE.OrthographicCamera) if (this.Camera instanceof OrthographicCamera)
{ {
this.ViewHeight *= scale; this.ViewHeight *= scale;
if (scaleCenter) if (scaleCenter && this.m_ViewHeight < this.m_MaxViewHeight)
{ {
this.m_Target.sub(scaleCenter); this.m_Target.sub(scaleCenter);
this.m_Target.multiplyScalar(scale); this.m_Target.multiplyScalar(scale);
this.m_Target.add(scaleCenter); this.m_Target.add(scaleCenter);
} }
} }
else if (this.Camera instanceof THREE.PerspectiveCamera) else if (this.Camera instanceof PerspectiveCamera)
{ {
let add = scale > 1 ? 1 : -1; let add = scale > 1 ? 1 : -1;
add *= this.Camera.position.distanceTo(this.m_Target) / 10; add *= this.Camera.position.distanceTo(this.m_Target) / 10;
@@ -129,9 +131,9 @@ export class CameraUpdate
} }
this.Update(); this.Update();
} }
ZoomExtensBox3(box3: THREE.Box3) ZoomExtensBox3(box3: Box3)
{ {
if (!box3) return; if (!box3 || box3.isEmpty()) return;
this.Camera.updateMatrixWorld(false); this.Camera.updateMatrixWorld(false);
//变换到相机坐标系 //变换到相机坐标系
box3.applyMatrix4(this.Camera.matrixWorldInverse); box3.applyMatrix4(this.Camera.matrixWorldInverse);
@@ -156,7 +158,7 @@ export class CameraUpdate
} }
this.Update(); this.Update();
} }
LookAt(dir: THREE.Vector3) LookAt(dir: Vector3)
{ {
this.m_Orbit.UpdateRoValue(dir); this.m_Orbit.UpdateRoValue(dir);
this.m_Direction.copy(dir); this.m_Direction.copy(dir);
@@ -170,15 +172,15 @@ export class CameraUpdate
} }
/** /**
* 根据视口大小,设置相机视口范围. * 根据视口大小,设置相机视口范围.
* *
* @returns * @returns
* @memberof CameraControl * @memberof CameraControl
*/ */
Update() Update()
{ {
this.Camera.position.copy(this.m_Target); this.Camera.position.copy(this.m_Target);
if (this.Camera instanceof THREE.OrthographicCamera) if (this.Camera instanceof OrthographicCamera)
{ {
this.Camera.left = this.Aspect * this.m_ViewHeight / -2; this.Camera.left = this.Aspect * this.m_ViewHeight / -2;
this.Camera.right = this.Aspect * this.m_ViewHeight / 2; this.Camera.right = this.Aspect * this.m_ViewHeight / 2;
@@ -187,10 +189,10 @@ export class CameraUpdate
this.Camera.position.sub(this.m_Direction); this.Camera.position.sub(this.m_Direction);
} }
else if (this.Camera instanceof THREE.PerspectiveCamera) else if (this.Camera instanceof PerspectiveCamera)
{ {
this.Camera.aspect = this.Aspect; this.Camera.aspect = this.Aspect;
let distens = (this.m_ViewHeight / 2) / (Math.tan(THREE.Math.degToRad(this.Camera.fov) / 2)); let distens = (this.m_ViewHeight / 2) / (Math.tan(MathUtils.degToRad(this.Camera.fov) / 2));
this.Camera.position.sub(this.m_Direction.clone().multiplyScalar(distens)); this.Camera.position.sub(this.m_Direction.clone().multiplyScalar(distens));
} }
@@ -206,13 +208,13 @@ export class CameraUpdate
SwitchCamera() SwitchCamera()
{ {
if (this.Camera instanceof THREE.OrthographicCamera) if (this.Camera instanceof OrthographicCamera)
{ {
this.m_CurCamera = this.m_CameraArray.get(THREE.PerspectiveCamera); this.m_CurCamera = this.m_CameraArray.get(PerspectiveCamera);
} }
else else
{ {
this.m_CurCamera = this.m_CameraArray.get(THREE.OrthographicCamera); this.m_CurCamera = this.m_CameraArray.get(OrthographicCamera);
} }
this.UpdateUp(); this.UpdateUp();
this.Update(); this.Update();

View File

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

View File

@@ -1,12 +1,12 @@
import { Box3, Vector3, Matrix4, Mesh } from "three"; import { Box3, Matrix4, Mesh, Vector3 } from "three";
import { Dimension, GetBoxArr } from "."; import { Dimension, GetBoxArr } from ".";
/** /**
* 绘制标注实体 * 绘制标注实体
* *
* @export * @export
* @param {Box3} box * @param {Box3} box
* @returns 标注实体列表 * @returns 标注实体列表
*/ */
export function DrawDimension(brList: Mesh[]): Dimension[] export function DrawDimension(brList: Mesh[]): Dimension[]
@@ -24,7 +24,7 @@ export function DrawDimension(brList: Mesh[]): Dimension[]
let textHeight = 45; let textHeight = 45;
let dimx = new Dimension(size.x, textHeight, true); let dimx = new Dimension(size.x, textHeight, true);
dimx.applyMatrix(mat4); dimx.applyMatrix4(mat4);
let dimz = new Dimension(size.z, textHeight); let dimz = new Dimension(size.z, textHeight);
mat4.makeBasis( mat4.makeBasis(
@@ -33,7 +33,7 @@ export function DrawDimension(brList: Mesh[]): Dimension[]
new Vector3(0, -1, 0) new Vector3(0, -1, 0)
) )
mat4.setPosition(box.max.clone().add(new Vector3(30, -size.y))); mat4.setPosition(box.max.clone().add(new Vector3(30, -size.y)));
dimz.applyMatrix(mat4); dimz.applyMatrix4(mat4);
let dimy = new Dimension(size.y, textHeight, true, true); let dimy = new Dimension(size.y, textHeight, true, true);
mat4.makeBasis( mat4.makeBasis(
@@ -42,7 +42,7 @@ export function DrawDimension(brList: Mesh[]): Dimension[]
new Vector3(0, 0, 1) new Vector3(0, 0, 1)
) )
mat4.setPosition(box.max.clone().add(new Vector3(30, -size.y))); mat4.setPosition(box.max.clone().add(new Vector3(30, -size.y)));
dimy.applyMatrix(mat4); dimy.applyMatrix4(mat4);
return [dimx, dimy, dimz]; return [dimx, dimy, dimz];

View File

@@ -1,16 +1,15 @@
import * as THREE from 'three'; import { Geometry, Vector, Vector2, Vector3, Box3, Matrix4, Object3D, Line, Mesh } from 'three';
import { Geometry, Vector, Vector2, Vector3 } from 'three';
import { Matrix2 } from './Matrix2'; import { Matrix2 } from './Matrix2';
export const cZeroVec = new THREE.Vector3(); export const cZeroVec = new Vector3();
export const cXAxis = new THREE.Vector3(1, 0, 0); export const cXAxis = new Vector3(1, 0, 0);
export const cYAxis = new THREE.Vector3(0, 1, 0); export const cYAxis = new Vector3(0, 1, 0);
export const cZAxis = new THREE.Vector3(0, 0, 1); export const cZAxis = new Vector3(0, 0, 1);
/** /**
* 旋转一个点,旋转中心在原点 * 旋转一个点,旋转中心在原点
* *
* @export * @export
* @param {Vector3} pt 点 * @param {Vector3} pt 点
* @param {number} ang 角度. * @param {number} ang 角度.
@@ -26,6 +25,12 @@ export function equaln(v1: number, v2: number, fuzz = 1e-3)
{ {
return Math.abs(v1 - v2) < fuzz; return Math.abs(v1 - v2) < fuzz;
} }
export function equalv3(v1: Vector3, v2: Vector3, fuzz = 1e-8)
{
return equaln(v1.x, v2.x, fuzz) && equaln(v1.y, v2.y, fuzz) && equaln(v1.z, v2.z, fuzz);
}
export function equal<T extends Vector>(v1: T, v2: T) export function equal<T extends Vector>(v1: T, v2: T)
{ {
return v1.distanceToSquared(v2) < 1e-8; return v1.distanceToSquared(v2) < 1e-8;
@@ -50,13 +55,13 @@ export function fixAngle(an: number, fixAngle: number, fuzz: number = 0.1)
/** /**
* 按照极坐标的方式移动一个点 * 按照极坐标的方式移动一个点
* *
* @export * @export
* @template * @template
* @param {T} v 向量(2d,3d) * @param {T} v 向量(2d,3d)
* @param {number} an 角度 * @param {number} an 角度
* @param {number} dis 距离 * @param {number} dis 距离
* @returns {T} * @returns {T}
*/ */
export function polar<T extends Vector2 | Vector3>(v: T, an: number, dis: number): T export function polar<T extends Vector2 | Vector3>(v: T, an: number, dis: number): T
{ {
@@ -76,22 +81,22 @@ export function angle(v: Vector3 | Vector2)
/** /**
* 求两个向量的夹角,顺时针为负,逆时针为正 * 求两个向量的夹角,顺时针为负,逆时针为正
* *
* @param {THREE.Vector3} v1 * @param {Vector3} v1
* @param {THREE.Vector3} v2 * @param {Vector3} v2
* @param {THREE.Vector3} [ref] 参考向量,如果为世界坐标系则为0,0,1 * @param {Vector3} [ref] 参考向量,如果为世界坐标系则为0,0,1
* @returns * @returns
*/ */
export function angleTo(v1: THREE.Vector3, v2: THREE.Vector3, ref: THREE.Vector3 = new THREE.Vector3(0, 0, 1)) export function angleTo(v1: Vector3, v2: Vector3, ref: Vector3 = new Vector3(0, 0, 1))
{ {
if (!ref.equals(new Vector3(0, 0, 1))) if (!ref.equals(new Vector3(0, 0, 1)))
{ {
//任意轴坐标系. 使用相机的构造矩阵. //任意轴坐标系. 使用相机的构造矩阵.
ref.multiplyScalar(-1); ref.multiplyScalar(-1);
let up = getLoocAtUpVec(ref); let up = getLoocAtUpVec(ref);
let refOcs = new THREE.Matrix4(); let refOcs = new Matrix4();
refOcs.lookAt(cZeroVec, ref, up); refOcs.lookAt(cZeroVec, ref, up);
let refOcsInv = new THREE.Matrix4().getInverse(refOcs); let refOcsInv = new Matrix4().getInverse(refOcs);
v1.applyMatrix4(refOcsInv); v1.applyMatrix4(refOcsInv);
v2.applyMatrix4(refOcsInv); v2.applyMatrix4(refOcsInv);
v1.z = 0; v1.z = 0;
@@ -103,7 +108,7 @@ export function angleTo(v1: THREE.Vector3, v2: THREE.Vector3, ref: THREE.Vector3
return cv.z === 0 ? v1.angleTo(v2) : v1.angleTo(v2) * cv.z; return cv.z === 0 ? v1.angleTo(v2) : v1.angleTo(v2) * cv.z;
} }
export function getLoocAtUpVec(dir: THREE.Vector3): THREE.Vector3 export function getLoocAtUpVec(dir: Vector3): Vector3
{ {
if (dir.equals(cZeroVec)) if (dir.equals(cZeroVec))
{ {
@@ -112,37 +117,37 @@ export function getLoocAtUpVec(dir: THREE.Vector3): THREE.Vector3
let norm = dir.clone().normalize(); let norm = dir.clone().normalize();
if (norm.equals(cZAxis)) if (norm.equals(cZAxis))
{ {
return new THREE.Vector3(0, 1, 0); return new Vector3(0, 1, 0);
} }
else if (norm.equals(cZAxis.clone().negate())) else if (norm.equals(cZAxis.clone().negate()))
{ {
return new THREE.Vector3(0, -1, 0); return new Vector3(0, -1, 0);
} }
else else
{ {
let xv: THREE.Vector3 = new THREE.Vector3(); let xv: Vector3 = new Vector3();
xv.crossVectors(cZAxis, norm); xv.crossVectors(cZAxis, norm);
let up = new THREE.Vector3(); let up = new Vector3();
up.crossVectors(norm, xv); up.crossVectors(norm, xv);
return up; return up;
} }
} }
export function createLookAtMat4(dir: THREE.Vector3): THREE.Matrix4 export function createLookAtMat4(dir: Vector3): Matrix4
{ {
let up = getLoocAtUpVec(dir); let up = getLoocAtUpVec(dir);
let mat = new THREE.Matrix4(); let mat = new Matrix4();
mat.lookAt(cZeroVec, dir, up); mat.lookAt(cZeroVec, dir, up);
return mat; return mat;
} }
export function isParallelTo(v1: THREE.Vector3, v2: THREE.Vector3) export function isParallelTo(v1: Vector3, v2: Vector3)
{ {
return v1.clone().cross(v2).lengthSq() < 1e-9; return v1.clone().cross(v2).lengthSq() < 1e-9;
} }
export function ptToString(v: THREE.Vector3, fractionDigits: number = 3): string export function ptToString(v: Vector3, fractionDigits: number = 3): string
{ {
return v.toArray().map(o => return v.toArray().map(o =>
{ {
@@ -150,16 +155,16 @@ export function ptToString(v: THREE.Vector3, fractionDigits: number = 3): string
}).join(",") }).join(",")
} }
export function midPoint(v1: THREE.Vector3, v2: THREE.Vector3): THREE.Vector3 export function midPoint(v1: Vector3, v2: Vector3): Vector3
{ {
return v1.clone().add(v2).multiplyScalar(0.5); return v1.clone().add(v2).multiplyScalar(0.5);
} }
export function midPoint2(v1: THREE.Vector2, v2: THREE.Vector2): THREE.Vector2 export function midPoint2(v1: Vector2, v2: Vector2): Vector2
{ {
return v1.clone().add(v2).multiplyScalar(0.5); return v1.clone().add(v2).multiplyScalar(0.5);
} }
export function midPtCir(v1: THREE.Vector3, v2: THREE.Vector3) export function midPtCir(v1: Vector3, v2: Vector3)
{ {
let baseline = new Vector3(1, 0, 0); let baseline = new Vector3(1, 0, 0);
let outLine = v2.clone().sub(v1); let outLine = v2.clone().sub(v1);
@@ -168,56 +173,52 @@ export function midPtCir(v1: THREE.Vector3, v2: THREE.Vector3)
return v1.clone().add(midLine); 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 (updateMatrix) obj.updateMatrixWorld(false);
if (obj.hasOwnProperty("geometry")) if (!obj.visible) return box;
obj.traverse(o =>
{ {
let geo = obj["geometry"]; //因为实体Erase时,实体仍然保存在Scene中.
if (geo instanceof THREE.Geometry || geo instanceof THREE.BufferGeometry) if (o.visible === false)
return;
//@ts-ignore
let geo = o.geometry as BufferGeometry;
if (geo)
{ {
if (!geo.boundingBox) if (!geo.boundingBox)
geo.computeBoundingBox(); geo.computeBoundingBox();
return geo.boundingBox.clone().applyMatrix4(obj.matrixWorld); box.union(geo.boundingBox.clone().applyMatrix4(o.matrixWorld));
} }
} });
else if (obj.children.length > 0)
{ return box;
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 box;
{
return GetBox(o);
}).filter(o =>
{
return o;
}).reduce((sumBox: THREE.Box3, objBox: THREE.Box3) =>
{
return sumBox.union(objBox)
}, new THREE.Box3());
} }
export function MoveMatrix(v: THREE.Vector3): THREE.Matrix4 export function MoveMatrix(v: Vector3): Matrix4
{ {
let mat = new THREE.Matrix4(); let mat = new Matrix4();
mat.makeTranslation(v.x, v.y, v.z); mat.makeTranslation(v.x, v.y, v.z);
return mat; return mat;
} }
@@ -269,9 +270,9 @@ export function angleAndX(v: Vector3 | Vector2)
} }
/** /**
* 将角度调整为0-2pi之间 * 将角度调整为0-2pi之间
* *
* @export * @export
* @param {number} an * @param {number} an
*/ */
export function angleTo2Pi(an: number) export function angleTo2Pi(an: number)
{ {
@@ -279,9 +280,9 @@ export function angleTo2Pi(an: number)
if (an < 0) an += Math.PI * 2 if (an < 0) an += Math.PI * 2
return an; return an;
} }
export function updateGeometry(l: THREE.Line | THREE.Mesh, geometry: Geometry) export function updateGeometry(l: Line | Mesh, geometry: Geometry)
{ {
let geo = l.geometry as THREE.Geometry; let geo = l.geometry as Geometry;
geo.dispose(); geo.dispose();
l.geometry = geometry; l.geometry = geometry;
geometry.verticesNeedUpdate = true; geometry.verticesNeedUpdate = true;

View File

@@ -8,6 +8,13 @@ export let boardMaterial = new MeshBasicMaterial({
polygonOffsetUnits: 1 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) }); export let edgeMaterial = new LineBasicMaterial({ linewidth: 2, color: new Color(0, 0, 0) });

View File

@@ -1,9 +1,9 @@
import * as THREE from "three"; import { MathUtils, Vector3 } from "three";
/** /**
* 轨道控制的数学类,观察向量和角度的互相转换 * 轨道控制的数学类,观察向量和角度的互相转换
* 当x当抬头或者低头到90度时,触发万向锁. * 当x当抬头或者低头到90度时,触发万向锁.
* *
* @class Orbit * @class Orbit
*/ */
export class Orbit export class Orbit
@@ -20,19 +20,19 @@ export class Orbit
} }
set RoX(v) set RoX(v)
{ {
this.m_RoX = THREE.Math.clamp(v, Math.PI * -0.5, Math.PI * 0.5); this.m_RoX = MathUtils.clamp(v, Math.PI * -0.5, Math.PI * 0.5);
} }
/** /**
* 使用旋转角度 计算观察向量 * 使用旋转角度 计算观察向量
* *
* @param {THREE.Vector3} [dir] 引用传入,如果传入,那么就不构造新的向量 * @param {Vector3} [dir] 引用传入,如果传入,那么就不构造新的向量
* @returns {THREE.Vector3} 返回观察向量 * @returns {Vector3} 返回观察向量
* @memberof Orbit * @memberof Orbit
*/ */
UpdateDirection(dir?: THREE.Vector3): THREE.Vector3 UpdateDirection(dir?: Vector3): Vector3
{ {
let rtDir = dir ? dir : new THREE.Vector3(); let rtDir = dir ? dir : new Vector3();
rtDir.z = Math.sin(this.m_RoX); rtDir.z = Math.sin(this.m_RoX);
@@ -47,11 +47,11 @@ export class Orbit
/** /**
* 使用观察向量,计算旋转角度 * 使用观察向量,计算旋转角度
* *
* @param {THREE.Vector3} dir * @param {Vector3} dir
* @memberof Orbit * @memberof Orbit
*/ */
UpdateRoValue(dir: THREE.Vector3) UpdateRoValue(dir: Vector3)
{ {
dir.normalize(); dir.normalize();
this.m_RoX = Math.asin(dir.z); this.m_RoX = Math.asin(dir.z);
@@ -62,30 +62,30 @@ export class Orbit
} }
/** /**
* *
* 根据观察向量 求头部的向量. * 根据观察向量 求头部的向量.
* *
* @static * @static
* @param {THREE.Vector3} dir * @param {Vector3} dir
* @param {THREE.Vector3} [up] * @param {Vector3} [up]
* @returns {THREE.Vector3} * @returns {Vector3}
* @memberof Orbit * @memberof Orbit
*/ */
static ComputUpDirection(dir: THREE.Vector3, up?: THREE.Vector3): THREE.Vector3 static ComputUpDirection(dir: Vector3, up?: Vector3): Vector3
{ {
let upRes = up ? up : new THREE.Vector3(); let upRes = up ? up : new Vector3();
if (dir.equals(new THREE.Vector3(0, 0, -1))) if (dir.equals(new Vector3(0, 0, -1)))
{ {
upRes.set(0, 1, 0); upRes.set(0, 1, 0);
} }
else if (dir.equals(new THREE.Vector3(0, 0, 1))) else if (dir.equals(new Vector3(0, 0, 1)))
{ {
upRes.set(0, -1, 0); upRes.set(0, -1, 0);
} }
else else
{ {
let xv = new THREE.Vector3(); let xv = new Vector3();
xv.crossVectors(new THREE.Vector3(0, 0, 1), dir); xv.crossVectors(new Vector3(0, 0, 1), dir);
upRes.crossVectors(dir, xv); upRes.crossVectors(dir, xv);
upRes.normalize(); upRes.normalize();
} }

View File

@@ -1,9 +1,9 @@
import * as THREE from 'three'; 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); super(normal, constant);
} }

View File

@@ -1,14 +1,14 @@
import { Matrix2 } from './Matrix2'; 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(); let roMat = new Matrix2();
roMat.set(0, -1, roMat.set(0, -1,
1, 0); 1, 0);
let addV = new THREE.Vector2(1, 0); let addV = new Vector2(1, 0);
for (let uvs of geo.faceVertexUvs) for (let uvs of geo.faceVertexUvs)
{ {

185
src/SimpleBoard.ts Normal file
View File

@@ -0,0 +1,185 @@
import { CylinderGeometry, LineSegments, Matrix4, Mesh, MeshBasicMaterial, Vector2, Vector3 } from "three";
import { ExtrudeSolid, Polyline, boardUVGenerator2 } from "webcad_ue4_api";
import { ColorMaterial } from "./ColorPalette";
import { edgeMaterial } from "./Material";
import { DbText } from "./Text";
function getVec(data: object): Vector3
{
return new Vector3(data["x"], data["y"], data["z"]);
}
enum BoardType
{
Layer = 0,
Vertical = 1,
Behind = 2
}
export class SimpleBoard
{
BoardName: string;
boardPts: any[];
boardBuls: any[];
xD: Vector3;
yD: Vector3;
zD: Vector3;
height: number;
width: number;
thickness: number;
pBase: Vector3;
SubBoardLocal: any[];
Drillings: any[];
DataID: number;
_BoardType: BoardType;
_CustomNumber: string;
constructor(boardData: any)
{
this.boardPts = boardData["Pts"];
this.boardBuls = boardData["Buls"];
this.pBase = getVec(boardData["BasePoint"]);
this.xD = getVec(boardData["XVec"]);
this.yD = getVec(boardData["YVec"]);
this.zD = getVec(boardData["ZVec"]);
this.SubBoardLocal = boardData["SubBoardLocal"] ?? [];
this.Drillings = boardData["Drillings"] ?? [];
this.height = boardData["L"];
this.width = boardData["W"];
this.thickness = boardData["H"];
this.BoardName = boardData["BoardName"];
this.DataID = boardData['DataID'];
this._BoardType = boardData['BoardType'];
this._CustomNumber = boardData['CustomNumber'];
}
public Conver2Ext(): ExtrudeSolid
{
let pts: Vector2[] = [];
let buls: number[] = [];
let boardMat = new Matrix4();
let matInv: Matrix4 = new Matrix4();
//InitBoardMat
this.pBase.add(this.zD.clone().multiplyScalar(-this.thickness));
boardMat.makeBasis(this.xD, this.yD, this.zD);
boardMat.setPosition(this.pBase);
matInv.getInverse(boardMat);
if (this.boardPts && this.boardPts.length !== 0)
for (let i = 0; i < this.boardPts.length; i++)
{
let pt = getVec(this.boardPts[i]);
if (this.boardPts[i].z !== undefined)
pt.applyMatrix4(matInv);
pts.push(new Vector2(pt.x, pt.y));
buls.push(this.boardBuls[i]);
}
else
{
pts.push(new Vector2(0, 0),
new Vector2(this.width, 0),
new Vector2(this.width, this.height),
new Vector2(0, this.height),
new Vector2(0, 0)
);
buls.push(0, 0, 0, 0, 0);
}
let ext = new ExtrudeSolid();
ext.OCSNoClone.copy(boardMat);
let pl = new Polyline(pts.map((p, i) => { return { pt: p, bul: buls[i] }; }));
ext.Thickness = this.thickness;
ext.ContourCurve = pl;
if (this.SubBoardLocal.length > 0)
ext.Grooves.push(...this.SubBoardLocal.map(sub => new SimpleBoard(sub).Conver2Ext()));
return ext;
}
createBoard(boardMaterial: MeshBasicMaterial)
{
let ext = this.Conver2Ext();
if (this.BoardName === "地脚线")
Object.defineProperty(ext, "UCGenerator",
{
get: function ()
{
return boardUVGenerator2;
},
});
//板件被镜像时.
// if (!equalv3(xD.clone().cross(yD), ZD))
// {
// for (let f of ext.faces)
// [f.a, f.c] = [f.c, f.a];
// }
//边
let edges: (LineSegments | Mesh)[] = [new LineSegments(ext.EdgeGeometry, edgeMaterial)];
edges[0].applyMatrix4(ext.OCSNoClone);
if (this.Drillings.length > 0)
{
let dris = this.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 + this.thickness);
else //1反
geo.translate(dri.x, dri.y, dri.h * 0.5);
geo.applyMatrix4(ext.OCSNoClone);
let mesh = new Mesh(geo, ColorMaterial.GetBasicMaterial(1));
edges.push(mesh);
}
}
let mesh = new Mesh(ext.MeshGeometry, boardMaterial);
mesh.userData = ext.Normal;
edges.forEach(e => e.userData = ext.Normal);
// 自定义编号
if (this._CustomNumber)
{
mesh.add(this.createCustomNo());
}
mesh.applyMatrix4(ext.OCSNoClone);
mesh.updateWorldMatrix(false, true);
return { mesh, edges };
}
private createCustomNo()
{
let text = new DbText(this._CustomNumber?.toString(), 100);
let position = new Vector3(this.width * 0.5, this.height * 0.5, this.thickness * 0.5);
if (this._BoardType === BoardType.Layer)
{
text.applyMatrix4(new Matrix4().makeRotationZ(-Math.PI / 2).setPosition(position));
}
else
{
text.applyMatrix4(new Matrix4().setPosition(position));
}
// text.CreateDoubleMesh(this._BoardType === BoardType.Layer);
return text;
}
}

View File

@@ -1,38 +1,59 @@
import { Font, FontLoader, Mesh, ShapeGeometry, Vector3 } from "three"; import { Font, FontLoader, Matrix4, Mesh, Shape, ShapeGeometry, Vector3 } from "three";
import { ColorMaterial } from "./ColorPalette"; import { ColorMaterial } from "./ColorPalette";
import { MoveMatrix } from "./GeUtils"; import { MoveMatrix } from "./GeUtils";
import { XAxis, XAxisN, YAxis, YAxisN, ZAxisN } from "./Utils";
class FontLoaderUtil { class FontLoaderUtil
private static defFont: Font; {
static Load(): Font { private static defFont: Font;
if (!this.defFont) { static Load(): Font
const f = require("../resources/fonts/helvetiker_regular.typeface.json"); {
let loader = new FontLoader(); if (!this.defFont)
this.defFont = loader.parse(f); {
const f = require("../resources/fonts/helvetiker_regular.typeface.json");
let loader = new FontLoader();
this.defFont = loader.parse(f);
}
return this.defFont;
} }
return this.defFont;
}
} }
export class DbText extends Mesh { export class DbText extends Mesh
/** {
* /**
* 构造一个文本对象,8位点(中心点下面)在0点 *
* @param {string} str 数字字符串 * 构造一个文本对象,8位点(中心点下面)在0点
* @param {number} height 文本高度 * @param {string} str 数字字符串
* @memberof DbText * @param {number} height 文本高度
*/ * @memberof DbText
constructor(str: string, height: number = 5) { */
let font = FontLoaderUtil.Load(); 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); let geometry = new ShapeGeometry(shapes);
geometry.computeBoundingBox(); geometry.computeBoundingBox();
super(geometry, ColorMaterial.GetLineMaterial(5)); super(geometry, ColorMaterial.GetBasicMaterial(5));
let center = geometry.boundingBox.getCenter(new Vector3()); let center = geometry.boundingBox.getCenter(new Vector3());
this.applyMatrix(MoveMatrix(new Vector3(-center.x, 0, 0))); this.applyMatrix4(MoveMatrix(new Vector3(-center.x, 0, 0)));
} }
CreateDoubleMesh(IsFsText: boolean)
{
let mesh2 = new Mesh(this.geometry, ColorMaterial.GetBasicMaterial(5));
//左右视图时应该这样,俯视图是X,-Y,-Z(y+=(xxx)
if (IsFsText)
{
mesh2.applyMatrix4(new Matrix4().makeBasis(XAxis, YAxisN, ZAxisN));
}
else
{
mesh2.applyMatrix4(new Matrix4().makeBasis(XAxisN, YAxis, ZAxisN));
}
this.add(mesh2);
}
} }

View File

@@ -71,32 +71,8 @@ export class ThreeBSP
vertex = new Vertex(vertex.x, vertex.y, vertex.z, face.vertexNormals[2], uvs); vertex = new Vertex(vertex.x, vertex.y, vertex.z, face.vertexNormals[2], uvs);
vertex.applyMatrix4(this.matrix); vertex.applyMatrix4(this.matrix);
polygon.vertices.push(vertex); polygon.vertices.push(vertex);
} else if (typeof THREE.Face4) }
{ else
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; throw 'Invalid face type at index ' + i;
} }

View File

@@ -1,17 +1,35 @@
import { Viewer, createTemplateBoard, createEdge, DrawDimension } from "."; import { Object3D, Vector3 } from "three";
import { Geometry } from "three"; import { DrawDimension, Viewer, createTemplateBoard } from ".";
export function LoadBoard(view: Viewer, data: any[]) export const XAxis = new Vector3(1, 0, 0);
export const XAxisN = new Vector3(-1, 0, 0);
export const YAxis = new Vector3(0, 1, 0);
export const YAxisN = new Vector3(0, -1, 0);
export const ZAxis = new Vector3(0, 0, 1);
export const ZAxisN = new Vector3(0, 0, -1);
function dispose(m: Object3D)
{ {
view.m_Scene.children.forEach(obj => //@ts-ignore
{ if (m.geometry)
let geo = obj["geometry"] as Geometry; //@ts-ignore
if (geo) geo.dispose(); m.geometry.dispose();
})
view.m_Scene.children.length = 0;
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); let dims = DrawDimension(meshs);
@@ -22,4 +40,6 @@ export function LoadBoard(view: Viewer, data: any[])
view.ViewToSwiso(); view.ViewToSwiso();
view.ZoomAll(); view.ZoomAll();
view.Zoom(1.1); view.Zoom(1.1);
return relations;
} }

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

@@ -0,0 +1,197 @@
[
{
"DataID": 3996018,
"OrderNo": 20230727027642,
"L": 800,
"W": 600,
"H": 18,
"BoardName": "层板",
"Grain": 0,
"BoardType": 0,
"CustomNumber": "",
"BasePoint": {
"x": 1877.02062480031,
"y": -1.77635683940025e-13,
"z": 823.651271182857
},
"XVec": {
"x": 2.22044604925031e-16,
"y": 1,
"z": 0
},
"YVec": {
"x": -1,
"y": 2.22044604925031e-16,
"z": 0
},
"ZVec": {
"x": 0,
"y": 0,
"z": 1
},
"Pts": [],
"Buls": [],
"SubBoardLocal": [],
"SubBoardAssoc": [],
"Drillings": [
{
"x": 50,
"y": 766,
"r": 7.5,
"h": 13.5,
"f": 0
},
{
"x": 300,
"y": 766,
"r": 7.5,
"h": 13.5,
"f": 0
},
{
"x": 550,
"y": 766,
"r": 7.5,
"h": 13.5,
"f": 0
},
{
"x": 550,
"y": 34,
"r": 7.5,
"h": 13.5,
"f": 0
},
{
"x": 300,
"y": 34,
"r": 7.5,
"h": 13.5,
"f": 0
},
{
"x": 50,
"y": 34,
"r": 7.5,
"h": 13.5,
"f": 0
}
]
},
{
"DataID": 3996019,
"OrderNo": 20230727027642,
"L": 1200,
"W": 600,
"H": 18,
"BoardName": "右侧板",
"Grain": 0,
"BoardType": 0,
"CustomNumber": "",
"BasePoint": {
"x": 1895.02062480031,
"y": 0,
"z": 214.651271182857
},
"XVec": {
"x": 4.93038065763132e-32,
"y": 1,
"z": -2.22044604925031e-16
},
"YVec": {
"x": -2.22044604925031e-16,
"y": 2.22044604925031e-16,
"z": 1
},
"ZVec": {
"x": 1,
"y": 0,
"z": 2.22044604925031e-16
},
"Pts": [],
"Buls": [],
"SubBoardLocal": [],
"SubBoardAssoc": [],
"Drillings": [
{
"x": 550,
"y": 600,
"r": 5,
"h": 13.5,
"f": 1
},
{
"x": 300,
"y": 600,
"r": 5,
"h": 13.5,
"f": 1
},
{
"x": 50,
"y": 600,
"r": 5,
"h": 13.5,
"f": 1
}
]
},
{
"DataID": 3996020,
"OrderNo": 20230727027642,
"L": 1200,
"W": 600,
"H": 18,
"BoardName": "左侧板",
"Grain": 0,
"BoardType": 0,
"CustomNumber": "",
"BasePoint": {
"x": 1077.02062480031,
"y": 0,
"z": 214.651271182857
},
"XVec": {
"x": 4.93038065763132e-32,
"y": 1,
"z": -2.22044604925031e-16
},
"YVec": {
"x": -2.22044604925031e-16,
"y": 2.22044604925031e-16,
"z": 1
},
"ZVec": {
"x": 1,
"y": 0,
"z": 2.22044604925031e-16
},
"Pts": [],
"Buls": [],
"SubBoardLocal": [],
"SubBoardAssoc": [],
"Drillings": [
{
"x": 50,
"y": 600,
"r": 5,
"h": 13.5,
"f": 0
},
{
"x": 300,
"y": 600,
"r": 5,
"h": 13.5,
"f": 0
},
{
"x": 550,
"y": 600,
"r": 5,
"h": 13.5,
"f": 0
}
]
}
]

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 { 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();
let data = require("./data.json");
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,194 +1,243 @@
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 { CameraUpdate } from "./CameraUpdate";
import { GetBox, GetBoxArr, cZeroVec } from "./GeUtils"; import { ColorMaterial } from "./ColorPalette";
import { cZeroVec, GetBox, GetBoxArr } from "./GeUtils";
import { PlaneExt } from "./PlaneExt"; 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 export class Viewer
{ {
m_LookTarget: any; m_LookTarget: any;
m_Camera: CameraUpdate = new CameraUpdate(); m_Camera: CameraUpdate = new CameraUpdate();
m_bNeedUpdate: boolean = true; m_CameraCtrl: CameraControls;
m_Render: THREE.WebGLRenderer;//渲染器 //暂时只用这个类型 m_bNeedUpdate: boolean = true;
m_DomEl: HTMLElement; //画布容器 m_Render: WebGLRenderer;//渲染器 //暂时只用这个类型
m_DomEl: HTMLElement; //画布容器
_Height: number; _Height: number;
_Width: number; _Width: number;
m_Scene: THREE.Scene = new THREE.Scene(); m_Scene: Scene = new Scene();
//构造 _Settings = new ViewerSettings();
constructor(canvasContainer: HTMLElement) /**
*
* @param {HTMLElement} canvasContainer 可以传入一个div或者一个画布
* @memberof Viewer
*/
constructor(canvasContainer: HTMLElement, setupAction: (settings: ViewerSettings) => void = null)
{
if (setupAction)
{ {
this.m_DomEl = canvasContainer; setupAction(this._Settings);
this.initRender(canvasContainer);
this.OnSize();
this.StartRender();
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;
}
})
} }
//初始化render this.m_DomEl = canvasContainer;
initRender(canvasContainer: HTMLElement) this.initRender(canvasContainer);
this.OnSize();
this.StartRender();
this.m_CameraCtrl = new CameraControls(this);
window.addEventListener("resize", () =>
{ {
this.m_Render = new THREE.WebGLRenderer( this.OnSize();
{ });
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:最大灯光数
}
);
//加到画布
canvasContainer.appendChild(this.m_Render.domElement);
this.m_Render.autoClear = true; this.m_Render.domElement.addEventListener("mousemove", (e: MouseEvent) =>
{
this.SelectByPoint(e.offsetX, e.offsetY);
})
}
//如果设置那么它希望所有的纹理和颜色都是预乘的伽玛。默认值为false。 //初始化render
// this.m_Render.gammaInput = true; initRender(canvasContainer: HTMLElement)
// this.m_Render.gammaOutput = true; {
// this.m_Render.shadowMap.enabled = true; let params: WebGLRendererParameters = {
// this.m_Render.toneMapping = THREE.ReinhardToneMapping; antialias: true,//antialias:true/false是否开启反锯齿
//设置设备像素比。 这通常用于HiDPI设备以防止模糊输出画布。 precision: "highp",//precision:highp/mediump/lowp着色精度选择
this.m_Render.setPixelRatio(window.devicePixelRatio); alpha: true//alpha:true/false是否可以设置背景色透明
this.m_Render.physicallyCorrectLights = true; };
//this.m_Render.toneMappingExposure = Math.pow(1, 5.0); // to allow for very bright scenes. if (canvasContainer instanceof HTMLCanvasElement)
{
//设置它的背景色为黑色 params.canvas = canvasContainer;
this.m_Render.setClearColor(0xffffff, 1); this.m_Render = new WebGLRenderer(params);
}
else
this.OnSize(); {
this.m_Render = new WebGLRenderer(params);
//加到画布
canvasContainer.appendChild(this.m_Render.domElement);
} }
OnSize = (width?, height?) => 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 = ReinhardToneMapping;
//设置设备像素比。 这通常用于HiDPI设备以防止模糊输出画布。
this.m_Render.setPixelRatio(window.devicePixelRatio);
this.m_Render.physicallyCorrectLights = true;
//this.m_Render.toneMappingExposure = Math.pow(1, 5.0); // to allow for very bright scenes.
//设置它的背景色为黑色
this.m_Render.setClearColor(0xffffff, 1);
this.OnSize();
}
OnSize = (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);
}
StartRender = () =>
{
requestAnimationFrame(this.StartRender);
if (this.m_Scene != null && this.m_bNeedUpdate)
{ {
this._Width = width ? width : this.m_DomEl.scrollWidth; this.Render();
this._Height = height ? height : this.m_DomEl.scrollHeight; this.m_bNeedUpdate = false;
//校验.成为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);
} }
}
Render()
{
this.m_Render.render(this.m_Scene, this.m_Camera.Camera);
}
StartRender = () => ScreenToWorld(pt: Vector3, planVec?: Vector3)
{
//变换和求交点
let plan = new PlaneExt(planVec || new Vector3(0, 0, 1));
let raycaster = new 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: Vector3)
{
let widthHalf = this._Width * 0.5;
let 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 = GetBoxArr(renderList.opaque.map(o => o.object));
if (box)
this.m_LookTarget = box.getCenter(new Vector3());
else
this.m_LookTarget = cZeroVec;
}
Rotate(mouseMove: Vector3)
{
this.m_Camera.Rotate(mouseMove, this.m_LookTarget);
this.m_bNeedUpdate = true;
}
Pan(mouseMove: Vector3)
{
this.m_Camera.Pan(mouseMove);
this.m_bNeedUpdate = true;
}
Zoom(scale: number, center?: Vector3)
{
this.m_Camera.Zoom(scale, center);
this.m_bNeedUpdate = true;
}
ZoomAll()
{
this.m_Camera.ZoomExtensBox3(GetBox(this.m_Scene, true));
this.m_bNeedUpdate = true;
}
ViewToTop()
{
this.m_Camera.LookAt(new Vector3(0, 0, -1));
this.m_bNeedUpdate = true;
}
ViewToFront()
{
this.m_Camera.LookAt(new Vector3(0, 1, 0));
this.m_bNeedUpdate = true;
}
ViewToSwiso()
{
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))
{ {
requestAnimationFrame(this.StartRender); this.oldMesh = mesh;
if (this.m_Scene != null && this.m_bNeedUpdate) 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)
{ {
this.Render(); if (obj.id == meshId)
this.m_bNeedUpdate = false; {
this.oldMesh = obj;
obj.material = this._Settings.selectMaterial;
this.m_bNeedUpdate = true;
}
} }
}
Render()
{
this.m_Render.render(this.m_Scene, this.m_Camera.Camera);
}
ScreenToWorld(pt: THREE.Vector3, planVec?: THREE.Vector3) })
{
//变换和求交点
let plan = new PlaneExt(planVec || new THREE.Vector3(0, 0, 1));
let raycaster = new THREE.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: THREE.Vector3)
{
let widthHalf = this._Width * 0.5;
let 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 = GetBoxArr(renderList.opaque.map(o => o.object));
if (box)
this.m_LookTarget = box.getCenter(new THREE.Vector3());
else
this.m_LookTarget = cZeroVec;
}
Rotate(mouseMove: THREE.Vector3)
{
this.m_Camera.Rotate(mouseMove, this.m_LookTarget);
this.m_bNeedUpdate = true;
}
Pan(mouseMove: THREE.Vector3)
{
this.m_Camera.Pan(mouseMove);
this.m_bNeedUpdate = true;
}
Zoom(scale: number, center?: THREE.Vector3)
{
this.m_Camera.Zoom(scale, center);
this.m_bNeedUpdate = true;
}
ZoomAll()
{
this.m_Camera.ZoomExtensBox3(GetBox(this.m_Scene, true));
this.m_bNeedUpdate = true;
}
ViewToTop()
{
this.m_Camera.LookAt(new THREE.Vector3(0, 0, -1));
this.m_bNeedUpdate = true;
}
ViewToFront()
{
this.m_Camera.LookAt(new THREE.Vector3(0, 1, 0));
this.m_bNeedUpdate = true;
}
ViewToSwiso()
{
this.m_Camera.LookAt(new THREE.Vector3(1, 1, -1));
this.m_bNeedUpdate = true;
} }
}
} }

View File

@@ -1,24 +1,22 @@
import * as THREE from 'three'; import { EdgesGeometry, Geometry, LineSegments, MeshBasicMaterial, Shape, Vector2 } from 'three';
import { Geometry, LineSegments, Vector2 } from 'three';
import { polar } from './GeUtils'; import { polar } from './GeUtils';
import { boardMaterial, edgeMaterial } from './Material'; import { edgeMaterial } from './Material';
import { RotateUVs } from './RotateUV'; import { SimpleBoard } from './SimpleBoard';
import { ThreeBSP } from './ThreeCSG';
//解析二维圆弧类. //解析二维圆弧类.
export class Arc2d export class Arc2d
{ {
m_StartAn: number; m_StartAn: number;
m_EndAn: number; m_EndAn: number;
m_StartPoint: THREE.Vector2; m_StartPoint: Vector2;
m_EndPoint: THREE.Vector2; m_EndPoint: Vector2;
m_Center: THREE.Vector2; m_Center: Vector2;
m_Radius: number; m_Radius: number;
constructor(p1: THREE.Vector2, p2: THREE.Vector2, bul: number) constructor(p1: Vector2, p2: Vector2, bul: number)
{ {
this.m_StartPoint = p1.clone(); this.m_StartPoint = p1.clone();
this.m_EndPoint = p2.clone(); this.m_EndPoint = p2.clone();
let vec: THREE.Vector2 = p2.clone().sub(p1); let vec: Vector2 = p2.clone().sub(p1);
let len = vec.length(); let len = vec.length();
let an = vec.angle(); let an = vec.angle();
this.m_Radius = len / Math.sin(2 * Math.atan(bul)) / 2; this.m_Radius = len / Math.sin(2 * Math.atan(bul)) / 2;
@@ -43,10 +41,10 @@ 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; if (pts.length === 0) return shape;
let firstPt = pts[0]; let firstPt = pts[0];
@@ -56,7 +54,7 @@ export function createPath(pts: THREE.Vector2[], buls: number[], shapeOut?: THRE
let nextPt = pts[i + 1]; let nextPt = pts[i + 1];
if (buls[i] == 0) if (buls[i] == 0)
{ {
shape.lineTo(nextPt.x, nextPt.y) shape.lineTo(nextPt.x, nextPt.y);
} }
else else
{ {
@@ -71,111 +69,39 @@ export function createPath(pts: THREE.Vector2[], buls: number[], shapeOut?: THRE
} }
return shape; return shape;
} }
export function getVec(data: object): THREE.Vector3
{
return new THREE.Vector3(data["x"], data["y"], data["z"]);
}
//创建板件 暂时这么写 //创建板件 暂时这么写
export function createBoard(boardData: object)
{
let pts: THREE.Vector2[] = new Array();
let buls: number[] = new Array();
let boardPts = boardData["Pts"];
let boardBuls = boardData["Buls"];
let boardHeight = boardData["H"];
let boardMat = new THREE.Matrix4(); export function createTemplateBoard(brDataList: any[], material: MeshBasicMaterial)
let matInv: THREE.Matrix4 = new THREE.Matrix4();
//InitBoardMat
{
let xD = getVec(boardData["XVec"]);
let yD = getVec(boardData["YVec"]);
let ZD = getVec(boardData["ZVec"]);
let pBase = getVec(boardData["BasePoint"]);
boardMat.makeBasis(xD, yD, ZD);
boardMat.setPosition(pBase);
matInv.getInverse(boardMat, true);
}
if (boardPts && boardPts.length !== 0)
for (let i = 0; i < boardPts.length; i++)
{
let pt = getVec(boardPts[i]);
if (pt.z !== undefined)
pt.applyMatrix4(matInv);
pts.push(new THREE.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 Vector2(0, 0),
new Vector2(width, 0),
new Vector2(width, length),
new Vector2(0, length),
new Vector2(0, 0)
);
buls.push(0, 0, 0, 0, 0);
}
let sp = createPath(pts, buls);
let extrudeSettings = {
steps: 1,
bevelEnabled: false,
amount: boardHeight
};
let ext = new THREE.ExtrudeGeometry(sp, extrudeSettings) as Geometry;
ext.computeBoundingSphere();
ext.computeBoundingBox();
ext.translate(0, 0, -boardHeight)
ext.applyMatrix(boardMat);
//外边.
let edges = [createEdge(ext)];
//差集
if (boardData["SubBoardLocal"].length > 0)
{
let subBoardList = boardData["SubBoardLocal"].map(d => createBoard(d));
let thisCsg = new ThreeBSP(ext);
for (let br of subBoardList)
{
edges.push(...br.edges);
let subCsg = new ThreeBSP(br.mesh);
thisCsg = thisCsg.subtract(subCsg);
}
ext = thisCsg.toGeometry();
}
if (boardData["BoardName"] === "地脚线")
RotateUVs(ext);
let mesh = new THREE.Mesh(ext, boardMaterial);
return { mesh, edges };
}
export function createTemplateBoard(brDataList: any[])
{ {
let meshs = []; let meshs = [];
let edgesa = []; let edgesa = [];
let relations = {
blockMeshMap: new Map<number, number>(),
meshBlockMap: new Map<number, number>()
};
for (let d of brDataList) for (let d of brDataList)
{ {
let { mesh, edges } = createBoard(d); let board = new SimpleBoard(d);
let { mesh, edges } = board.createBoard(material);
meshs.push(mesh); meshs.push(mesh);
edgesa.push(...edges); edgesa.push(...edges);
if (board.DataID)
{
relations.blockMeshMap.set(board.DataID, mesh.id);
relations.meshBlockMap.set(mesh.id, board.DataID);
}
} }
return { meshs, edgesa }; return { meshs, edgesa, relations };
} }
export function createEdge(geo: Geometry): LineSegments export function createEdge(geo: Geometry): LineSegments
{ {
let edge = new THREE.EdgesGeometry(geo, 1); let edge = new EdgesGeometry(geo, 1);
return new LineSegments(edge, edgeMaterial); return new LineSegments(edge, edgeMaterial);
} }

View File

@@ -1,550 +0,0 @@
export var data =
[
{
"L": 100.0,
"W": 800.0,
"H": 18.0,
"BasePoint": {
"x": 2076.407626150509,
"y": 1942.2104819571228,
"z": 1882.0
},
"XVec": {
"x": 1.0,
"y": 4.930380657631324e-32,
"z": -2.220446049250313e-16
},
"YVec": {
"x": 2.220446049250313e-16,
"y": 2.220446049250313e-16,
"z": 1.0
},
"ZVec": {
"x": 9.860761315262648e-32,
"y": -1.0,
"z": 2.220446049250313e-16
},
"Pts": [
{
"x": 2076.407626150509,
"y": 1942.2104819571228,
"z": 1882.0
},
{
"x": 2876.407626150509,
"y": 1942.2104819571228,
"z": 1881.9999999999998
},
{
"x": 2876.407626150509,
"y": 1942.2104819571228,
"z": 1981.9999999999998
},
{
"x": 2076.407626150509,
"y": 1942.2104819571228,
"z": 1982.0
},
{
"x": 2076.407626150509,
"y": 1942.2104819571228,
"z": 1882.0
}
],
"Buls": [
0.0,
0.0,
0.0,
0.0,
0.0
],
"SubBoardLocal": [],
"SubBoardAssoc": []
},
{
"L": 800.0,
"W": 100.00000000000068,
"H": 18.0,
"MaterialId": "EE",
"BasePoint": {
"x": 2876.407626150509,
"y": 1960.2104819571226,
"z": 1900.0000000000005
},
"XVec": {
"x": 4.440892098500626e-16,
"y": 1.0,
"z": 2.2204460492503124e-16
},
"YVec": {
"x": -1.0,
"y": 4.440892098500626e-16,
"z": 2.220446049250314e-16
},
"ZVec": {
"x": 2.220446049250313e-16,
"y": -2.220446049250313e-16,
"z": 1.0
},
"Handle": "293",
"CabName": "1.标准柜上梁1",
"BoardName": "",
"Grain": 0,
"Pts": [
{
"x": 2876.407626150509,
"y": 1960.2104819571228,
"z": 1900.0000000000005
},
{
"x": 2876.407626150509,
"y": 2060.210481957123,
"z": 1900.0000000000005
},
{
"x": 2076.407626150509,
"y": 2060.210481957123,
"z": 1900.0000000000005
},
{
"x": 2076.407626150509,
"y": 1960.210481957123,
"z": 1900.0000000000005
},
{
"x": 2876.407626150509,
"y": 1960.2104819571228,
"z": 1900.0000000000005
}
],
"Buls": [
0.0,
0.0,
0.0,
0.0,
0.0
],
"SubBoardLocal": [],
"SubBoardAssoc": []
},
{
"L": 1899.9999999999998,
"W": 800.0,
"H": 18.0,
"MaterialId": "EE",
"BasePoint": {
"x": 2076.407626150509,
"y": 2060.2104819571225,
"z": -1.816324868286756e-13
},
"XVec": {
"x": 1.0,
"y": 0.0,
"z": 0.0
},
"YVec": {
"x": 0.0,
"y": 4.440892098500626e-16,
"z": 1.0
},
"ZVec": {
"x": 0.0,
"y": -1.0,
"z": 4.440892098500626e-16
},
"Handle": "291",
"CabName": "1.标准柜上梁1",
"BoardName": "背板",
"Grain": 0,
"Pts": [
{
"x": 2076.407626150509,
"y": 2060.2104819571225,
"z": -1.021405182655144e-13
},
{
"x": 2876.407626150509,
"y": 2060.2104819571225,
"z": -1.816324868286756e-13
},
{
"x": 2876.407626150509,
"y": 2060.210481957123,
"z": 1899.9999999999996
},
{
"x": 2076.407626150509,
"y": 2060.210481957123,
"z": 1899.9999999999998
},
{
"x": 2076.407626150509,
"y": 2060.2104819571225,
"z": -1.021405182655144e-13
}
],
"Buls": [
0.0,
0.0,
0.0,
0.0,
0.0
],
"SubBoardLocal": [],
"SubBoardAssoc": []
},
{
"L": 800.0,
"W": 482.0000000000002,
"H": 18.0,
"MaterialId": "EE",
"BasePoint": {
"x": 2876.407626150509,
"y": 1578.210481957122,
"z": 97.99999999999999
},
"XVec": {
"x": 4.440892098500626e-16,
"y": 1.0,
"z": 0.0
},
"YVec": {
"x": -1.0,
"y": 4.440892098500626e-16,
"z": 0.0
},
"ZVec": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"Handle": "290",
"CabName": "1.标准柜上梁1",
"BoardName": "底板",
"Grain": 0,
"Pts": [
{
"x": 2876.407626150509,
"y": 1578.210481957122,
"z": 97.99999999999999
},
{
"x": 2876.407626150509,
"y": 2060.2104819571225,
"z": 97.99999999999999
},
{
"x": 2076.407626150509,
"y": 2060.2104819571225,
"z": 97.99999999999999
},
{
"x": 2076.407626150509,
"y": 1578.2104819571226,
"z": 97.99999999999999
},
{
"x": 2876.407626150509,
"y": 1578.210481957122,
"z": 97.99999999999999
}
],
"Buls": [
0.0,
0.0,
0.0,
0.0,
0.0
],
"SubBoardLocal": [],
"SubBoardAssoc": []
},
{
"L": 80.0,
"W": 800.0,
"H": 18.0,
"MaterialId": "EE",
"BasePoint": {
"x": 2076.407626150509,
"y": 1578.2104819571223,
"z": 0.0
},
"XVec": {
"x": 1.0,
"y": 0.0,
"z": 0.0
},
"YVec": {
"x": 0.0,
"y": 4.440892098500626e-16,
"z": 1.0
},
"ZVec": {
"x": 0.0,
"y": -1.0,
"z": 4.440892098500626e-16
},
"Handle": "28E",
"CabName": "1.标准柜上梁1",
"BoardName": "地脚线",
"Grain": 1,
"Pts": [
{
"x": 2076.407626150509,
"y": 1578.2104819571223,
"z": 0.0
},
{
"x": 2876.407626150509,
"y": 1578.2104819571223,
"z": 0.0
},
{
"x": 2876.407626150509,
"y": 1578.2104819571223,
"z": 80.0
},
{
"x": 2076.407626150509,
"y": 1578.2104819571223,
"z": 80.0
},
{
"x": 2076.407626150509,
"y": 1578.2104819571223,
"z": 0.0
}
],
"Buls": [
0.0,
0.0,
0.0,
0.0,
0.0
],
"SubBoardLocal": [],
"SubBoardAssoc": []
},
{
"L": 800.0,
"W": 482.0,
"H": 18.0,
"MaterialId": "EE",
"BasePoint": {
"x": 2876.4076261505085,
"y": 1478.210481957122,
"z": 1999.9999999999996
},
"XVec": {
"x": 4.440892098500626e-16,
"y": 1.0,
"z": 0.0
},
"YVec": {
"x": -1.0,
"y": 4.440892098500626e-16,
"z": 0.0
},
"ZVec": {
"x": 0.0,
"y": 0.0,
"z": 1.0
},
"Handle": "28C",
"CabName": "1.标准柜上梁1",
"BoardName": "顶板",
"Grain": 0,
"Pts": [
{
"x": 2076.407626150509,
"y": 1960.2104819571223,
"z": 1999.9999999999996
},
{
"x": 2076.407626150509,
"y": 1478.2104819571226,
"z": 1999.9999999999996
},
{
"x": 2876.407626150509,
"y": 1478.210481957122,
"z": 1999.9999999999996
},
{
"x": 2876.4076261505085,
"y": 1960.210481957122,
"z": 1999.9999999999996
},
{
"x": 2076.407626150509,
"y": 1960.2104819571223,
"z": 1999.9999999999996
}
],
"Buls": [
0.0,
0.0,
0.0,
0.0,
0.0
],
"SubBoardLocal": [],
"SubBoardAssoc": []
},
{
"L": 1999.9999999999996,
"W": 600.0,
"H": 18.0,
"MaterialId": "EE",
"BasePoint": {
"x": 2894.4076261505094,
"y": 1478.2104819571223,
"z": -2.2737367544323197e-13
},
"XVec": {
"x": 4.930380657631324e-32,
"y": 1.0,
"z": -2.220446049250313e-16
},
"YVec": {
"x": -2.220446049250313e-16,
"y": 2.220446049250313e-16,
"z": 1.0
},
"ZVec": {
"x": 1.0,
"y": 0.0,
"z": 2.220446049250313e-16
},
"Handle": "28B",
"CabName": "1.标准柜上梁1",
"BoardName": "右侧板",
"Grain": 0,
"Pts": [
{
"x": 2894.407626150509,
"y": 1960.2104819571228,
"z": 1899.9999999999989
},
{
"x": 2894.407626150509,
"y": 1960.2104819571228,
"z": 1999.9999999999994
},
{
"x": 2894.407626150509,
"y": 1478.2104819571228,
"z": 1999.9999999999994
},
{
"x": 2894.4076261505094,
"y": 1478.2104819571223,
"z": -1.816324868286755e-13
},
{
"x": 2894.4076261505094,
"y": 2078.2104819571225,
"z": -6.274980535181384e-13
},
{
"x": 2894.407626150509,
"y": 2078.2104819571229,
"z": 1899.9999999999973
},
{
"x": 2894.407626150509,
"y": 1960.2104819571228,
"z": 1899.9999999999989
}
],
"Buls": [
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
],
"SubBoardLocal": [],
"SubBoardAssoc": []
},
{
"L": 1999.9999999999996,
"W": 600.0,
"H": 18.0,
"MaterialId": "EE",
"BasePoint": {
"x": 2076.4076261505094,
"y": 1478.2104819571223,
"z": 1.0097419586828951e-28
},
"XVec": {
"x": 4.930380657631324e-32,
"y": 1.0,
"z": -2.220446049250313e-16
},
"YVec": {
"x": -2.220446049250313e-16,
"y": 2.220446049250313e-16,
"z": 1.0
},
"ZVec": {
"x": 1.0,
"y": 0.0,
"z": 2.220446049250313e-16
},
"Handle": "288",
"CabName": "1.标准柜上梁1",
"BoardName": "左侧板",
"Grain": 0,
"Pts": [
{
"x": 2076.407626150509,
"y": 1960.2104819571228,
"z": 1899.999999999999
},
{
"x": 2076.407626150509,
"y": 1960.2104819571228,
"z": 1999.9999999999996
},
{
"x": 2076.407626150509,
"y": 1478.2104819571228,
"z": 1999.9999999999996
},
{
"x": 2076.4076261505094,
"y": 1478.2104819571223,
"z": 1.0097419586828951e-28
},
{
"x": 2076.4076261505094,
"y": 2078.2104819571225,
"z": -4.4586556668946279e-13
},
{
"x": 2076.407626150509,
"y": 2078.2104819571229,
"z": 1899.9999999999978
},
{
"x": 2076.407626150509,
"y": 1960.2104819571228,
"z": 1899.999999999999
}
],
"Buls": [
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
],
"SubBoardLocal": [],
"SubBoardAssoc": []
}
]

View File

@@ -1,21 +1,27 @@
{ {
"compileOnSave": true,
"compilerOptions": { "compilerOptions": {
"sourceMap": true,
"declaration": true,
"outDir": "./dist", "outDir": "./dist",
"target": "esnext", "sourceMap": true,
"module": "commonjs",
"target": "es2020",
"noLib": false,
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"lib": [ "lib": [
"es2017", "esnext",
"dom" "dom"
], ],
"types": [ "types": [
"node" "node",
"webpack-env",
"webpack-dev-server",
], ],
"module": "commonjs", "jsx": "react",
"experimentalDecorators": true "experimentalDecorators": true
}, },
"include": [ "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"
]
});

7
utils/rmtype.ts Normal file
View File

@@ -0,0 +1,7 @@
import fs from "fs";
fs.rmdir(".\\node_modules\\@types\\webpack-merge\\node_modules\\webpack", { recursive: true }, (err) =>
{
console.log("删除webpack目录");
if (err) console.log(err);
});

4165
yarn.lock Normal file

File diff suppressed because it is too large Load Diff