From 8f50141956f7e6dd0c843e8ede3b1d74a41964f9 Mon Sep 17 00:00:00 2001 From: ChenX Date: Mon, 30 May 2022 11:03:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91:=E6=B8=85=E7=90=86=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/FileSystem/file.test.ts | 19 ++-- __test__/Geometry/intersect.test.ts | 33 +++--- src/Add-on/DrawFloor.ts | 116 +++++++++++----------- src/Add-on/DrawGripStretch.ts | 13 ++- src/Add-on/DrawSky.ts | 5 +- src/Add-on/DrawZeroCircle.ts | 8 +- src/Common/SetMaterial.ts | 5 +- src/DatabaseServices/3DSolid/Cylineder.ts | 9 +- src/DatabaseServices/CADFactory.ts | 3 + src/GraphicsSystem/Octree.ts | 17 ++-- src/WebCADView/WebCADView.ts | 71 +++++++------ src/webview.ts | 26 ++--- 12 files changed, 161 insertions(+), 164 deletions(-) diff --git a/__test__/FileSystem/file.test.ts b/__test__/FileSystem/file.test.ts index d509afda0..a9a38db0e 100644 --- a/__test__/FileSystem/file.test.ts +++ b/__test__/FileSystem/file.test.ts @@ -1,4 +1,5 @@ -import * as THREE from 'three'; + +import { Vector3 } from 'three'; import { AllObjectData } from '../../src/DatabaseServices/AllObjectData'; import { BlockTableRecord } from '../../src/DatabaseServices/BlockTableRecord'; import { CADFactory } from '../../src/DatabaseServices/CADFactory'; @@ -8,8 +9,8 @@ import { CommandHistoryRecord } from '../../src/DatabaseServices/CommandHistoryR import { CreateObjectData } from '../../src/DatabaseServices/CreateObjectData'; import { Database } from '../../src/DatabaseServices/Database'; import { Entity } from '../../src/DatabaseServices/Entity/Entity'; -import { HistorycRecord } from '../../src/DatabaseServices/HistorycRecord'; import { Line } from '../../src/DatabaseServices/Entity/Line'; +import { HistorycRecord } from '../../src/DatabaseServices/HistorycRecord'; import { ObjectAllDataHistoryRecord } from '../../src/DatabaseServices/ObjectAllDataHistoryRecord'; import { RemoveObjectData } from '../../src/DatabaseServices/RemoveObjectData'; @@ -82,7 +83,7 @@ test('clone object', () => let db = new Database(); let line = new Line(); db.ModelSpace.Append(line); - line.StartPoint = new THREE.Vector3(9, 9, 8); + line.StartPoint = new Vector3(9, 9, 8); CadObjectToString(line);/*?*/ @@ -107,7 +108,7 @@ test('changev', () => expect(id.Object !== l1).toBeTruthy(); //创建对象的撤销和重做后 id指向了新的实体 - (id.Object as Line).StartPoint = new THREE.Vector3(2, 3, 4); + (id.Object as Line).StartPoint = new Vector3(2, 3, 4); let file = db.FileWrite(); expect(file.ToString()/*?*/).toMatchSnapshot(); @@ -134,14 +135,14 @@ test('xxx', () => db.hm.Redo(); //? // db.hm.StartCmd(""); - (id1.Object as Line).StartPoint = new THREE.Vector3(10, 4, 2); - (id1.Object as Line).EndPoint = new THREE.Vector3(2, 2, 2); + (id1.Object as Line).StartPoint = new Vector3(10, 4, 2); + (id1.Object as Line).EndPoint = new Vector3(2, 2, 2); let file = db.FileWrite(); db.hm.StartCmd(""); - (id1.Object as Line).StartPoint = new THREE.Vector3(100, 300, 400); - (id1.Object as Line).EndPoint = new THREE.Vector3(2000, 3000, 4000); + (id1.Object as Line).StartPoint = new Vector3(100, 300, 400); + (id1.Object as Line).EndPoint = new Vector3(2000, 3000, 4000); db.hm.Undo(); @@ -169,7 +170,7 @@ test('创建 修改 撤销撤销 重做重做 撤销 重做', () => let line = new Line(); db.ModelSpace.Append(line); db.hm.StartCmd("U"); - line.StartPoint = new THREE.Vector3(1, 2, 3); + line.StartPoint = new Vector3(1, 2, 3); db.hm.EndCmd(); db.hm.Undo(); /*?*/ diff --git a/__test__/Geometry/intersect.test.ts b/__test__/Geometry/intersect.test.ts index 73703781a..b76dc8a9c 100644 --- a/__test__/Geometry/intersect.test.ts +++ b/__test__/Geometry/intersect.test.ts @@ -1,4 +1,3 @@ -import * as THREE from 'three'; import { Vector3 } from 'three'; import { Arc } from '../../src/DatabaseServices/Entity/Arc'; import { Circle } from '../../src/DatabaseServices/Entity/Circle'; @@ -9,13 +8,13 @@ import { LoadCurvesFromFileData, LoadEntityFromFileData } from '../Utils/LoadEnt test('相交测试', () => { - let p1 = new THREE.Vector3(0, 0, 0); - let p2 = new THREE.Vector3(1, 0, 0); - let p3 = new THREE.Vector3(0.5, 0.5, 0); - let p4 = new THREE.Vector3(0.5, 1, 0); + let p1 = new Vector3(0, 0, 0); + let p2 = new Vector3(1, 0, 0); + let p3 = new Vector3(0.5, 0.5, 0); + let p4 = new Vector3(0.5, 1, 0); - let p5 = new THREE.Vector3(3, 0, 0); - let p6 = new THREE.Vector3(6, 0, 0); + let p5 = new Vector3(3, 0, 0); + let p6 = new Vector3(6, 0, 0); let res = IntersectLine3AndLine3(p1, p2, p3, p4);/*?*/ expect(res).toMatchSnapshot(); @@ -24,22 +23,22 @@ test('相交测试', () => expect(res).toMatchSnapshot(); let ins = IntersectLine3AndLine3( - new THREE.Vector3(0, 5), - new THREE.Vector3(5, 5), - new THREE.Vector3(0.5, 1), - new THREE.Vector3(0.5, 8)); + new Vector3(0, 5), + new Vector3(5, 5), + new Vector3(0.5, 1), + new Vector3(0.5, 8)); expect(ins).toMatchSnapshot(); }); test('三维空间直线相交测试', () => { - let p1 = new THREE.Vector3(); - let p2 = new THREE.Vector3(10, 10, 10); - let p3 = new THREE.Vector3(5, 5, 5); - let p4 = new THREE.Vector3(5, 10, 5); + let p1 = new Vector3(); + let p2 = new Vector3(10, 10, 10); + let p3 = new Vector3(5, 5, 5); + let p4 = new Vector3(5, 10, 5); - let p5 = new THREE.Vector3(3, 3, 3); - let p6 = new THREE.Vector3(6, 6, 6); + let p5 = new Vector3(3, 3, 3); + let p6 = new Vector3(6, 6, 6); let res = IntersectLine3AndLine3(p1, p2, p3, p4);/*?*/ expect(res).toMatchSnapshot(); diff --git a/src/Add-on/DrawFloor.ts b/src/Add-on/DrawFloor.ts index d1c8c1bd2..819bb03ab 100644 --- a/src/Add-on/DrawFloor.ts +++ b/src/Add-on/DrawFloor.ts @@ -1,11 +1,11 @@ -import * as THREE from 'three'; +import { Clock, CubeTextureLoader, HemisphereLight, Mesh, MeshStandardMaterial, PlaneGeometry, PointLight, RepeatWrapping, RGBFormat, SphereGeometry, TextureLoader } from 'three'; import { begin } from 'xaop'; import { app } from '../ApplicationServices/Application'; import { Command } from '../Editor/CommandMachine'; export class DrawFloor implements Command { - textureLoader: THREE.TextureLoader; + textureLoader: TextureLoader; get scene() { @@ -13,7 +13,7 @@ export class DrawFloor implements Command } constructor() { - this.textureLoader = new THREE.TextureLoader(); + this.textureLoader = new TextureLoader(); } async exec() { @@ -44,7 +44,7 @@ export class DrawFloor implements Command private drawFloor() { - let floorMat = new THREE.MeshStandardMaterial({ + let floorMat = new MeshStandardMaterial({ roughness: 0.8, color: 0xffffff, metalness: 0.2, @@ -54,8 +54,8 @@ export class DrawFloor implements Command }); this.materialList.push(floorMat); - var floorGeometry = new THREE.PlaneGeometry(20, 20); - var floorMesh = new THREE.Mesh(floorGeometry, floorMat); + var floorGeometry = new PlaneGeometry(20, 20); + var floorMesh = new Mesh(floorGeometry, floorMat); floorMesh.receiveShadow = true; this.scene.add(floorMesh); @@ -66,7 +66,7 @@ export class DrawFloor implements Command floorMat.transparent = true; floorMat.opacity = 0.9; - // let ref = new THREE.Reflector(20, 20, { + // let ref = new Reflector(20, 20, { // clipBias: 0.003, // textureWidth: app.m_Viewer.Width * window.devicePixelRatio, // textureHeight: app.m_Viewer.Height * window.devicePixelRatio, @@ -84,8 +84,8 @@ export class DrawFloor implements Command this.textureLoader.load("textures/hardwood2_diffuse.jpg", function (map) { - map.wrapS = THREE.RepeatWrapping; - map.wrapT = THREE.RepeatWrapping; + map.wrapS = RepeatWrapping; + map.wrapT = RepeatWrapping; map.anisotropy = 16; map.repeat.set(10, 24); @@ -97,27 +97,27 @@ export class DrawFloor implements Command }); this.textureLoader.load("textures/hardwood2_bump.jpg", function (map) { - map.wrapS = THREE.RepeatWrapping; - map.wrapT = THREE.RepeatWrapping; + map.wrapS = RepeatWrapping; + map.wrapT = RepeatWrapping; map.anisotropy = 16; map.repeat.set(10, 24); self.materialList.forEach(m => { - (m).bumpMap = map; + (m).bumpMap = map; m.needsUpdate = true; }); }); this.textureLoader.load("textures/hardwood2_roughness.jpg", function (map) { - map.wrapS = THREE.RepeatWrapping; - map.wrapT = THREE.RepeatWrapping; + map.wrapS = RepeatWrapping; + map.wrapT = RepeatWrapping; map.anisotropy = 16; map.repeat.set(10, 24); self.materialList.forEach(m => { - (m).roughnessMap = map; + (m).roughnessMap = map; m.needsUpdate = true; }); }); @@ -125,18 +125,18 @@ export class DrawFloor implements Command drawLight() { - var bulbGeometry = new THREE.SphereGeometry(0.02, 16, 8); - // let bulbLight = new THREE.PointLight(0xffee88, 1.5, 100, 1); - let bulbLight = new THREE.PointLight(0x999999, 1.5, 100, 2); + var bulbGeometry = new SphereGeometry(0.02, 16, 8); + // let bulbLight = new PointLight(0xffee88, 1.5, 100, 1); + let bulbLight = new PointLight(0x999999, 1.5, 100, 2); - let bulbMat = new THREE.MeshStandardMaterial({ + let bulbMat = new MeshStandardMaterial({ emissive: 0xffffee, emissiveIntensity: 1, color: 0x000000 }); - bulbLight.add(new THREE.Mesh(bulbGeometry, bulbMat)); + bulbLight.add(new Mesh(bulbGeometry, bulbMat)); bulbLight.position.set(0, 2, 2); bulbLight.castShadow = true; @@ -150,7 +150,7 @@ export class DrawFloor implements Command this.scene.add(light2); - var clock = new THREE.Clock(); + var clock = new Clock(); begin(app.Viewer, app.Viewer.StartRender, () => { var time = Date.now() * 0.0005; @@ -162,8 +162,8 @@ export class DrawFloor implements Command private drawHemiLight() { //0xddeeff 0x0f0e0d - // var hemiLight = new THREE.HemisphereLight(0xffffff, 0xffffff, 0.05); - var hemiLight = new THREE.HemisphereLight(0xddeeff, 0x0f0e0d, 0.05); + // var hemiLight = new HemisphereLight(0xffffff, 0xffffff, 0.05); + var hemiLight = new HemisphereLight(0xddeeff, 0x0f0e0d, 0.05); hemiLight.intensity = 23; this.scene.add(hemiLight); } @@ -171,7 +171,7 @@ export class DrawFloor implements Command drawWall() { - // let floorMat = new THREE.MeshStandardMaterial({ + // let floorMat = new MeshStandardMaterial({ // roughness: 0.8, // color: 0xffffff, // metalness: 0.2, @@ -180,8 +180,8 @@ export class DrawFloor implements Command // this.textureLoader.load("textures/wallmap.png", function (map) // { - // map.wrapS = THREE.RepeatWrapping; - // map.wrapT = THREE.RepeatWrapping; + // map.wrapS = RepeatWrapping; + // map.wrapT = RepeatWrapping; // map.anisotropy = 4; // map.repeat.set(10, 24); // floorMat.map = map; @@ -190,7 +190,7 @@ export class DrawFloor implements Command // let wallFont = new Solid3d(4, 0.12, 2.8); - // let obj = wallFont.Draw(RenderType.Wireframe) as THREE.Mesh; + // let obj = wallFont.Draw(RenderType.Wireframe) as Mesh; // obj.material = floorMat; // obj.castShadow = true; @@ -200,18 +200,18 @@ export class DrawFloor implements Command // let objRight = obj.clone(); - // obj.applyMatrix(Move(new THREE.Vector3(-2.1, 4, 0))); + // obj.applyMatrix(Move(new Vector3(-2.1, 4, 0))); - // let roMatLeft = new THREE.Matrix4(); + // let roMatLeft = new Matrix4(); // roMatLeft.makeRotationZ(Math.PI / 2); // objLeft.applyMatrix(roMatLeft); - // let roMatRight = new THREE.Matrix4(); + // let roMatRight = new Matrix4(); // roMatRight.makeRotationZ(Math.PI / 2); // objRight.applyMatrix(roMatRight); - // objLeft.applyMatrix(Move(new THREE.Vector3(-2, 0, 0))) - // objRight.applyMatrix(Move(new THREE.Vector3(2, 0, 0))) + // objLeft.applyMatrix(Move(new Vector3(-2, 0, 0))) + // objRight.applyMatrix(Move(new Vector3(2, 0, 0))) // this.scene.add(obj); @@ -219,7 +219,7 @@ export class DrawFloor implements Command // this.scene.add(objRight); - // let skyMaterail = new THREE.MeshStandardMaterial({ + // let skyMaterail = new MeshStandardMaterial({ // roughness: 0.8, // color: 0xffffff, // metalness: 0.2, @@ -227,10 +227,10 @@ export class DrawFloor implements Command // }) // //天花板. // let skyWall = new Solid3d(4.12, 4, 0.12); - // let skyObj = skyWall.Draw(RenderType.Wireframe) as THREE.Mesh; + // let skyObj = skyWall.Draw(RenderType.Wireframe) as Mesh; // skyObj.material = skyMaterail; - // skyObj.applyMatrix(Move(new THREE.Vector3(-2.12, 0, 2.8))); + // skyObj.applyMatrix(Move(new Vector3(-2.12, 0, 2.8))); // this.scene.add(skyObj); } @@ -243,7 +243,7 @@ export class DrawFloor implements Command // obj.castShadow = true; - // let mat = new THREE.MeshStandardMaterial({ + // let mat = new MeshStandardMaterial({ // roughness: 0.8, // color: 0xffffff, // metalness: 0.2, @@ -252,14 +252,14 @@ export class DrawFloor implements Command // this.textureLoader.load("textures/door.png", function (map) // { - // map.wrapS = THREE.RepeatWrapping; - // map.wrapT = THREE.RepeatWrapping; + // map.wrapS = RepeatWrapping; + // map.wrapT = RepeatWrapping; // map.anisotropy = 16; // map.repeat.set(1, 1); // mat.map = map; // mat.needsUpdate = true; // }); - // (obj).material = mat; + // (obj).material = mat; // this.scene.add(obj); @@ -275,8 +275,8 @@ export class DrawFloor implements Command path + 'posy' + format, path + 'negy' + format, path + 'posz' + format, path + 'negz' + format ]; - var textureCube = new THREE.CubeTextureLoader().load(urls); - textureCube.format = THREE.RGBFormat; + var textureCube = new CubeTextureLoader().load(urls); + textureCube.format = RGBFormat; return textureCube; }; @@ -286,17 +286,17 @@ export class DrawFloor implements Command // let obj = solid.Draw(RenderType.Wireframe); - // // obj = new THREE.Mesh(new THREE.SphereGeometry(1, 32, 32)); + // // obj = new Mesh(new SphereGeometry(1, 32, 32)); // obj.position.set(0, 0, 1); // obj.castShadow = true; - // let cubeCamera1 = new THREE.CubeCamera(0.1, 15, 1024); - // let cubeCamera2 = new THREE.CubeCamera(0.1, 15, 1024); + // let cubeCamera1 = new CubeCamera(0.1, 15, 1024); + // let cubeCamera2 = new CubeCamera(0.1, 15, 1024); // cubeCamera1.position.set(0, 0, 1); // cubeCamera2.position.set(0, 0, 1); - // cubeCamera1.renderTarget.texture.minFilter = THREE.LinearMipMapLinearFilter; - // cubeCamera2.renderTarget.texture.minFilter = THREE.LinearMipMapLinearFilter; + // cubeCamera1.renderTarget.texture.minFilter = LinearMipMapLinearFilter; + // cubeCamera2.renderTarget.texture.minFilter = LinearMipMapLinearFilter; // cubeCamera1.renderTarget.texture.anisotropy = 16; // cubeCamera2.renderTarget.texture.anisotropy = 16; @@ -307,7 +307,7 @@ export class DrawFloor implements Command - // let mat = new THREE.MeshStandardMaterial({ + // let mat = new MeshStandardMaterial({ // roughness: 0.8, // metalness: 0.8, // // color: 0xffffff, @@ -319,8 +319,8 @@ export class DrawFloor implements Command // this.textureLoader.load("textures/Metal/130616_header2.jpg", function (map) // { - // map.wrapS = THREE.RepeatWrapping; - // map.wrapT = THREE.RepeatWrapping; + // map.wrapS = RepeatWrapping; + // map.wrapT = RepeatWrapping; // map.anisotropy = 16; // map.repeat.set(1, 1); // mat.map = map; @@ -329,8 +329,8 @@ export class DrawFloor implements Command // this.textureLoader.load("textures/Metal/Titanium-Scuffed_basecolor.png", function (map) // { - // map.wrapS = THREE.RepeatWrapping; - // map.wrapT = THREE.RepeatWrapping; + // map.wrapS = RepeatWrapping; + // map.wrapT = RepeatWrapping; // map.anisotropy = 16; // map.repeat.set(1, 1); // mat.map = map; @@ -338,8 +338,8 @@ export class DrawFloor implements Command // }); // this.textureLoader.load("textures/Metal/Titanium-Scuffed_roughness.png", function (map) // { - // map.wrapS = THREE.RepeatWrapping; - // map.wrapT = THREE.RepeatWrapping; + // map.wrapS = RepeatWrapping; + // map.wrapT = RepeatWrapping; // map.anisotropy = 16; // map.repeat.set(1, 1); // mat.roughnessMap = map; @@ -347,8 +347,8 @@ export class DrawFloor implements Command // }); // this.textureLoader.load("textures/Metal/Titanium-Scuffed_normal.png", function (map) // { - // map.wrapS = THREE.RepeatWrapping; - // map.wrapT = THREE.RepeatWrapping; + // map.wrapS = RepeatWrapping; + // map.wrapT = RepeatWrapping; // map.anisotropy = 16; // map.repeat.set(1, 1); // mat.normalMap = map; @@ -356,8 +356,8 @@ export class DrawFloor implements Command // }); // this.textureLoader.load("textures/Metal/Titanium-Scuffed_metallic.png", function (map) // { - // map.wrapS = THREE.RepeatWrapping; - // map.wrapT = THREE.RepeatWrapping; + // map.wrapS = RepeatWrapping; + // map.wrapT = RepeatWrapping; // map.anisotropy = 16; // map.repeat.set(1, 1); // mat.metalnessMap = map; @@ -388,7 +388,7 @@ export class DrawFloor implements Command // // obj.visible = true; // // isOne = !isOne; // // }); - // (obj).material = mat; + // (obj).material = mat; // this.scene.add(obj); } diff --git a/src/Add-on/DrawGripStretch.ts b/src/Add-on/DrawGripStretch.ts index bc80a6279..16df6ff3a 100644 --- a/src/Add-on/DrawGripStretch.ts +++ b/src/Add-on/DrawGripStretch.ts @@ -1,5 +1,4 @@ -import * as THREE from 'three'; - +import { Geometry, Line, Mesh, Points, PointsMaterial } from 'three'; import { app } from '../ApplicationServices/Application'; import { Command } from '../Editor/CommandMachine'; @@ -16,9 +15,9 @@ export class DrawGripStretch implements Command return; } - let geometry = new THREE.Geometry(); + let geometry = new Geometry(); - let material = new THREE.PointsMaterial({ + let material = new PointsMaterial({ size: 15, color: 0x001dfa, sizeAttenuation: false @@ -27,9 +26,9 @@ export class DrawGripStretch implements Command for (let en of app.Viewer.OutlinePass.selectedObjects) { - if (en instanceof THREE.Mesh || en instanceof THREE.Line) + if (en instanceof Mesh || en instanceof Line) { - if (en.geometry instanceof THREE.Geometry) + if (en.geometry instanceof Geometry) { for (let p of en.geometry.vertices) { @@ -37,7 +36,7 @@ export class DrawGripStretch implements Command } } } - let pts = new THREE.Points(geometry, material); + let pts = new Points(geometry, material); app.Viewer.Scene.add(pts); } } diff --git a/src/Add-on/DrawSky.ts b/src/Add-on/DrawSky.ts index 20aa9f2c8..2ef601dbd 100644 --- a/src/Add-on/DrawSky.ts +++ b/src/Add-on/DrawSky.ts @@ -1,5 +1,4 @@ -import * as THREE from 'three'; - +import { ShaderMaterial } from 'three'; import { app } from '../ApplicationServices/Application'; import { IsDev } from '../Common/Deving'; import { Command } from '../Editor/CommandMachine'; @@ -16,7 +15,7 @@ export class DrawSky implements Command sky.scale.setScalar(50); sky.rotateY(Math.PI); - let mat = sky.material as THREE.ShaderMaterial; + let mat = sky.material as ShaderMaterial; mat.uniforms.sub; window["sky"] = sky; } diff --git a/src/Add-on/DrawZeroCircle.ts b/src/Add-on/DrawZeroCircle.ts index 9d47ec039..4d2ae828f 100644 --- a/src/Add-on/DrawZeroCircle.ts +++ b/src/Add-on/DrawZeroCircle.ts @@ -1,5 +1,5 @@ -import * as THREE from 'three'; +import { Vector3 } from 'three'; import { app } from '../ApplicationServices/Application'; import { Circle } from '../DatabaseServices/Entity/Circle'; import { Line } from '../DatabaseServices/Entity/Line'; @@ -9,16 +9,16 @@ export class DrawCircle0 implements Command { async exec() { - let cir = new Circle(new THREE.Vector3(0, 0, 0), 10); + let cir = new Circle(new Vector3(0, 0, 0), 10); app.Database.ModelSpace.Append(cir); - let p = new THREE.Vector3(0, 0, 0); + let p = new Vector3(0, 0, 0); app.Viewer.WorldToScreen(p); app.Viewer.ScreenToWorld(p); - let line = new Line(new THREE.Vector3(0, 0, 0), new THREE.Vector3(100, 0, 0)); + let line = new Line(new Vector3(0, 0, 0), new Vector3(100, 0, 0)); app.Database.ModelSpace.Append(line); } diff --git a/src/Common/SetMaterial.ts b/src/Common/SetMaterial.ts index aba10847d..8c0ada22c 100644 --- a/src/Common/SetMaterial.ts +++ b/src/Common/SetMaterial.ts @@ -1,7 +1,6 @@ -import * as THREE from 'three'; +import { Material, Object3D } from "three"; - -export function SetMaterial(obj: THREE.Object3D, material: THREE.Material) +export function SetMaterial(obj: Object3D, material: Material) { if (obj.hasOwnProperty("material")) { diff --git a/src/DatabaseServices/3DSolid/Cylineder.ts b/src/DatabaseServices/3DSolid/Cylineder.ts index 7f4ce06dc..d8677248a 100644 --- a/src/DatabaseServices/3DSolid/Cylineder.ts +++ b/src/DatabaseServices/3DSolid/Cylineder.ts @@ -1,8 +1,7 @@ -import * as THREE from 'three'; -import { MeshNormalMaterial, Object3D, Geometry, Vector3, ExtrudeGeometry } from "three"; +import { ExtrudeGeometry, Geometry, Mesh, MeshNormalMaterial, Object3D, Vector3 } from "three"; import { RenderType } from "../../GraphicsSystem/RenderType"; -import { CADFiler } from '../CADFiler'; import { Factory } from '../CADFactory'; +import { CADFiler } from '../CADFiler'; import { Contour } from '../Contour'; import { Circle } from '../Entity/Circle'; import { Entity } from '../Entity/Entity'; @@ -60,11 +59,11 @@ export class Cylineder extends Entity } InitDrawObject(renderType: RenderType): Object3D { - return new THREE.Mesh(this.CreateGeometry(), new MeshNormalMaterial()); + return new Mesh(this.CreateGeometry(), new MeshNormalMaterial()); } UpdateDrawObject(type: RenderType, en: Object3D) { - let obj = en as THREE.Mesh; + let obj = en as Mesh; obj.geometry = this.CreateGeometry(); (obj.geometry as Geometry).verticesNeedUpdate = true; } diff --git a/src/DatabaseServices/CADFactory.ts b/src/DatabaseServices/CADFactory.ts index 7a1cb7c15..5ed5dd66c 100644 --- a/src/DatabaseServices/CADFactory.ts +++ b/src/DatabaseServices/CADFactory.ts @@ -1,4 +1,6 @@ +//const UE_REX_DEL = /_.*/g; + /** * CAD对象工厂,通过注册 和暴露的创建方法,动态创建对象 */ @@ -9,6 +11,7 @@ export class CADFactory private static factory = new CADFactory(); static RegisterObject(C: any) { + //this.factory.objectNameMap.set(C.name.replace(UE_REX_DEL, ""), C); this.factory.objectNameMap.set(C.name, C); } static RegisterObjectAlias(C: any, name: string) diff --git a/src/GraphicsSystem/Octree.ts b/src/GraphicsSystem/Octree.ts index 76b60f836..64f5c6096 100644 --- a/src/GraphicsSystem/Octree.ts +++ b/src/GraphicsSystem/Octree.ts @@ -1,6 +1,5 @@ -import { Vector3, LineSegments } from "three"; -import { isNumber, isArray } from "util"; -import * as THREE from 'three'; +import { BoxGeometry, BoxHelper, Color, LineSegments, Mesh, Vector3 } from "three"; +import { isArray, isNumber } from "util"; function toArray(target) { @@ -86,7 +85,7 @@ export class Octree if (this.scene) { - var helper = new THREE.BoxHelper(new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1)), new THREE.Color(0xff0066)); + var helper = new BoxHelper(new Mesh(new BoxGeometry(1, 1, 1)), new Color(0xff0066)); this.visualGeometry = helper.geometry; this.visualMaterial = helper.material; @@ -181,9 +180,9 @@ export class Octree class OctreeNode { // utility - utilVec31Branch = new THREE.Vector3(); - utilVec31Expand = new THREE.Vector3(); - utilVec31Ray = new THREE.Vector3(); + utilVec31Branch = new Vector3(); + utilVec31Expand = new Vector3(); + utilVec31Ray = new Vector3(); tree; id; position; @@ -785,7 +784,7 @@ class OctreeNode overlap = radius * this.tree.overlapPct; radiusOffset = radius - overlap; offset = this.utilVec31Branch.set(indexOctant & 1 ? radiusOffset : - radiusOffset, indexOctant & 2 ? radiusOffset : - radiusOffset, indexOctant & 4 ? radiusOffset : - radiusOffset); - position = new THREE.Vector3().addVectors(this.position, offset); + position = new Vector3().addVectors(this.position, offset); // node @@ -1005,7 +1004,7 @@ class OctreeNode radiusOffset = (radiusParent + overlapParent) - (radius + overlap); offset.set(indexOctant & 1 ? radiusOffset : - radiusOffset, indexOctant & 2 ? radiusOffset : - radiusOffset, indexOctant & 4 ? radiusOffset : - radiusOffset); - position = new THREE.Vector3().addVectors(this.position, offset); + position = new Vector3().addVectors(this.position, offset); // parent diff --git a/src/WebCADView/WebCADView.ts b/src/WebCADView/WebCADView.ts index 1ee4bf00d..283bbaa18 100644 --- a/src/WebCADView/WebCADView.ts +++ b/src/WebCADView/WebCADView.ts @@ -1,5 +1,4 @@ -import * as THREE from 'three'; - +import { BufferGeometry, EdgesGeometry, FileLoader, LineBasicMaterial, LineSegments, Matrix4, Object3D } from 'three'; import { ColorMaterial } from '../Common/ColorPalette'; import { SetMaterial } from '../Common/SetMaterial'; import { CameraControls } from '../Editor/CameraControls'; @@ -24,44 +23,44 @@ interface LoadFileRes */ export class WebCADView { - m_EdgeEntitytList: Array = []; - m_SolidEntityList: Array = []; + _EdgeEntitytList: Array = []; + _SolidEntityList: Array = []; - m_Viewer: Viewer; - m_CamerCtrl: CameraControls; + _Viewer: Viewer; + _CamerCtrl: CameraControls; /** * Creates an instance of WebCADView. - * + * * 构造函数,提供一个dom节点.. - * - * @param {HTMLElement} domNode + * + * @param {HTMLElement} domNode * @memberof WebCADView */ constructor(domNode: HTMLElement) { window["app"] = this; //渲染器 - this.m_Viewer = new Viewer(domNode); + this._Viewer = new Viewer(domNode); //相机控制 - this.m_CamerCtrl = new CameraControls(this.m_Viewer); + this._CamerCtrl = new CameraControls(this._Viewer); } - WriteEdge(obj: THREE.Object3D, color?: number) + WriteEdge(obj: Object3D, color?: number) { if (obj.hasOwnProperty("geometry")) { - let edge = new THREE.EdgesGeometry((obj["geometry"]), 1); + let edge = new EdgesGeometry((obj["geometry"]), 1); - let move = new THREE.Matrix4(); + let move = new Matrix4(); move.makeTranslation(1500, 0, 0); // edge.applyMatrix(move) if (!color) color = 7; - var line = new THREE.LineSegments(edge, ColorMaterial.GetLineMaterial(color)); + var line = new LineSegments(edge, ColorMaterial.GetLineMaterial(color)); line.userData.color = color; - this.m_Viewer.Scene.add(line); + this._Viewer.Scene.add(line); - this.m_EdgeEntitytList.push(line); + this._EdgeEntitytList.push(line); } else { @@ -69,10 +68,10 @@ export class WebCADView } } /** - * + * * 加载场景 - * - * @param {string} jsonFile + * + * @param {string} jsonFile * @memberof WebCADView */ async Load(jsonFile: string, pathUrl: string) @@ -87,29 +86,29 @@ export class WebCADView { let Material = ColorMaterial.GetLineMaterial(element.Color); SetMaterial(fbxObj.object, Material); - this.m_Viewer.Scene.add(fbxObj.object); + this._Viewer.Scene.add(fbxObj.object); - this.m_SolidEntityList.push(fbxObj.object); + this._SolidEntityList.push(fbxObj.object); fbxObj.object.visible = true; this.WriteEdge(fbxObj.object, element.Color); } } - this.m_Viewer.UpdateRender(); + this._Viewer.UpdateRender(); } /** * 加载json - * - * @param {string} jsonFile - * @returns {Promise} + * + * @param {string} jsonFile + * @returns {Promise} * @memberof WebCADView */ LoadJson(jsonFile: string): Promise { return new Promise((res, rej) => { - let loader = new THREE.FileLoader(); + let loader = new FileLoader(); //load a text file a output the result to the console loader.load( @@ -146,41 +145,41 @@ export class WebCADView //缩放到全部 ZoomAll() { - this.m_Viewer.ZoomAll(); + this._Viewer.ZoomAll(); } //前视图 ViewToFont() { - this.m_Viewer.ViewToFront(); + this._Viewer.ViewToFront(); } //俯视图 ViewToTop() { - this.m_Viewer.ViewToTop(); + this._Viewer.ViewToTop(); } //西南等轴视图 SolidShow() { - for (let e of this.m_SolidEntityList) + for (let e of this._SolidEntityList) { e.visible = true; } - for (let e of this.m_EdgeEntitytList) + for (let e of this._EdgeEntitytList) { - (e.material).color = ColorMaterial.GetColor(7); + (e.material).color = ColorMaterial.GetColor(7); } } EdgeShow() { - for (let e of this.m_SolidEntityList) + for (let e of this._SolidEntityList) { e.visible = false; } - for (let e of this.m_EdgeEntitytList) + for (let e of this._EdgeEntitytList) { - (e.material).color = ColorMaterial.GetColor(e.userData.color); + (e.material).color = ColorMaterial.GetColor(e.userData.color); } } } diff --git a/src/webview.ts b/src/webview.ts index 8fc9208d8..ec089d4f2 100644 --- a/src/webview.ts +++ b/src/webview.ts @@ -1,4 +1,4 @@ -import * as THREE from 'three'; +import { AmbientLight, Vector3 } from 'three'; import '../../Css/switchTheme.less'; import { CameraControlState } from './Editor/CameraControls'; import './UI/Css/style.less'; @@ -40,7 +40,7 @@ window.onload = async () => window.addEventListener("resize", () => { - app.m_Viewer.OnSize(); + app._Viewer.OnSize(); }); let param = parseQuery(window.location.search); @@ -49,8 +49,8 @@ window.onload = async () => { await app.Load(`${cdnUrl}${param["id"]}.json`, cdnUrl); } - let hemiLight = new THREE.AmbientLight(0xffffff, 3); - app.m_Viewer.Scene.add(hemiLight); + let hemiLight = new AmbientLight(0xffffff, 3); + app._Viewer.Scene.add(hemiLight); app.EdgeShow(); app.ZoomAll(); @@ -61,13 +61,13 @@ window.onload = async () => createBtn("缩放", content, () => { - app.m_Viewer.ZoomAll(); + app._Viewer.ZoomAll(); }); createBtn("俯视", content, () => { app.ViewToTop(); - app.m_Viewer.ZoomAll(); + app._Viewer.ZoomAll(); }); createBtn("前视", content, () => @@ -77,38 +77,38 @@ window.onload = async () => }); createBtn("西南", content, () => { - app.m_Viewer.CameraCtrl.LookAt(new THREE.Vector3(1, 1, -1)); + app._Viewer.CameraCtrl.LookAt(new Vector3(1, 1, -1)); app.ZoomAll(); }); createBtn("右视", content, () => { - app.m_Viewer.CameraCtrl.LookAt(new THREE.Vector3(-1, 0, 0)); + app._Viewer.CameraCtrl.LookAt(new Vector3(-1, 0, 0)); app.ZoomAll(); }); createBtn("实体", content, () => { app.SolidShow(); - app.m_Viewer.UpdateRender(); + app._Viewer.UpdateRender(); }); createBtn("线框", content, () => { app.EdgeShow(); - app.m_Viewer.UpdateRender(); + app._Viewer.UpdateRender(); }); let btn: HTMLElement; function rotateSwithMove() { - if (app.m_CamerCtrl.TouchTypeList[0] == CameraControlState.Rotate) + if (app._CamerCtrl.TouchTypeList[0] == CameraControlState.Rotate) { - app.m_CamerCtrl.TouchTypeList[0] = CameraControlState.Pan; + app._CamerCtrl.TouchTypeList[0] = CameraControlState.Pan; btn.textContent = "平移"; } else { - app.m_CamerCtrl.TouchTypeList[0] = CameraControlState.Rotate; + app._CamerCtrl.TouchTypeList[0] = CameraControlState.Rotate; btn.textContent = "旋转"; }