添加缩放全部功能

pull/7/head
ChenX 7 years ago
parent 302ce77891
commit 4acce41929

1057
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,34 +1,16 @@
import { RenderType } from '../src/GraphicsSystem/Enum';
import { Solid3d } from '../src/DatabaseServices/Entity';
import * as THREE from 'three';
import { GeUtils } from "../src/Geometry/GeUtils";
let box = new Solid3d(10, 10, 10);
let obj = box.Draw(RenderType.Wireframe);
function getBox(obj: THREE.Object3D): THREE.Box3
{
if (obj.hasOwnProperty("geometry"))
{
let geom = obj["geometry"];
geom.computeBoundingBox();
return geom.boundingBox;
}
else
{
if (obj.children.length > 0)
{
let box;
for (var index = 0; index < obj.children.length; index++)
{
var element = obj.children[index];
let box2 = getBox(element);
if (box2)
{
if (box)
{
box.union(box2);
}
else
box = box2;
}
}
return box;
}
return null;
}
}
let move = new THREE.Matrix4();
move.makeTranslation(100, 0, 0);
box.applyMatrix4(move);
let b = GeUtils.GetBox(obj, true);
console.log('b: ', b);

@ -6,6 +6,7 @@ import * as _ from "lodash";
import { UndoData } from '../DatabaseServices/UndoData';
import { PromptStatus } from '../Editor/PromptResult';
import * as ReactDOM from 'react-dom';
import { GeUtils } from "../Geometry/GeUtils";
export class DrawLine implements Command
{
@ -54,3 +55,12 @@ export class Redo implements Command
undoData.redo(1);
}
}
export class ZoomE implements Command
{
async exec()
{
app.m_Viewer.ZoomAll();
app.m_Editor.UpdateScreen();
}
}

@ -1,5 +1,7 @@
import { app } from '../ApplicationServices/Application';
import * as THREE from 'three';
export function log(msg)
{
app.m_Editor.m_CommandStore.Prompt(msg);
}
}

@ -59,4 +59,39 @@ export namespace GeUtils
{
return v1.clone().add(v2).multiplyScalar(0.5);
}
}
export function GetBox(obj: THREE.Object3D, updateMatrix?: boolean): THREE.Box3
{
if (updateMatrix) obj.updateMatrixWorld(false);
if (obj.hasOwnProperty("geometry"))
{
let geom: THREE.Geometry = obj["geometry"];
geom.computeBoundingBox();
return geom.boundingBox.applyMatrix4(obj.matrixWorld);
}
else if (obj.children.length > 0)
{
let box: THREE.Box3;
obj.children.forEach(element =>
{
let box2 = GetBox(element);
if (box2)
{
if (box)
{
box.union(box2);
}
else
box = box2
}
})
if (box) box.applyMatrix4(obj.matrixWorld);
return box;
}
else
return null;
}
}

@ -304,8 +304,6 @@ export class Viewer
{
this.ViewLookAt(1, 1, -1);
}
/**
*
*
@ -346,9 +344,8 @@ export class Viewer
}
this.m_Camera.Update();
}
ZoomAll()
{
// this.ZoomExtensBox3(getBox(this.m_Scene))
this.ZoomExtensBox3(GeUtils.GetBox(this.m_Scene, true));
}
}

@ -12,7 +12,7 @@ import { Provider } from "mobx-react";
import { ApplicationService, app } from './ApplicationServices/Application';
import { DownPanel } from './UI/Components/Panel';
import { DownPanelStore } from './UI/Store/DownPanelStore';
import { DrawLine, Undo, Redo } from './Add-on/DrawLine';
import { DrawLine, Undo, Redo, ZoomE } from './Add-on/DrawLine';
import { UndoData } from './DatabaseServices/UndoData';
import { Solid3d, Line } from './DatabaseServices/Entity';
import { Vector3 } from 'three';
@ -57,6 +57,7 @@ function initApp()
app.m_Editor.m_CommandMachine.m_CommandList.set("l", new DrawLine())
app.m_Editor.m_CommandMachine.m_CommandList.set("u", new Undo())
app.m_Editor.m_CommandMachine.m_CommandList.set("redo", new Redo())
app.m_Editor.m_CommandMachine.m_CommandList.set("ze", new ZoomE())
// let box = new Solid3d(10, 10, 10);
// app.m_Database.appendEntity(box)

Loading…
Cancel
Save