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

Add support for debug rendering obbs #6023

Merged
merged 2 commits into from Jan 31, 2024
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
5 changes: 3 additions & 2 deletions src/framework/app-base.js
Expand Up @@ -1794,15 +1794,16 @@ class AppBase extends EventHandler {
* @param {boolean} [depthTest] - Specifies if the sphere lines are depth tested against the
* depth buffer. Defaults to true.
* @param {Layer} [layer] - The layer to render the sphere into. Defaults to {@link LAYERID_IMMEDIATE}.
* @param {Mat4} [mat] - Matrix to transform the box before rendering.
* @example
* // Render a red wire aligned box
* const min = new pc.Vec3(-1, -1, -1);
* const max = new pc.Vec3(1, 1, 1);
* app.drawWireAlignedBox(min, max, pc.Color.RED);
* @ignore
*/
drawWireAlignedBox(minPoint, maxPoint, color = Color.WHITE, depthTest = true, layer = this.scene.defaultDrawLayer) {
this.scene.immediate.drawWireAlignedBox(minPoint, maxPoint, color, depthTest, layer);
drawWireAlignedBox(minPoint, maxPoint, color = Color.WHITE, depthTest = true, layer = this.scene.defaultDrawLayer, mat) {
this.scene.immediate.drawWireAlignedBox(minPoint, maxPoint, color, depthTest, layer, mat);
}

/**
Expand Down
54 changes: 39 additions & 15 deletions src/scene/immediate/immediate.js
Expand Up @@ -9,7 +9,10 @@ import { createShaderFromCode } from '../shader-lib/utils.js';
import { shaderChunks } from '../shader-lib/chunks/chunks.js';
import { ImmediateBatches } from './immediate-batches.js';

import { Vec3 } from '../../core/math/vec3.js';

const tempPoints = [];
const vec = new Vec3();

class Immediate {
constructor(device) {
Expand Down Expand Up @@ -167,21 +170,42 @@ class Immediate {
layerMeshInstances.push(meshInstance);
}

drawWireAlignedBox(min, max, color, depthTest, layer) {
tempPoints.push(
min.x, min.y, min.z, min.x, max.y, min.z,
min.x, max.y, min.z, max.x, max.y, min.z,
max.x, max.y, min.z, max.x, min.y, min.z,
max.x, min.y, min.z, min.x, min.y, min.z,
min.x, min.y, max.z, min.x, max.y, max.z,
min.x, max.y, max.z, max.x, max.y, max.z,
max.x, max.y, max.z, max.x, min.y, max.z,
max.x, min.y, max.z, min.x, min.y, max.z,
min.x, min.y, min.z, min.x, min.y, max.z,
min.x, max.y, min.z, min.x, max.y, max.z,
max.x, max.y, min.z, max.x, max.y, max.z,
max.x, min.y, min.z, max.x, min.y, max.z
);
drawWireAlignedBox(min, max, color, depthTest, layer, mat) {
if (mat) {
const mulPoint = (x, y, z) => {
vec.set(x, y, z);
mat.transformPoint(vec, vec);
tempPoints.push(vec.x, vec.y, vec.z);
};

mulPoint(min.x, min.y, min.z); mulPoint(min.x, max.y, min.z);
mulPoint(min.x, max.y, min.z); mulPoint(max.x, max.y, min.z);
mulPoint(max.x, max.y, min.z); mulPoint(max.x, min.y, min.z);
mulPoint(max.x, min.y, min.z); mulPoint(min.x, min.y, min.z);
mulPoint(min.x, min.y, max.z); mulPoint(min.x, max.y, max.z);
mulPoint(min.x, max.y, max.z); mulPoint(max.x, max.y, max.z);
mulPoint(max.x, max.y, max.z); mulPoint(max.x, min.y, max.z);
mulPoint(max.x, min.y, max.z); mulPoint(min.x, min.y, max.z);
mulPoint(min.x, min.y, min.z); mulPoint(min.x, min.y, max.z);
mulPoint(min.x, max.y, min.z); mulPoint(min.x, max.y, max.z);
mulPoint(max.x, max.y, min.z); mulPoint(max.x, max.y, max.z);
mulPoint(max.x, min.y, min.z); mulPoint(max.x, min.y, max.z);
} else {
tempPoints.push(
min.x, min.y, min.z, min.x, max.y, min.z,
min.x, max.y, min.z, max.x, max.y, min.z,
max.x, max.y, min.z, max.x, min.y, min.z,
max.x, min.y, min.z, min.x, min.y, min.z,
min.x, min.y, max.z, min.x, max.y, max.z,
min.x, max.y, max.z, max.x, max.y, max.z,
max.x, max.y, max.z, max.x, min.y, max.z,
max.x, min.y, max.z, min.x, min.y, max.z,
min.x, min.y, min.z, min.x, min.y, max.z,
min.x, max.y, min.z, min.x, max.y, max.z,
max.x, max.y, min.z, max.x, max.y, max.z,
max.x, min.y, min.z, max.x, min.y, max.z
);
}

const batch = this.getBatch(layer, depthTest);
batch.addLinesArrays(tempPoints, color);
Expand Down