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

test(particles.cloudPoint): add tests for intersectsMesh function #12992

Merged
merged 1 commit into from Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 19 additions & 19 deletions packages/dev/core/src/Particles/cloudPoint.ts
Expand Up @@ -149,29 +149,29 @@ export class CloudPoint {
if (!target.hasBoundingInfo) {
return false;
}
isSphere = isSphere ? isSphere : false;

if (!this._pcs.mesh) {
throw new Error("Point Cloud System doesnt contain the Mesh");
}

if (isSphere) {
return target.getBoundingInfo().boundingSphere.intersectsPoint(this.position.add(this._pcs.mesh.position));
} else {
let maxX = 0;
let minX = 0;
let maxY = 0;
let minY = 0;
let maxZ = 0;
let minZ = 0;
maxX = target.getBoundingInfo().boundingBox.maximumWorld.x;
minX = target.getBoundingInfo().boundingBox.minimumWorld.x;
maxY = target.getBoundingInfo().boundingBox.maximumWorld.y;
minY = target.getBoundingInfo().boundingBox.minimumWorld.y;
maxZ = target.getBoundingInfo().boundingBox.maximumWorld.z;
minZ = target.getBoundingInfo().boundingBox.minimumWorld.z;

const x = this.position.x + this._pcs.mesh.position.x;
const y = this.position.y + this._pcs.mesh.position.y;
const z = this.position.z + this._pcs.mesh.position.z;
return minX <= x && x <= maxX && minY <= y && y <= maxY && minZ <= z && z <= maxZ;
}

const bbox = target.getBoundingInfo().boundingBox;

const maxX = bbox.maximumWorld.x;
const minX = bbox.minimumWorld.x;
const maxY = bbox.maximumWorld.y;
const minY = bbox.minimumWorld.y;
const maxZ = bbox.maximumWorld.z;
const minZ = bbox.minimumWorld.z;

const x = this.position.x + this._pcs.mesh.position.x;
const y = this.position.y + this._pcs.mesh.position.y;
const z = this.position.z + this._pcs.mesh.position.z;

return minX <= x && x <= maxX && minY <= y && y <= maxY && minZ <= z && z <= maxZ;
}

/**
Expand Down
46 changes: 28 additions & 18 deletions packages/dev/core/src/Particles/pointsCloudSystem.ts
Expand Up @@ -57,7 +57,7 @@ export class PointsCloudSystem implements IDisposable {
/**
* The PCS mesh. It's a standard BJS Mesh, so all the methods from the Mesh class are available.
*/
public mesh: Mesh;
public mesh?: Mesh;
/**
* This empty object is intended to store some PCS specific or temporary values in order to lower the Garbage Collector activity.
* Please read :
Expand Down Expand Up @@ -765,15 +765,15 @@ export class PointsCloudSystem implements IDisposable {
Matrix.IdentityToRef(rotMatrix);
let idx = 0; // current index of the particle

if (this.mesh.isFacetDataEnabled) {
if (this.mesh?.isFacetDataEnabled) {
this._computeBoundingBox = true;
}

end = end >= this.nbParticles ? this.nbParticles - 1 : end;
if (this._computeBoundingBox) {
if (start != 0 || end != this.nbParticles - 1) {
// only some particles are updated, then use the current existing BBox basis. Note : it can only increase.
const boundingInfo = this.mesh.getBoundingInfo();
const boundingInfo = this.mesh?.getBoundingInfo();
if (boundingInfo) {
minimum.copyFrom(boundingInfo.minimum);
maximum.copyFrom(boundingInfo.maximum);
Expand Down Expand Up @@ -907,21 +907,23 @@ export class PointsCloudSystem implements IDisposable {
}

// if the VBO must be updated
if (update) {
if (this._computeParticleColor) {
mesh.updateVerticesData(VertexBuffer.ColorKind, colors32, false, false);
}
if (this._computeParticleTexture) {
mesh.updateVerticesData(VertexBuffer.UVKind, uvs32, false, false);
if (mesh) {
if (update) {
if (this._computeParticleColor) {
mesh.updateVerticesData(VertexBuffer.ColorKind, colors32, false, false);
}
if (this._computeParticleTexture) {
mesh.updateVerticesData(VertexBuffer.UVKind, uvs32, false, false);
}
mesh.updateVerticesData(VertexBuffer.PositionKind, positions32, false, false);
}
mesh.updateVerticesData(VertexBuffer.PositionKind, positions32, false, false);
}

if (this._computeBoundingBox) {
if (mesh.hasBoundingInfo) {
mesh.getBoundingInfo().reConstruct(minimum, maximum, mesh._worldMatrix);
} else {
mesh.buildBoundingInfo(minimum, maximum, mesh._worldMatrix);
if (this._computeBoundingBox) {
if (mesh.hasBoundingInfo) {
mesh.getBoundingInfo().reConstruct(minimum, maximum, mesh._worldMatrix);
} else {
mesh.buildBoundingInfo(minimum, maximum, mesh._worldMatrix);
}
}
}
this.afterUpdateParticles(start, end, update);
Expand All @@ -932,7 +934,7 @@ export class PointsCloudSystem implements IDisposable {
* Disposes the PCS.
*/
public dispose(): void {
this.mesh.dispose();
this.mesh?.dispose();
this.vars = null;
// drop references to internal big arrays for the GC
(<any>this._positions) = null;
Expand All @@ -953,7 +955,7 @@ export class PointsCloudSystem implements IDisposable {
*/
public refreshVisibleSize(): PointsCloudSystem {
if (!this._isVisibilityBoxLocked) {
this.mesh.refreshBoundingInfo();
this.mesh?.refreshBoundingInfo();
}
return this;
}
Expand All @@ -965,6 +967,10 @@ export class PointsCloudSystem implements IDisposable {
* doc :
*/
public setVisibilityBox(size: number): void {
if (!this.mesh) {
return;
}

const vis = size / 2;
this.mesh.buildBoundingInfo(new Vector3(-vis, -vis, -vis), new Vector3(vis, vis, vis));
}
Expand All @@ -982,6 +988,10 @@ export class PointsCloudSystem implements IDisposable {
* doc :
*/
public set isAlwaysVisible(val: boolean) {
if (!this.mesh) {
return;
}

this._alwaysVisible = val;
this.mesh.alwaysSelectAsActiveMesh = val;
}
Expand Down