Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (mesh.reservedDataStore && mesh.reservedDataStore.wireframeOver) {
mesh.reservedDataStore.wireframeOver.dispose(false, true);
mesh.reservedDataStore.wireframeOver = null;
this.forceUpdate();
return;
}
var wireframeOver = mesh.clone()!;
wireframeOver.reservedDataStore = { hidden: true };
// Sets up the mesh to be attached to the parent.
// So all neutral in local space.
wireframeOver.parent = mesh;
wireframeOver.position = Vector3.Zero();
wireframeOver.scaling = new Vector3(1, 1, 1);
wireframeOver.rotation = Vector3.Zero();
wireframeOver.rotationQuaternion = null;
var material = new StandardMaterial("wireframeOver", scene);
material.reservedDataStore = { hidden: true };
wireframeOver.material = material;
material.zOffset = 1;
material.disableLighting = true;
material.backFaceCulling = false;
material.emissiveColor = Color3.White();
material.wireframe = true;
if (!mesh.reservedDataStore) {
mesh.reservedDataStore = {};
}
if (node.reservedDataStore.axisViewer) {
node.reservedDataStore.axisViewer.dispose();
node.reservedDataStore.axisViewer = null;
scene.onBeforeRenderObservable.remove(node.reservedDataStore.onBeforeRenderObserver);
node.reservedDataStore.onBeforeRenderObserver = null;
this.setState({ displayAxis: false });
return;
}
const viewer = new AxesViewer(scene);
node.reservedDataStore.axisViewer = viewer;
const x = new Vector3(1, 0, 0);
const y = new Vector3(0, 1, 0);
const z = new Vector3(0, 0, 1);
viewer.xAxis.reservedDataStore = { hidden: true };
viewer.yAxis.reservedDataStore = { hidden: true };
viewer.zAxis.reservedDataStore = { hidden: true };
node.reservedDataStore.onBeforeRenderObserver = scene.onBeforeRenderObservable.add(() => {
let cameraMatrix = scene.activeCamera!.getWorldMatrix();
let matrix = node.getWorldMatrix();
let extend = Tmp.Vector3[0];
Vector3.TransformCoordinatesFromFloatsToRef(0, 0, 1, cameraMatrix, extend);
viewer.scaleLines = extend.length() / 10;
viewer.update(node.getAbsolutePosition(), Vector3.TransformNormal(x, matrix), Vector3.TransformNormal(y, matrix), Vector3.TransformNormal(z, matrix));
});
node.reservedDataStore.axisViewer.dispose();
node.reservedDataStore.axisViewer = null;
scene.onBeforeRenderObservable.remove(node.reservedDataStore.onBeforeRenderObserver);
node.reservedDataStore.onBeforeRenderObserver = null;
this.setState({ displayAxis: false });
return;
}
const viewer = new AxesViewer(scene);
node.reservedDataStore.axisViewer = viewer;
const x = new Vector3(1, 0, 0);
const y = new Vector3(0, 1, 0);
const z = new Vector3(0, 0, 1);
viewer.xAxis.reservedDataStore = { hidden: true };
viewer.yAxis.reservedDataStore = { hidden: true };
viewer.zAxis.reservedDataStore = { hidden: true };
node.reservedDataStore.onBeforeRenderObserver = scene.onBeforeRenderObservable.add(() => {
let cameraMatrix = scene.activeCamera!.getWorldMatrix();
let matrix = node.getWorldMatrix();
let extend = Tmp.Vector3[0];
Vector3.TransformCoordinatesFromFloatsToRef(0, 0, 1, cameraMatrix, extend);
viewer.scaleLines = extend.length() / 10;
viewer.update(node.getAbsolutePosition(), Vector3.TransformNormal(x, matrix), Vector3.TransformNormal(y, matrix), Vector3.TransformNormal(z, matrix));
});
this.setState({ displayAxis: true });
public loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void = () => { }): Promise {
const extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
if (extensionPromise) {
return extensionPromise;
}
const promises = new Array>();
this.logOpen(`${context} ${camera.name || ""}`);
const babylonCamera = new FreeCamera(camera.name || `camera${camera.index}`, Vector3.Zero(), this._babylonScene, false);
babylonCamera.rotation = new Vector3(0, Math.PI, 0);
switch (camera.type) {
case CameraType.PERSPECTIVE: {
const perspective = camera.perspective;
if (!perspective) {
throw new Error(`${context}: Camera perspective properties are missing`);
}
babylonCamera.fov = perspective.yfov;
babylonCamera.minZ = perspective.znear;
babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
break;
}
case CameraType.ORTHOGRAPHIC: {
if (!camera.orthographic) {
throw new Error(`${context}: Camera orthographic properties are missing`);
public loadCameraAsync(context: string, camera: ICamera, assign: (babylonCamera: Camera) => void = () => { }): Promise {
const extensionPromise = this._extensionsLoadCameraAsync(context, camera, assign);
if (extensionPromise) {
return extensionPromise;
}
const promises = new Array>();
this.logOpen(`${context} ${camera.name || ""}`);
const babylonCamera = new FreeCamera(camera.name || `camera${camera.index}`, Vector3.Zero(), this._babylonScene, false);
babylonCamera.rotation = new Vector3(0, Math.PI, 0);
switch (camera.type) {
case CameraType.PERSPECTIVE: {
const perspective = camera.perspective;
if (!perspective) {
throw new Error(`${context}: Camera perspective properties are missing`);
}
babylonCamera.fov = perspective.yfov;
babylonCamera.minZ = perspective.znear;
babylonCamera.maxZ = perspective.zfar || Number.MAX_VALUE;
break;
}
case CameraType.ORTHOGRAPHIC: {
if (!camera.orthographic) {
throw new Error(`${context}: Camera orthographic properties are missing`);
public get scaling(): Vector3 {
if (!this._node) {
return new Vector3(1, 1, 1);
}
return this._node.scaling;
}
protected _mapGridNode(control: Control3D, nodePosition: Vector3) {
let mesh = control.mesh;
if (!mesh) {
return;
}
let newPos = this._sphericalMapping(nodePosition);
control.position = newPos;
switch (this.orientation) {
case Container3D.FACEORIGIN_ORIENTATION:
mesh.lookAt(new Vector3(2 * newPos.x, 2 * newPos.y, 2 * newPos.z));
break;
case Container3D.FACEORIGINREVERSED_ORIENTATION:
mesh.lookAt(new Vector3(-newPos.x, -newPos.y, -newPos.z));
break;
case Container3D.FACEFORWARD_ORIENTATION:
break;
case Container3D.FACEFORWARDREVERSED_ORIENTATION:
mesh.rotate(Axis.Y, Math.PI, Space.LOCAL);
break;
}
}
private _sphericalMapping(source: Vector3) {
let newPos = new Vector3(0, 0, this._radius);
let xAngle = (source.y / this._radius);
let yAngle = -(source.x / this._radius);
Matrix.RotationYawPitchRollToRef(yAngle, xAngle, 0, TmpVectors.Matrix[0]);
return Vector3.TransformNormal(newPos, TmpVectors.Matrix[0]);
}
}
protected _mapGridNode(control: Control3D, nodePosition: Vector3) {
let mesh = control.mesh;
let newPos = this._scatterMapping(nodePosition);
if (!mesh) {
return;
}
switch (this.orientation) {
case Container3D.FACEORIGIN_ORIENTATION:
case Container3D.FACEFORWARD_ORIENTATION:
mesh.lookAt(new Vector3(0, 0, 1));
break;
case Container3D.FACEFORWARDREVERSED_ORIENTATION:
case Container3D.FACEORIGINREVERSED_ORIENTATION:
mesh.lookAt(new Vector3(0, 0, -1));
break;
}
control.position = newPos;
}
protected _mapGridNode(control: Control3D, nodePosition: Vector3) {
let mesh = control.mesh;
if (!mesh) {
return;
}
control.position = nodePosition.clone();
let target = TmpVectors.Vector3[0];
target.copyFrom(nodePosition);
switch (this.orientation) {
case Container3D.FACEORIGIN_ORIENTATION:
case Container3D.FACEFORWARD_ORIENTATION:
target.addInPlace(new Vector3(0, 0, 1));
mesh.lookAt(target);
break;
case Container3D.FACEFORWARDREVERSED_ORIENTATION:
case Container3D.FACEORIGINREVERSED_ORIENTATION:
target.addInPlace(new Vector3(0, 0, -1));
mesh.lookAt(target);
break;
}
}
}