Skip to content

Commit

Permalink
Gizmo clipping plane fix (playcanvas#7045)
Browse files Browse the repository at this point in the history
* clamped z to w to prevent clipping

* fixed z clamping issue with cull flag

* Updated get selection to use camera position and screen to world with clip range

* Removed sign from gizmo shader
  • Loading branch information
kpal81xd committed Oct 17, 2024
1 parent 9829e16 commit ffc9147
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/extras/gizmo/gizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ class Gizmo extends EventHandler {
* @private
*/
_getSelection(x, y) {
const start = this._camera.screenToWorld(x, y, this._camera.nearClip);
const end = this._camera.screenToWorld(x, y, this._camera.farClip);
const start = this._camera.entity.getPosition();
const end = this._camera.screenToWorld(x, y, this._camera.farClip - this._camera.nearClip);
const dir = end.clone().sub(start).normalize();

const selection = [];
Expand Down
4 changes: 2 additions & 2 deletions src/extras/gizmo/shape/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,17 @@ const shaderDesc = {
attribute vec3 vertex_position;
attribute vec4 vertex_color;
varying vec4 vColor;
varying vec2 vZW;
uniform mat4 matrix_model;
uniform mat4 matrix_viewProjection;
void main(void) {
gl_Position = matrix_viewProjection * matrix_model * vec4(vertex_position, 1.0);
gl_Position.z = clamp(gl_Position.z, -abs(gl_Position.w), abs(gl_Position.w));
vColor = vertex_color;
}
`,
fragmentCode: /* glsl */`
precision highp float;
varying vec4 vColor;
varying vec2 vZW;
void main(void) {
gl_FragColor = vColor;
}
Expand Down Expand Up @@ -308,6 +307,7 @@ class Shape {
const meshInstances = [];
for (let i = 0; i < meshes.length; i++) {
const mi = new MeshInstance(meshes[i], material);
mi.cull = false;
meshInstances.push(mi);
this.meshInstances.push(mi);
}
Expand Down

0 comments on commit ffc9147

Please sign in to comment.