|
@@ -14,6 +14,7 @@ import { DirectionalLight } from '../Lights/directionalLight';
|
|
import { SphereBuilder } from '../Meshes/Builders/sphereBuilder';
|
|
import { SphereBuilder } from '../Meshes/Builders/sphereBuilder';
|
|
import { HemisphereBuilder } from '../Meshes/Builders/hemisphereBuilder';
|
|
import { HemisphereBuilder } from '../Meshes/Builders/hemisphereBuilder';
|
|
import { SpotLight } from '../Lights/spotLight';
|
|
import { SpotLight } from '../Lights/spotLight';
|
|
|
|
+import { TransformNode } from '../Meshes/transformNode';
|
|
|
|
|
|
/**
|
|
/**
|
|
* Gizmo that enables viewing a light
|
|
* Gizmo that enables viewing a light
|
|
@@ -21,8 +22,9 @@ import { SpotLight } from '../Lights/spotLight';
|
|
export class LightGizmo extends Gizmo {
|
|
export class LightGizmo extends Gizmo {
|
|
private _lightMesh: Mesh;
|
|
private _lightMesh: Mesh;
|
|
private _material: StandardMaterial;
|
|
private _material: StandardMaterial;
|
|
- private cachedPosition = new Vector3();
|
|
|
|
- private cachedForward = new Vector3(0, 0, 1);
|
|
|
|
|
|
+ private _cachedPosition = new Vector3();
|
|
|
|
+ private _cachedForward = new Vector3(0, 0, 1);
|
|
|
|
+ private _attachedMeshParent: TransformNode;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Creates a LightGizmo
|
|
* Creates a LightGizmo
|
|
@@ -31,6 +33,9 @@ export class LightGizmo extends Gizmo {
|
|
constructor(gizmoLayer?: UtilityLayerRenderer) {
|
|
constructor(gizmoLayer?: UtilityLayerRenderer) {
|
|
super(gizmoLayer);
|
|
super(gizmoLayer);
|
|
this.attachedMesh = new AbstractMesh("", this.gizmoLayer.utilityLayerScene);
|
|
this.attachedMesh = new AbstractMesh("", this.gizmoLayer.utilityLayerScene);
|
|
|
|
+ this._attachedMeshParent = new TransformNode("parent", this.gizmoLayer.originalScene);
|
|
|
|
+
|
|
|
|
+ this.attachedMesh.parent = this._attachedMeshParent;
|
|
this._material = new StandardMaterial("light", this.gizmoLayer.originalScene);
|
|
this._material = new StandardMaterial("light", this.gizmoLayer.originalScene);
|
|
this._material.diffuseColor = new Color3(0.5, 0.5, 0.5);
|
|
this._material.diffuseColor = new Color3(0.5, 0.5, 0.5);
|
|
this._material.specularColor = new Color3(0.1, 0.1, 0.1);
|
|
this._material.specularColor = new Color3(0.1, 0.1, 0.1);
|
|
@@ -73,6 +78,10 @@ export class LightGizmo extends Gizmo {
|
|
}
|
|
}
|
|
this.attachedMesh!.reservedDataStore.lightGizmo = this;
|
|
this.attachedMesh!.reservedDataStore.lightGizmo = this;
|
|
|
|
|
|
|
|
+ if (light.parent) {
|
|
|
|
+ this._attachedMeshParent.freezeWorldMatrix(light.parent.getWorldMatrix());
|
|
|
|
+ }
|
|
|
|
+
|
|
// Get update position and direction if the light has it
|
|
// Get update position and direction if the light has it
|
|
if ((light as any).position) {
|
|
if ((light as any).position) {
|
|
this.attachedMesh!.position.copyFrom((light as any).position);
|
|
this.attachedMesh!.position.copyFrom((light as any).position);
|
|
@@ -104,12 +113,17 @@ export class LightGizmo extends Gizmo {
|
|
if (!this._light) {
|
|
if (!this._light) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (this._light.parent) {
|
|
|
|
+ this._attachedMeshParent.freezeWorldMatrix(this._light.parent.getWorldMatrix());
|
|
|
|
+ }
|
|
|
|
+
|
|
if ((this._light as any).position) {
|
|
if ((this._light as any).position) {
|
|
// If the gizmo is moved update the light otherwise update the gizmo to match the light
|
|
// If the gizmo is moved update the light otherwise update the gizmo to match the light
|
|
- if (!this.attachedMesh!.position.equals(this.cachedPosition)) {
|
|
|
|
|
|
+ if (!this.attachedMesh!.position.equals(this._cachedPosition)) {
|
|
// update light to match gizmo
|
|
// update light to match gizmo
|
|
(this._light as any).position.copyFrom(this.attachedMesh!.position);
|
|
(this._light as any).position.copyFrom(this.attachedMesh!.position);
|
|
- this.cachedPosition.copyFrom(this.attachedMesh!.position);
|
|
|
|
|
|
+ this._cachedPosition.copyFrom(this.attachedMesh!.position);
|
|
} else {
|
|
} else {
|
|
// update gizmo to match light
|
|
// update gizmo to match light
|
|
this.attachedMesh!.position.copyFrom((this._light as any).position);
|
|
this.attachedMesh!.position.copyFrom((this._light as any).position);
|
|
@@ -118,14 +132,14 @@ export class LightGizmo extends Gizmo {
|
|
}
|
|
}
|
|
if ((this._light as any).direction) {
|
|
if ((this._light as any).direction) {
|
|
// If the gizmo is moved update the light otherwise update the gizmo to match the light
|
|
// If the gizmo is moved update the light otherwise update the gizmo to match the light
|
|
- if (Vector3.DistanceSquared(this.attachedMesh!.forward, this.cachedForward) > 0.0001) {
|
|
|
|
|
|
+ if (Vector3.DistanceSquared(this.attachedMesh!.forward, this._cachedForward) > 0.0001) {
|
|
// update light to match gizmo
|
|
// update light to match gizmo
|
|
(this._light as any).direction.copyFrom(this.attachedMesh!.forward);
|
|
(this._light as any).direction.copyFrom(this.attachedMesh!.forward);
|
|
- this.cachedForward.copyFrom(this.attachedMesh!.forward);
|
|
|
|
|
|
+ this._cachedForward.copyFrom(this.attachedMesh!.forward);
|
|
} else if (Vector3.DistanceSquared(this.attachedMesh!.forward, (this._light as any).direction) > 0.0001) {
|
|
} else if (Vector3.DistanceSquared(this.attachedMesh!.forward, (this._light as any).direction) > 0.0001) {
|
|
// update gizmo to match light
|
|
// update gizmo to match light
|
|
this.attachedMesh!.setDirection((this._light as any).direction);
|
|
this.attachedMesh!.setDirection((this._light as any).direction);
|
|
- this.cachedForward.copyFrom(this._lightMesh.forward);
|
|
|
|
|
|
+ this._cachedForward.copyFrom(this._lightMesh.forward);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!this._light.isEnabled()) {
|
|
if (!this._light.isEnabled()) {
|
|
@@ -141,7 +155,7 @@ export class LightGizmo extends Gizmo {
|
|
/**
|
|
/**
|
|
* Creates the lines for a light mesh
|
|
* Creates the lines for a light mesh
|
|
*/
|
|
*/
|
|
- private static _createLightLines = (levels: number, scene: Scene) => {
|
|
|
|
|
|
+ private static _CreateLightLines = (levels: number, scene: Scene) => {
|
|
var distFromSphere = 1.2;
|
|
var distFromSphere = 1.2;
|
|
|
|
|
|
var root = new Mesh("root", scene);
|
|
var root = new Mesh("root", scene);
|
|
@@ -204,6 +218,7 @@ export class LightGizmo extends Gizmo {
|
|
public dispose() {
|
|
public dispose() {
|
|
this._material.dispose();
|
|
this._material.dispose();
|
|
super.dispose();
|
|
super.dispose();
|
|
|
|
+ this._attachedMeshParent.dispose();
|
|
}
|
|
}
|
|
|
|
|
|
private static _CreateHemisphericLightMesh(scene: Scene) {
|
|
private static _CreateHemisphericLightMesh(scene: Scene) {
|
|
@@ -213,7 +228,7 @@ export class LightGizmo extends Gizmo {
|
|
hemisphere.rotation.x = Math.PI / 2;
|
|
hemisphere.rotation.x = Math.PI / 2;
|
|
hemisphere.parent = root;
|
|
hemisphere.parent = root;
|
|
|
|
|
|
- var lines = this._createLightLines(3, scene);
|
|
|
|
|
|
+ var lines = this._CreateLightLines(3, scene);
|
|
lines.parent = root;
|
|
lines.parent = root;
|
|
lines.position.z - 0.15;
|
|
lines.position.z - 0.15;
|
|
|
|
|
|
@@ -229,7 +244,7 @@ export class LightGizmo extends Gizmo {
|
|
sphere.rotation.x = Math.PI / 2;
|
|
sphere.rotation.x = Math.PI / 2;
|
|
sphere.parent = root;
|
|
sphere.parent = root;
|
|
|
|
|
|
- var lines = this._createLightLines(5, scene);
|
|
|
|
|
|
+ var lines = this._CreateLightLines(5, scene);
|
|
lines.parent = root;
|
|
lines.parent = root;
|
|
root.scaling.scaleInPlace(LightGizmo._Scale);
|
|
root.scaling.scaleInPlace(LightGizmo._Scale);
|
|
root.rotation.x = Math.PI / 2;
|
|
root.rotation.x = Math.PI / 2;
|
|
@@ -246,7 +261,7 @@ export class LightGizmo extends Gizmo {
|
|
hemisphere.parent = root;
|
|
hemisphere.parent = root;
|
|
hemisphere.rotation.x = -Math.PI / 2;
|
|
hemisphere.rotation.x = -Math.PI / 2;
|
|
|
|
|
|
- var lines = this._createLightLines(2, scene);
|
|
|
|
|
|
+ var lines = this._CreateLightLines(2, scene);
|
|
lines.parent = root;
|
|
lines.parent = root;
|
|
root.scaling.scaleInPlace(LightGizmo._Scale);
|
|
root.scaling.scaleInPlace(LightGizmo._Scale);
|
|
root.rotation.x = Math.PI / 2;
|
|
root.rotation.x = Math.PI / 2;
|