Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We��ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gizmo fixes #6763

Merged
merged 11 commits into from
Jun 28, 2024
Prev Previous commit
Next Next commit
refactor variable names
  • Loading branch information
kpal81xd committed Jun 27, 2024
commit 0c3a7ae2c7bd44062d0e851cfc5c9deb829eafbf
20 changes: 11 additions & 9 deletions src/extras/gizmo/gizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,21 @@ class Gizmo extends EventHandler {
const selection = [];
for (let i = 0; i < this.intersectData.length; i++) {
const { triData, parent, meshInstances } = this.intersectData[i];
const wtm = parent.getWorldTransform();
const parentTM = parent.getWorldTransform();
for (let j = 0; j < triData.length; j++) {
const { tris, ptm, priority } = triData[j];
tmpM1.copy(wtm).mul(ptm);
tmpM2.copy(tmpM1).invert();
tmpM2.transformPoint(start, tmpR1.origin);
tmpM2.transformVector(dir, tmpR1.direction);
tmpR1.direction.normalize();
const { tris, transform, priority } = triData[j];
const triWTM = tmpM1.copy(parentTM).mul(transform);
const invTriWTM = tmpM2.copy(triWTM).invert();

const ray = tmpR1;
invTriWTM.transformPoint(start, ray.origin);
invTriWTM.transformVector(dir, ray.direction);
ray.direction.normalize();

for (let k = 0; k < tris.length; k++) {
if (tris[k].intersectsRay(tmpR1, tmpV1)) {
if (tris[k].intersectsRay(ray, tmpV1)) {
selection.push({
dist: tmpM1.transformPoint(tmpV1).sub(start).length(),
dist: triWTM.transformPoint(tmpV1).sub(start).length(),
meshInstances: meshInstances,
priority: priority
});
Expand Down
8 changes: 4 additions & 4 deletions src/extras/gizmo/tri-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TriData {
*
* @type {Mat4}
*/
_ptm = new Mat4();
_transform = new Mat4();

/**
* The array of triangles for the geometry.
Expand All @@ -47,16 +47,16 @@ class TriData {
this._priority = priority;
}

get ptm() {
return this._ptm;
get transform() {
return this._transform;
}

get priority() {
return this._priority;
}

setTransform(pos = new Vec3(), rot = new Quat(), scale = new Vec3()) {
this.ptm.setTRS(pos, rot, scale);
this.transform.setTRS(pos, rot, scale);
}

calculateTris(geometry) {
Expand Down