Added target sphere to pick preview
This commit is contained in:
parent
263879d215
commit
17206abca7
@ -4,6 +4,7 @@ import {
|
||||
MeshBuilder,
|
||||
Observable,
|
||||
Observer,
|
||||
Ray,
|
||||
Scene,
|
||||
TransformNode,
|
||||
Vector3,
|
||||
@ -33,14 +34,34 @@ export class ConnectionPreview {
|
||||
this._parent = input.pointer;
|
||||
this._fromId = fromMesh.id;
|
||||
this._transform = new TransformNode("transform", this._scene);
|
||||
|
||||
this._transform.position = point.clone();
|
||||
this._transform.setParent(this._parent);
|
||||
this._fromPoint = fromMesh.getAbsolutePosition();
|
||||
|
||||
const target = MeshBuilder.CreateSphere("target", {segments: 8, diameter: .02});
|
||||
target.parent = this._transform;
|
||||
const ray: Ray = new Ray(fromMesh.getAbsolutePosition(), target.absoluteScaling);
|
||||
const pick = this._scene.pickWithRay(ray, (mesh) => {
|
||||
return mesh.id === "target";
|
||||
});
|
||||
|
||||
target.isPickable = false;
|
||||
|
||||
if (pick.pickedPoint) {
|
||||
console.log('picked');
|
||||
this._options = {
|
||||
points: [this._fromPoint, pick.pickedPoint],
|
||||
updatable: true,
|
||||
useAlphaForLines: false,
|
||||
};
|
||||
} else {
|
||||
this._options = {
|
||||
points: [this._fromPoint, this._transform.absolutePosition],
|
||||
updatable: true,
|
||||
useAlphaForLines: false,
|
||||
};
|
||||
}
|
||||
this._line = MeshBuilder.CreateLines("connectionPreview", this._options, this._scene);
|
||||
this._options.instance = this._line;
|
||||
this._renderObserver = this._scene.onBeforeRenderObservable.add(() => {
|
||||
@ -53,7 +74,7 @@ export class ConnectionPreview {
|
||||
public dispose() {
|
||||
this._scene.onBeforeRenderObservable.remove(this._renderObserver);
|
||||
this._parent = null;
|
||||
this._transform.dispose();
|
||||
this._transform.dispose(false, true);
|
||||
this._line.dispose();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user