开发:清理代码

pull/1920/MERGE
ChenX 2 years ago
parent c9ba8d4706
commit 8f50141956

@ -1,4 +1,5 @@
import * as THREE from 'three';
import { Vector3 } from 'three';
import { AllObjectData } from '../../src/DatabaseServices/AllObjectData'; import { AllObjectData } from '../../src/DatabaseServices/AllObjectData';
import { BlockTableRecord } from '../../src/DatabaseServices/BlockTableRecord'; import { BlockTableRecord } from '../../src/DatabaseServices/BlockTableRecord';
import { CADFactory } from '../../src/DatabaseServices/CADFactory'; import { CADFactory } from '../../src/DatabaseServices/CADFactory';
@ -8,8 +9,8 @@ import { CommandHistoryRecord } from '../../src/DatabaseServices/CommandHistoryR
import { CreateObjectData } from '../../src/DatabaseServices/CreateObjectData'; import { CreateObjectData } from '../../src/DatabaseServices/CreateObjectData';
import { Database } from '../../src/DatabaseServices/Database'; import { Database } from '../../src/DatabaseServices/Database';
import { Entity } from '../../src/DatabaseServices/Entity/Entity'; import { Entity } from '../../src/DatabaseServices/Entity/Entity';
import { HistorycRecord } from '../../src/DatabaseServices/HistorycRecord';
import { Line } from '../../src/DatabaseServices/Entity/Line'; import { Line } from '../../src/DatabaseServices/Entity/Line';
import { HistorycRecord } from '../../src/DatabaseServices/HistorycRecord';
import { ObjectAllDataHistoryRecord } from '../../src/DatabaseServices/ObjectAllDataHistoryRecord'; import { ObjectAllDataHistoryRecord } from '../../src/DatabaseServices/ObjectAllDataHistoryRecord';
import { RemoveObjectData } from '../../src/DatabaseServices/RemoveObjectData'; import { RemoveObjectData } from '../../src/DatabaseServices/RemoveObjectData';
@ -82,7 +83,7 @@ test('clone object', () =>
let db = new Database(); let db = new Database();
let line = new Line(); let line = new Line();
db.ModelSpace.Append(line); db.ModelSpace.Append(line);
line.StartPoint = new THREE.Vector3(9, 9, 8); line.StartPoint = new Vector3(9, 9, 8);
CadObjectToString(line);/*?*/ CadObjectToString(line);/*?*/
@ -107,7 +108,7 @@ test('changev', () =>
expect(id.Object !== l1).toBeTruthy(); //创建对象的撤销和重做后 id指向了新的实体 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(); let file = db.FileWrite();
expect(file.ToString()/*?*/).toMatchSnapshot(); expect(file.ToString()/*?*/).toMatchSnapshot();
@ -134,14 +135,14 @@ test('xxx', () =>
db.hm.Redo(); //? db.hm.Redo(); //?
// db.hm.StartCmd(""); // db.hm.StartCmd("");
(id1.Object as Line).StartPoint = new THREE.Vector3(10, 4, 2); (id1.Object as Line).StartPoint = new Vector3(10, 4, 2);
(id1.Object as Line).EndPoint = new THREE.Vector3(2, 2, 2); (id1.Object as Line).EndPoint = new Vector3(2, 2, 2);
let file = db.FileWrite(); let file = db.FileWrite();
db.hm.StartCmd(""); db.hm.StartCmd("");
(id1.Object as Line).StartPoint = new THREE.Vector3(100, 300, 400); (id1.Object as Line).StartPoint = new Vector3(100, 300, 400);
(id1.Object as Line).EndPoint = new THREE.Vector3(2000, 3000, 4000); (id1.Object as Line).EndPoint = new Vector3(2000, 3000, 4000);
db.hm.Undo(); db.hm.Undo();
@ -169,7 +170,7 @@ test('创建 修改 撤销撤销 重做重做 撤销 重做', () =>
let line = new Line(); let line = new Line();
db.ModelSpace.Append(line); db.ModelSpace.Append(line);
db.hm.StartCmd("U"); db.hm.StartCmd("U");
line.StartPoint = new THREE.Vector3(1, 2, 3); line.StartPoint = new Vector3(1, 2, 3);
db.hm.EndCmd(); db.hm.EndCmd();
db.hm.Undo(); /*?*/ db.hm.Undo(); /*?*/

@ -1,4 +1,3 @@
import * as THREE from 'three';
import { Vector3 } from 'three'; import { Vector3 } from 'three';
import { Arc } from '../../src/DatabaseServices/Entity/Arc'; import { Arc } from '../../src/DatabaseServices/Entity/Arc';
import { Circle } from '../../src/DatabaseServices/Entity/Circle'; import { Circle } from '../../src/DatabaseServices/Entity/Circle';
@ -9,13 +8,13 @@ import { LoadCurvesFromFileData, LoadEntityFromFileData } from '../Utils/LoadEnt
test('相交测试', () => test('相交测试', () =>
{ {
let p1 = new THREE.Vector3(0, 0, 0); let p1 = new Vector3(0, 0, 0);
let p2 = new THREE.Vector3(1, 0, 0); let p2 = new Vector3(1, 0, 0);
let p3 = new THREE.Vector3(0.5, 0.5, 0); let p3 = new Vector3(0.5, 0.5, 0);
let p4 = new THREE.Vector3(0.5, 1, 0); let p4 = new Vector3(0.5, 1, 0);
let p5 = new THREE.Vector3(3, 0, 0); let p5 = new Vector3(3, 0, 0);
let p6 = new THREE.Vector3(6, 0, 0); let p6 = new Vector3(6, 0, 0);
let res = IntersectLine3AndLine3(p1, p2, p3, p4);/*?*/ let res = IntersectLine3AndLine3(p1, p2, p3, p4);/*?*/
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
@ -24,22 +23,22 @@ test('相交测试', () =>
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
let ins = IntersectLine3AndLine3( let ins = IntersectLine3AndLine3(
new THREE.Vector3(0, 5), new Vector3(0, 5),
new THREE.Vector3(5, 5), new Vector3(5, 5),
new THREE.Vector3(0.5, 1), new Vector3(0.5, 1),
new THREE.Vector3(0.5, 8)); new Vector3(0.5, 8));
expect(ins).toMatchSnapshot(); expect(ins).toMatchSnapshot();
}); });
test('三维空间直线相交测试', () => test('三维空间直线相交测试', () =>
{ {
let p1 = new THREE.Vector3(); let p1 = new Vector3();
let p2 = new THREE.Vector3(10, 10, 10); let p2 = new Vector3(10, 10, 10);
let p3 = new THREE.Vector3(5, 5, 5); let p3 = new Vector3(5, 5, 5);
let p4 = new THREE.Vector3(5, 10, 5); let p4 = new Vector3(5, 10, 5);
let p5 = new THREE.Vector3(3, 3, 3); let p5 = new Vector3(3, 3, 3);
let p6 = new THREE.Vector3(6, 6, 6); let p6 = new Vector3(6, 6, 6);
let res = IntersectLine3AndLine3(p1, p2, p3, p4);/*?*/ let res = IntersectLine3AndLine3(p1, p2, p3, p4);/*?*/
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();

@ -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 { begin } from 'xaop';
import { app } from '../ApplicationServices/Application'; import { app } from '../ApplicationServices/Application';
import { Command } from '../Editor/CommandMachine'; import { Command } from '../Editor/CommandMachine';
export class DrawFloor implements Command export class DrawFloor implements Command
{ {
textureLoader: THREE.TextureLoader; textureLoader: TextureLoader;
get scene() get scene()
{ {
@ -13,7 +13,7 @@ export class DrawFloor implements Command
} }
constructor() constructor()
{ {
this.textureLoader = new THREE.TextureLoader(); this.textureLoader = new TextureLoader();
} }
async exec() async exec()
{ {
@ -44,7 +44,7 @@ export class DrawFloor implements Command
private drawFloor() private drawFloor()
{ {
let floorMat = new THREE.MeshStandardMaterial({ let floorMat = new MeshStandardMaterial({
roughness: 0.8, roughness: 0.8,
color: 0xffffff, color: 0xffffff,
metalness: 0.2, metalness: 0.2,
@ -54,8 +54,8 @@ export class DrawFloor implements Command
}); });
this.materialList.push(floorMat); this.materialList.push(floorMat);
var floorGeometry = new THREE.PlaneGeometry(20, 20); var floorGeometry = new PlaneGeometry(20, 20);
var floorMesh = new THREE.Mesh(floorGeometry, floorMat); var floorMesh = new Mesh(floorGeometry, floorMat);
floorMesh.receiveShadow = true; floorMesh.receiveShadow = true;
this.scene.add(floorMesh); this.scene.add(floorMesh);
@ -66,7 +66,7 @@ export class DrawFloor implements Command
floorMat.transparent = true; floorMat.transparent = true;
floorMat.opacity = 0.9; floorMat.opacity = 0.9;
// let ref = new THREE.Reflector(20, 20, { // let ref = new Reflector(20, 20, {
// clipBias: 0.003, // clipBias: 0.003,
// textureWidth: app.m_Viewer.Width * window.devicePixelRatio, // textureWidth: app.m_Viewer.Width * window.devicePixelRatio,
// textureHeight: app.m_Viewer.Height * 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) this.textureLoader.load("textures/hardwood2_diffuse.jpg", function (map)
{ {
map.wrapS = THREE.RepeatWrapping; map.wrapS = RepeatWrapping;
map.wrapT = THREE.RepeatWrapping; map.wrapT = RepeatWrapping;
map.anisotropy = 16; map.anisotropy = 16;
map.repeat.set(10, 24); map.repeat.set(10, 24);
@ -97,27 +97,27 @@ export class DrawFloor implements Command
}); });
this.textureLoader.load("textures/hardwood2_bump.jpg", function (map) this.textureLoader.load("textures/hardwood2_bump.jpg", function (map)
{ {
map.wrapS = THREE.RepeatWrapping; map.wrapS = RepeatWrapping;
map.wrapT = THREE.RepeatWrapping; map.wrapT = RepeatWrapping;
map.anisotropy = 16; map.anisotropy = 16;
map.repeat.set(10, 24); map.repeat.set(10, 24);
self.materialList.forEach(m => self.materialList.forEach(m =>
{ {
(<THREE.MeshStandardMaterial>m).bumpMap = map; (<MeshStandardMaterial>m).bumpMap = map;
m.needsUpdate = true; m.needsUpdate = true;
}); });
}); });
this.textureLoader.load("textures/hardwood2_roughness.jpg", function (map) this.textureLoader.load("textures/hardwood2_roughness.jpg", function (map)
{ {
map.wrapS = THREE.RepeatWrapping; map.wrapS = RepeatWrapping;
map.wrapT = THREE.RepeatWrapping; map.wrapT = RepeatWrapping;
map.anisotropy = 16; map.anisotropy = 16;
map.repeat.set(10, 24); map.repeat.set(10, 24);
self.materialList.forEach(m => self.materialList.forEach(m =>
{ {
(<THREE.MeshStandardMaterial>m).roughnessMap = map; (<MeshStandardMaterial>m).roughnessMap = map;
m.needsUpdate = true; m.needsUpdate = true;
}); });
}); });
@ -125,18 +125,18 @@ export class DrawFloor implements Command
drawLight() drawLight()
{ {
var bulbGeometry = new THREE.SphereGeometry(0.02, 16, 8); var bulbGeometry = new SphereGeometry(0.02, 16, 8);
// let bulbLight = new THREE.PointLight(0xffee88, 1.5, 100, 1); // let bulbLight = new PointLight(0xffee88, 1.5, 100, 1);
let bulbLight = new THREE.PointLight(0x999999, 1.5, 100, 2); let bulbLight = new PointLight(0x999999, 1.5, 100, 2);
let bulbMat = new THREE.MeshStandardMaterial({ let bulbMat = new MeshStandardMaterial({
emissive: 0xffffee, emissive: 0xffffee,
emissiveIntensity: 1, emissiveIntensity: 1,
color: 0x000000 color: 0x000000
}); });
bulbLight.add(new THREE.Mesh(bulbGeometry, bulbMat)); bulbLight.add(new Mesh(bulbGeometry, bulbMat));
bulbLight.position.set(0, 2, 2); bulbLight.position.set(0, 2, 2);
bulbLight.castShadow = true; bulbLight.castShadow = true;
@ -150,7 +150,7 @@ export class DrawFloor implements Command
this.scene.add(light2); this.scene.add(light2);
var clock = new THREE.Clock(); var clock = new Clock();
begin(app.Viewer, app.Viewer.StartRender, () => begin(app.Viewer, app.Viewer.StartRender, () =>
{ {
var time = Date.now() * 0.0005; var time = Date.now() * 0.0005;
@ -162,8 +162,8 @@ export class DrawFloor implements Command
private drawHemiLight() private drawHemiLight()
{ {
//0xddeeff 0x0f0e0d //0xddeeff 0x0f0e0d
// var hemiLight = new THREE.HemisphereLight(0xffffff, 0xffffff, 0.05); // var hemiLight = new HemisphereLight(0xffffff, 0xffffff, 0.05);
var hemiLight = new THREE.HemisphereLight(0xddeeff, 0x0f0e0d, 0.05); var hemiLight = new HemisphereLight(0xddeeff, 0x0f0e0d, 0.05);
hemiLight.intensity = 23; hemiLight.intensity = 23;
this.scene.add(hemiLight); this.scene.add(hemiLight);
} }
@ -171,7 +171,7 @@ export class DrawFloor implements Command
drawWall() drawWall()
{ {
// let floorMat = new THREE.MeshStandardMaterial({ // let floorMat = new MeshStandardMaterial({
// roughness: 0.8, // roughness: 0.8,
// color: 0xffffff, // color: 0xffffff,
// metalness: 0.2, // metalness: 0.2,
@ -180,8 +180,8 @@ export class DrawFloor implements Command
// this.textureLoader.load("textures/wallmap.png", function (map) // this.textureLoader.load("textures/wallmap.png", function (map)
// { // {
// map.wrapS = THREE.RepeatWrapping; // map.wrapS = RepeatWrapping;
// map.wrapT = THREE.RepeatWrapping; // map.wrapT = RepeatWrapping;
// map.anisotropy = 4; // map.anisotropy = 4;
// map.repeat.set(10, 24); // map.repeat.set(10, 24);
// floorMat.map = map; // floorMat.map = map;
@ -190,7 +190,7 @@ export class DrawFloor implements Command
// let wallFont = new Solid3d(4, 0.12, 2.8); // 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.material = floorMat;
// obj.castShadow = true; // obj.castShadow = true;
@ -200,18 +200,18 @@ export class DrawFloor implements Command
// let objRight = obj.clone(); // 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); // roMatLeft.makeRotationZ(Math.PI / 2);
// objLeft.applyMatrix(roMatLeft); // objLeft.applyMatrix(roMatLeft);
// let roMatRight = new THREE.Matrix4(); // let roMatRight = new Matrix4();
// roMatRight.makeRotationZ(Math.PI / 2); // roMatRight.makeRotationZ(Math.PI / 2);
// objRight.applyMatrix(roMatRight); // objRight.applyMatrix(roMatRight);
// objLeft.applyMatrix(Move(new THREE.Vector3(-2, 0, 0))) // objLeft.applyMatrix(Move(new Vector3(-2, 0, 0)))
// objRight.applyMatrix(Move(new THREE.Vector3(2, 0, 0))) // objRight.applyMatrix(Move(new Vector3(2, 0, 0)))
// this.scene.add(obj); // this.scene.add(obj);
@ -219,7 +219,7 @@ export class DrawFloor implements Command
// this.scene.add(objRight); // this.scene.add(objRight);
// let skyMaterail = new THREE.MeshStandardMaterial({ // let skyMaterail = new MeshStandardMaterial({
// roughness: 0.8, // roughness: 0.8,
// color: 0xffffff, // color: 0xffffff,
// metalness: 0.2, // metalness: 0.2,
@ -227,10 +227,10 @@ export class DrawFloor implements Command
// }) // })
// //天花板. // //天花板.
// let skyWall = new Solid3d(4.12, 4, 0.12); // 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.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); // this.scene.add(skyObj);
} }
@ -243,7 +243,7 @@ export class DrawFloor implements Command
// obj.castShadow = true; // obj.castShadow = true;
// let mat = new THREE.MeshStandardMaterial({ // let mat = new MeshStandardMaterial({
// roughness: 0.8, // roughness: 0.8,
// color: 0xffffff, // color: 0xffffff,
// metalness: 0.2, // metalness: 0.2,
@ -252,14 +252,14 @@ export class DrawFloor implements Command
// this.textureLoader.load("textures/door.png", function (map) // this.textureLoader.load("textures/door.png", function (map)
// { // {
// map.wrapS = THREE.RepeatWrapping; // map.wrapS = RepeatWrapping;
// map.wrapT = THREE.RepeatWrapping; // map.wrapT = RepeatWrapping;
// map.anisotropy = 16; // map.anisotropy = 16;
// map.repeat.set(1, 1); // map.repeat.set(1, 1);
// mat.map = map; // mat.map = map;
// mat.needsUpdate = true; // mat.needsUpdate = true;
// }); // });
// (<THREE.Mesh>obj).material = mat; // (<Mesh>obj).material = mat;
// this.scene.add(obj); // this.scene.add(obj);
@ -275,8 +275,8 @@ export class DrawFloor implements Command
path + 'posy' + format, path + 'negy' + format, path + 'posy' + format, path + 'negy' + format,
path + 'posz' + format, path + 'negz' + format path + 'posz' + format, path + 'negz' + format
]; ];
var textureCube = new THREE.CubeTextureLoader().load(urls); var textureCube = new CubeTextureLoader().load(urls);
textureCube.format = THREE.RGBFormat; textureCube.format = RGBFormat;
return textureCube; return textureCube;
}; };
@ -286,17 +286,17 @@ export class DrawFloor implements Command
// let obj = solid.Draw(RenderType.Wireframe); // 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.position.set(0, 0, 1);
// obj.castShadow = true; // obj.castShadow = true;
// let cubeCamera1 = new THREE.CubeCamera(0.1, 15, 1024); // let cubeCamera1 = new CubeCamera(0.1, 15, 1024);
// let cubeCamera2 = new THREE.CubeCamera(0.1, 15, 1024); // let cubeCamera2 = new CubeCamera(0.1, 15, 1024);
// cubeCamera1.position.set(0, 0, 1); // cubeCamera1.position.set(0, 0, 1);
// cubeCamera2.position.set(0, 0, 1); // cubeCamera2.position.set(0, 0, 1);
// cubeCamera1.renderTarget.texture.minFilter = THREE.LinearMipMapLinearFilter; // cubeCamera1.renderTarget.texture.minFilter = LinearMipMapLinearFilter;
// cubeCamera2.renderTarget.texture.minFilter = THREE.LinearMipMapLinearFilter; // cubeCamera2.renderTarget.texture.minFilter = LinearMipMapLinearFilter;
// cubeCamera1.renderTarget.texture.anisotropy = 16; // cubeCamera1.renderTarget.texture.anisotropy = 16;
// cubeCamera2.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, // roughness: 0.8,
// metalness: 0.8, // metalness: 0.8,
// // color: 0xffffff, // // color: 0xffffff,
@ -319,8 +319,8 @@ export class DrawFloor implements Command
// this.textureLoader.load("textures/Metal/130616_header2.jpg", function (map) // this.textureLoader.load("textures/Metal/130616_header2.jpg", function (map)
// { // {
// map.wrapS = THREE.RepeatWrapping; // map.wrapS = RepeatWrapping;
// map.wrapT = THREE.RepeatWrapping; // map.wrapT = RepeatWrapping;
// map.anisotropy = 16; // map.anisotropy = 16;
// map.repeat.set(1, 1); // map.repeat.set(1, 1);
// mat.map = map; // mat.map = map;
@ -329,8 +329,8 @@ export class DrawFloor implements Command
// this.textureLoader.load("textures/Metal/Titanium-Scuffed_basecolor.png", function (map) // this.textureLoader.load("textures/Metal/Titanium-Scuffed_basecolor.png", function (map)
// { // {
// map.wrapS = THREE.RepeatWrapping; // map.wrapS = RepeatWrapping;
// map.wrapT = THREE.RepeatWrapping; // map.wrapT = RepeatWrapping;
// map.anisotropy = 16; // map.anisotropy = 16;
// map.repeat.set(1, 1); // map.repeat.set(1, 1);
// mat.map = map; // mat.map = map;
@ -338,8 +338,8 @@ export class DrawFloor implements Command
// }); // });
// this.textureLoader.load("textures/Metal/Titanium-Scuffed_roughness.png", function (map) // this.textureLoader.load("textures/Metal/Titanium-Scuffed_roughness.png", function (map)
// { // {
// map.wrapS = THREE.RepeatWrapping; // map.wrapS = RepeatWrapping;
// map.wrapT = THREE.RepeatWrapping; // map.wrapT = RepeatWrapping;
// map.anisotropy = 16; // map.anisotropy = 16;
// map.repeat.set(1, 1); // map.repeat.set(1, 1);
// mat.roughnessMap = map; // mat.roughnessMap = map;
@ -347,8 +347,8 @@ export class DrawFloor implements Command
// }); // });
// this.textureLoader.load("textures/Metal/Titanium-Scuffed_normal.png", function (map) // this.textureLoader.load("textures/Metal/Titanium-Scuffed_normal.png", function (map)
// { // {
// map.wrapS = THREE.RepeatWrapping; // map.wrapS = RepeatWrapping;
// map.wrapT = THREE.RepeatWrapping; // map.wrapT = RepeatWrapping;
// map.anisotropy = 16; // map.anisotropy = 16;
// map.repeat.set(1, 1); // map.repeat.set(1, 1);
// mat.normalMap = map; // mat.normalMap = map;
@ -356,8 +356,8 @@ export class DrawFloor implements Command
// }); // });
// this.textureLoader.load("textures/Metal/Titanium-Scuffed_metallic.png", function (map) // this.textureLoader.load("textures/Metal/Titanium-Scuffed_metallic.png", function (map)
// { // {
// map.wrapS = THREE.RepeatWrapping; // map.wrapS = RepeatWrapping;
// map.wrapT = THREE.RepeatWrapping; // map.wrapT = RepeatWrapping;
// map.anisotropy = 16; // map.anisotropy = 16;
// map.repeat.set(1, 1); // map.repeat.set(1, 1);
// mat.metalnessMap = map; // mat.metalnessMap = map;
@ -388,7 +388,7 @@ export class DrawFloor implements Command
// // obj.visible = true; // // obj.visible = true;
// // isOne = !isOne; // // isOne = !isOne;
// // }); // // });
// (<THREE.Mesh>obj).material = mat; // (<Mesh>obj).material = mat;
// this.scene.add(obj); // this.scene.add(obj);
} }

@ -1,5 +1,4 @@
import * as THREE from 'three'; import { Geometry, Line, Mesh, Points, PointsMaterial } from 'three';
import { app } from '../ApplicationServices/Application'; import { app } from '../ApplicationServices/Application';
import { Command } from '../Editor/CommandMachine'; import { Command } from '../Editor/CommandMachine';
@ -16,9 +15,9 @@ export class DrawGripStretch implements Command
return; return;
} }
let geometry = new THREE.Geometry(); let geometry = new Geometry();
let material = new THREE.PointsMaterial({ let material = new PointsMaterial({
size: 15, size: 15,
color: 0x001dfa, color: 0x001dfa,
sizeAttenuation: false sizeAttenuation: false
@ -27,9 +26,9 @@ export class DrawGripStretch implements Command
for (let en of app.Viewer.OutlinePass.selectedObjects) 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) 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); app.Viewer.Scene.add(pts);
} }
} }

@ -1,5 +1,4 @@
import * as THREE from 'three'; import { ShaderMaterial } from 'three';
import { app } from '../ApplicationServices/Application'; import { app } from '../ApplicationServices/Application';
import { IsDev } from '../Common/Deving'; import { IsDev } from '../Common/Deving';
import { Command } from '../Editor/CommandMachine'; import { Command } from '../Editor/CommandMachine';
@ -16,7 +15,7 @@ export class DrawSky implements Command
sky.scale.setScalar(50); sky.scale.setScalar(50);
sky.rotateY(Math.PI); sky.rotateY(Math.PI);
let mat = sky.material as THREE.ShaderMaterial; let mat = sky.material as ShaderMaterial;
mat.uniforms.sub; mat.uniforms.sub;
window["sky"] = sky; window["sky"] = sky;
} }

@ -1,5 +1,5 @@
import * as THREE from 'three';
import { Vector3 } from 'three';
import { app } from '../ApplicationServices/Application'; import { app } from '../ApplicationServices/Application';
import { Circle } from '../DatabaseServices/Entity/Circle'; import { Circle } from '../DatabaseServices/Entity/Circle';
import { Line } from '../DatabaseServices/Entity/Line'; import { Line } from '../DatabaseServices/Entity/Line';
@ -9,16 +9,16 @@ export class DrawCircle0 implements Command
{ {
async exec() 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); 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.WorldToScreen(p);
app.Viewer.ScreenToWorld(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); app.Database.ModelSpace.Append(line);
} }

@ -1,7 +1,6 @@
import * as THREE from 'three'; import { Material, Object3D } from "three";
export function SetMaterial(obj: Object3D, material: Material)
export function SetMaterial(obj: THREE.Object3D, material: THREE.Material)
{ {
if (obj.hasOwnProperty("material")) if (obj.hasOwnProperty("material"))
{ {

@ -1,8 +1,7 @@
import * as THREE from 'three'; import { ExtrudeGeometry, Geometry, Mesh, MeshNormalMaterial, Object3D, Vector3 } from "three";
import { MeshNormalMaterial, Object3D, Geometry, Vector3, ExtrudeGeometry } from "three";
import { RenderType } from "../../GraphicsSystem/RenderType"; import { RenderType } from "../../GraphicsSystem/RenderType";
import { CADFiler } from '../CADFiler';
import { Factory } from '../CADFactory'; import { Factory } from '../CADFactory';
import { CADFiler } from '../CADFiler';
import { Contour } from '../Contour'; import { Contour } from '../Contour';
import { Circle } from '../Entity/Circle'; import { Circle } from '../Entity/Circle';
import { Entity } from '../Entity/Entity'; import { Entity } from '../Entity/Entity';
@ -60,11 +59,11 @@ export class Cylineder extends Entity
} }
InitDrawObject(renderType: RenderType): Object3D InitDrawObject(renderType: RenderType): Object3D
{ {
return new THREE.Mesh(this.CreateGeometry(), new MeshNormalMaterial()); return new Mesh(this.CreateGeometry(), new MeshNormalMaterial());
} }
UpdateDrawObject(type: RenderType, en: Object3D) UpdateDrawObject(type: RenderType, en: Object3D)
{ {
let obj = en as THREE.Mesh; let obj = en as Mesh;
obj.geometry = this.CreateGeometry(); obj.geometry = this.CreateGeometry();
(obj.geometry as Geometry).verticesNeedUpdate = true; (obj.geometry as Geometry).verticesNeedUpdate = true;
} }

@ -1,4 +1,6 @@
//const UE_REX_DEL = /_.*/g;
/** /**
* CAD, , * CAD, ,
*/ */
@ -9,6 +11,7 @@ export class CADFactory
private static factory = new CADFactory(); private static factory = new CADFactory();
static RegisterObject(C: any) static RegisterObject(C: any)
{ {
//this.factory.objectNameMap.set(C.name.replace(UE_REX_DEL, ""), C);
this.factory.objectNameMap.set(C.name, C); this.factory.objectNameMap.set(C.name, C);
} }
static RegisterObjectAlias(C: any, name: string) static RegisterObjectAlias(C: any, name: string)

@ -1,6 +1,5 @@
import { Vector3, LineSegments } from "three"; import { BoxGeometry, BoxHelper, Color, LineSegments, Mesh, Vector3 } from "three";
import { isNumber, isArray } from "util"; import { isArray, isNumber } from "util";
import * as THREE from 'three';
function toArray(target) function toArray(target)
{ {
@ -86,7 +85,7 @@ export class Octree
if (this.scene) 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.visualGeometry = helper.geometry;
this.visualMaterial = helper.material; this.visualMaterial = helper.material;
@ -181,9 +180,9 @@ export class Octree
class OctreeNode class OctreeNode
{ {
// utility // utility
utilVec31Branch = new THREE.Vector3(); utilVec31Branch = new Vector3();
utilVec31Expand = new THREE.Vector3(); utilVec31Expand = new Vector3();
utilVec31Ray = new THREE.Vector3(); utilVec31Ray = new Vector3();
tree; tree;
id; id;
position; position;
@ -785,7 +784,7 @@ class OctreeNode
overlap = radius * this.tree.overlapPct; overlap = radius * this.tree.overlapPct;
radiusOffset = radius - overlap; radiusOffset = radius - overlap;
offset = this.utilVec31Branch.set(indexOctant & 1 ? radiusOffset : - radiusOffset, indexOctant & 2 ? radiusOffset : - radiusOffset, indexOctant & 4 ? radiusOffset : - radiusOffset); 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 // node
@ -1005,7 +1004,7 @@ class OctreeNode
radiusOffset = (radiusParent + overlapParent) - (radius + overlap); radiusOffset = (radiusParent + overlapParent) - (radius + overlap);
offset.set(indexOctant & 1 ? radiusOffset : - radiusOffset, indexOctant & 2 ? radiusOffset : - radiusOffset, indexOctant & 4 ? radiusOffset : - radiusOffset); 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 // parent

@ -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 { ColorMaterial } from '../Common/ColorPalette';
import { SetMaterial } from '../Common/SetMaterial'; import { SetMaterial } from '../Common/SetMaterial';
import { CameraControls } from '../Editor/CameraControls'; import { CameraControls } from '../Editor/CameraControls';
@ -24,44 +23,44 @@ interface LoadFileRes
*/ */
export class WebCADView export class WebCADView
{ {
m_EdgeEntitytList: Array<THREE.LineSegments> = []; _EdgeEntitytList: Array<LineSegments> = [];
m_SolidEntityList: Array<THREE.Object3D> = []; _SolidEntityList: Array<Object3D> = [];
m_Viewer: Viewer; _Viewer: Viewer;
m_CamerCtrl: CameraControls; _CamerCtrl: CameraControls;
/** /**
* Creates an instance of WebCADView. * Creates an instance of WebCADView.
* *
* ,dom.. * ,dom..
* *
* @param {HTMLElement} domNode * @param {HTMLElement} domNode
* @memberof WebCADView * @memberof WebCADView
*/ */
constructor(domNode: HTMLElement) constructor(domNode: HTMLElement)
{ {
window["app"] = this; 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")) if (obj.hasOwnProperty("geometry"))
{ {
let edge = new THREE.EdgesGeometry((<THREE.BufferGeometry>obj["geometry"]), 1); let edge = new EdgesGeometry((<BufferGeometry>obj["geometry"]), 1);
let move = new THREE.Matrix4(); let move = new Matrix4();
move.makeTranslation(1500, 0, 0); move.makeTranslation(1500, 0, 0);
// edge.applyMatrix(move) // edge.applyMatrix(move)
if (!color) color = 7; 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; 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 else
{ {
@ -69,10 +68,10 @@ export class WebCADView
} }
} }
/** /**
* *
* *
* *
* @param {string} jsonFile * @param {string} jsonFile
* @memberof WebCADView * @memberof WebCADView
*/ */
async Load(jsonFile: string, pathUrl: string) async Load(jsonFile: string, pathUrl: string)
@ -87,29 +86,29 @@ export class WebCADView
{ {
let Material = ColorMaterial.GetLineMaterial(element.Color); let Material = ColorMaterial.GetLineMaterial(element.Color);
SetMaterial(fbxObj.object, Material); 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; fbxObj.object.visible = true;
this.WriteEdge(fbxObj.object, element.Color); this.WriteEdge(fbxObj.object, element.Color);
} }
} }
this.m_Viewer.UpdateRender(); this._Viewer.UpdateRender();
} }
/** /**
* json * json
* *
* @param {string} jsonFile * @param {string} jsonFile
* @returns {Promise<LoadFileRes>} * @returns {Promise<LoadFileRes>}
* @memberof WebCADView * @memberof WebCADView
*/ */
LoadJson(jsonFile: string): Promise<LoadFileRes> LoadJson(jsonFile: string): Promise<LoadFileRes>
{ {
return new Promise<LoadFileRes>((res, rej) => return new Promise<LoadFileRes>((res, rej) =>
{ {
let loader = new THREE.FileLoader(); let loader = new FileLoader();
//load a text file a output the result to the console //load a text file a output the result to the console
loader.load( loader.load(
@ -146,41 +145,41 @@ export class WebCADView
//缩放到全部 //缩放到全部
ZoomAll() ZoomAll()
{ {
this.m_Viewer.ZoomAll(); this._Viewer.ZoomAll();
} }
//前视图 //前视图
ViewToFont() ViewToFont()
{ {
this.m_Viewer.ViewToFront(); this._Viewer.ViewToFront();
} }
//俯视图 //俯视图
ViewToTop() ViewToTop()
{ {
this.m_Viewer.ViewToTop(); this._Viewer.ViewToTop();
} }
//西南等轴视图 //西南等轴视图
SolidShow() SolidShow()
{ {
for (let e of this.m_SolidEntityList) for (let e of this._SolidEntityList)
{ {
e.visible = true; e.visible = true;
} }
for (let e of this.m_EdgeEntitytList) for (let e of this._EdgeEntitytList)
{ {
(<THREE.LineBasicMaterial>e.material).color = ColorMaterial.GetColor(7); (<LineBasicMaterial>e.material).color = ColorMaterial.GetColor(7);
} }
} }
EdgeShow() EdgeShow()
{ {
for (let e of this.m_SolidEntityList) for (let e of this._SolidEntityList)
{ {
e.visible = false; e.visible = false;
} }
for (let e of this.m_EdgeEntitytList) for (let e of this._EdgeEntitytList)
{ {
(<THREE.LineBasicMaterial>e.material).color = ColorMaterial.GetColor(e.userData.color); (<LineBasicMaterial>e.material).color = ColorMaterial.GetColor(e.userData.color);
} }
} }
} }

@ -1,4 +1,4 @@
import * as THREE from 'three'; import { AmbientLight, Vector3 } from 'three';
import '../../Css/switchTheme.less'; import '../../Css/switchTheme.less';
import { CameraControlState } from './Editor/CameraControls'; import { CameraControlState } from './Editor/CameraControls';
import './UI/Css/style.less'; import './UI/Css/style.less';
@ -40,7 +40,7 @@ window.onload = async () =>
window.addEventListener("resize", () => window.addEventListener("resize", () =>
{ {
app.m_Viewer.OnSize(); app._Viewer.OnSize();
}); });
let param = parseQuery(window.location.search); let param = parseQuery(window.location.search);
@ -49,8 +49,8 @@ window.onload = async () =>
{ {
await app.Load(`${cdnUrl}${param["id"]}.json`, cdnUrl); await app.Load(`${cdnUrl}${param["id"]}.json`, cdnUrl);
} }
let hemiLight = new THREE.AmbientLight(0xffffff, 3); let hemiLight = new AmbientLight(0xffffff, 3);
app.m_Viewer.Scene.add(hemiLight); app._Viewer.Scene.add(hemiLight);
app.EdgeShow(); app.EdgeShow();
app.ZoomAll(); app.ZoomAll();
@ -61,13 +61,13 @@ window.onload = async () =>
createBtn("缩放", content, () => createBtn("缩放", content, () =>
{ {
app.m_Viewer.ZoomAll(); app._Viewer.ZoomAll();
}); });
createBtn("俯视", content, () => createBtn("俯视", content, () =>
{ {
app.ViewToTop(); app.ViewToTop();
app.m_Viewer.ZoomAll(); app._Viewer.ZoomAll();
}); });
createBtn("前视", content, () => createBtn("前视", content, () =>
@ -77,38 +77,38 @@ window.onload = async () =>
}); });
createBtn("西南", content, () => createBtn("西南", content, () =>
{ {
app.m_Viewer.CameraCtrl.LookAt(new THREE.Vector3(1, 1, -1)); app._Viewer.CameraCtrl.LookAt(new Vector3(1, 1, -1));
app.ZoomAll(); app.ZoomAll();
}); });
createBtn("右视", content, () => createBtn("右视", content, () =>
{ {
app.m_Viewer.CameraCtrl.LookAt(new THREE.Vector3(-1, 0, 0)); app._Viewer.CameraCtrl.LookAt(new Vector3(-1, 0, 0));
app.ZoomAll(); app.ZoomAll();
}); });
createBtn("实体", content, () => createBtn("实体", content, () =>
{ {
app.SolidShow(); app.SolidShow();
app.m_Viewer.UpdateRender(); app._Viewer.UpdateRender();
}); });
createBtn("线框", content, () => createBtn("线框", content, () =>
{ {
app.EdgeShow(); app.EdgeShow();
app.m_Viewer.UpdateRender(); app._Viewer.UpdateRender();
}); });
let btn: HTMLElement; let btn: HTMLElement;
function rotateSwithMove() 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 = "平移"; btn.textContent = "平移";
} }
else else
{ {
app.m_CamerCtrl.TouchTypeList[0] = CameraControlState.Rotate; app._CamerCtrl.TouchTypeList[0] = CameraControlState.Rotate;
btn.textContent = "旋转"; btn.textContent = "旋转";
} }

Loading…
Cancel
Save