@cyclonium/debug-draw 0.0.105 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +13 -9
- package/lib/legacy.d.ts +3 -3
- package/lib/legacy.js +6 -6
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -24,12 +24,12 @@ DebugDrawTarget = __decorate([
|
|
|
24
24
|
], DebugDrawTarget);
|
|
25
25
|
export { DebugDrawTarget };
|
|
26
26
|
export function tryGetDebugGeometryRenderer(camera) {
|
|
27
|
-
let renderCamera
|
|
27
|
+
let renderCamera;
|
|
28
28
|
if (camera) {
|
|
29
29
|
renderCamera = camera.camera;
|
|
30
30
|
}
|
|
31
31
|
else if (EDITOR_NOT_IN_PREVIEW) {
|
|
32
|
-
renderCamera =
|
|
32
|
+
renderCamera = getEditorCamera()?.camera;
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
35
|
renderCamera = find('World/Main Camera')?.getComponent(Camera)?.camera;
|
|
@@ -65,7 +65,7 @@ function getGeometryRendererFromCamera(camera) {
|
|
|
65
65
|
const cacheAABB = new geometry.AABB();
|
|
66
66
|
export class DebugDrawContext {
|
|
67
67
|
static fromEditorCamera() {
|
|
68
|
-
const camera =
|
|
68
|
+
const camera = getEditorCamera();
|
|
69
69
|
if (!camera) {
|
|
70
70
|
return undefined;
|
|
71
71
|
}
|
|
@@ -99,7 +99,7 @@ export class DebugDrawContext {
|
|
|
99
99
|
Vec3.scaleAndAdd(v2, v2, right, -hx);
|
|
100
100
|
const v3 = Vec3.scaleAndAdd(vec3Caches[iVec3Cache++], center, up, -hy);
|
|
101
101
|
Vec3.scaleAndAdd(v3, v3, right, -hx);
|
|
102
|
-
const v4 = Vec3.scaleAndAdd(vec3Caches[iVec3Cache
|
|
102
|
+
const v4 = Vec3.scaleAndAdd(vec3Caches[iVec3Cache], center, right, hx);
|
|
103
103
|
Vec3.scaleAndAdd(v4, v4, up, -hy);
|
|
104
104
|
if (transform) {
|
|
105
105
|
Vec3.transformMat4(v1, v1, transform);
|
|
@@ -174,12 +174,12 @@ export class DebugDrawContext {
|
|
|
174
174
|
Mat4.multiply(finalTransform, transform, finalTransform);
|
|
175
175
|
}
|
|
176
176
|
this._geometryRenderers.forEach((g) => {
|
|
177
|
-
g.addArc(Vec3.ZERO, radius, color, toDegrees(startAngle), toDegrees(endAngle), segments, depthTest,
|
|
177
|
+
g.addArc(Vec3.ZERO, radius, color, toDegrees(startAngle), toDegrees(endAngle), segments, depthTest, wireframe, finalTransform);
|
|
178
178
|
});
|
|
179
179
|
}
|
|
180
180
|
sector(opts) {
|
|
181
181
|
let iCacheMat4 = 0;
|
|
182
|
-
|
|
182
|
+
const iCacheQuat = 0;
|
|
183
183
|
let iCacheVec3 = 0;
|
|
184
184
|
const { center, radius, halfVector = Vec3.UNIT_Z, halfAngle = Math.PI / 2, normal = Vec3.UNIT_Y, color = Color.BLACK, wireframe = false, depthTest, segments = 64, transform, unlit = false, } = opts;
|
|
185
185
|
const finalTransform = Mat4.identity(mat4Caches[iCacheMat4++]);
|
|
@@ -191,9 +191,9 @@ export class DebugDrawContext {
|
|
|
191
191
|
const inputNormal = Vec3.normalize(vec3Caches[iCacheVec3++], normal);
|
|
192
192
|
const cross = Vec3.cross(vec3Caches[iCacheVec3++], inputHalfVector, inputNormal).normalize();
|
|
193
193
|
const newY = Vec3.cross(vec3Caches[iCacheVec3++], cross, inputHalfVector).normalize();
|
|
194
|
-
const newX = Vec3.transformQuat(vec3Caches[iCacheVec3++], inputHalfVector, Quat.fromAxisAngle(quatCaches[iCacheQuat
|
|
195
|
-
const newZ = Vec3.cross(vec3Caches[iCacheVec3
|
|
196
|
-
const newMat4 = mat4FromAxes(mat4Caches[iCacheMat4
|
|
194
|
+
const newX = Vec3.transformQuat(vec3Caches[iCacheVec3++], inputHalfVector, Quat.fromAxisAngle(quatCaches[iCacheQuat], newY, halfAngle));
|
|
195
|
+
const newZ = Vec3.cross(vec3Caches[iCacheVec3], newX, newY).normalize();
|
|
196
|
+
const newMat4 = mat4FromAxes(mat4Caches[iCacheMat4], newX, newY, newZ);
|
|
197
197
|
Mat4.multiply(finalTransform, newMat4, finalTransform);
|
|
198
198
|
}
|
|
199
199
|
// Translate
|
|
@@ -210,6 +210,10 @@ export class DebugDrawContext {
|
|
|
210
210
|
}
|
|
211
211
|
_geometryRenderers;
|
|
212
212
|
}
|
|
213
|
+
function getEditorCamera() {
|
|
214
|
+
const editorGlobal = globalThis;
|
|
215
|
+
return editorGlobal.cce?.Camera.camera;
|
|
216
|
+
}
|
|
213
217
|
function mat4FromAxes(mat4, xAxis, yAxis, zAxis) {
|
|
214
218
|
return Mat4.set(mat4, xAxis.x, xAxis.y, xAxis.z, 0, yAxis.x, yAxis.y, yAxis.z, 0, zAxis.x, zAxis.y, zAxis.z, 0, 0, 0, 0, 1);
|
|
215
219
|
}
|
package/lib/legacy.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Mat3 } from
|
|
2
|
-
import { Vec2 } from
|
|
3
|
-
import { Mat4, type GeometryRenderer, type Color, Vec3 } from
|
|
1
|
+
import { Mat3 } from '@cyclonium/core/math/mat3';
|
|
2
|
+
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
3
|
+
import { Mat4, type GeometryRenderer, type Color, Vec3 } from 'cc';
|
|
4
4
|
export declare const drawBox2D: (geometryRenderer: GeometryRenderer, center: Readonly<Vec2>, halfExtent: Readonly<Vec2> | number, color: Readonly<Color>, { wireframe, depthTest, z, transform, }?: {
|
|
5
5
|
wireframe?: boolean;
|
|
6
6
|
depthTest?: boolean;
|
package/lib/legacy.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Mat3 } from
|
|
2
|
-
import { decomposeSRTMat3 } from
|
|
3
|
-
import { Vec2 } from
|
|
4
|
-
import { Mat4, Quat, Vec3 } from
|
|
1
|
+
import { Mat3 } from '@cyclonium/core/math/mat3';
|
|
2
|
+
import { decomposeSRTMat3 } from '@cyclonium/core/math/transform-2d';
|
|
3
|
+
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
4
|
+
import { Mat4, Quat, Vec3 } from 'cc';
|
|
5
5
|
export const drawBox2D = (() => {
|
|
6
6
|
return (geometryRenderer, center, halfExtent, color, { wireframe = true, depthTest = true, z = 0, transform, } = {}) => {
|
|
7
7
|
const hx = typeof halfExtent === 'number' ? halfExtent : halfExtent.x;
|
|
@@ -22,7 +22,7 @@ export const drawBox2D = (() => {
|
|
|
22
22
|
export const drawCircleXY = (() => {
|
|
23
23
|
const transform = Mat4.fromQuat(new Mat4(), Quat.fromAxisAngle(new Quat(), Vec3.UNIT_X, Math.PI / 2));
|
|
24
24
|
return (geometryRenderer, center, radius, color, { wireframe = true, depthTest = true, segments = 32, } = {}) => {
|
|
25
|
-
geometryRenderer.addCircle(center, radius, color, segments, depthTest,
|
|
25
|
+
geometryRenderer.addCircle(center, radius, color, segments, depthTest, wireframe, transform);
|
|
26
26
|
};
|
|
27
27
|
})();
|
|
28
28
|
export const drawLineFromTo2D = (() => {
|
|
@@ -69,7 +69,7 @@ export const drawCircle2D = (() => {
|
|
|
69
69
|
const transform4 = Mat4.fromSRT(new Mat4(), Quat.fromAxisAngle(new Quat(), Vec3.UNIT_Z, srt.rotation), new Vec3(srt.translation.x, srt.translation.y, z), new Vec3(srt.scale.x, srt.scale.y, z));
|
|
70
70
|
Mat4.multiply(transformMatrix, transform4, transformMatrix);
|
|
71
71
|
}
|
|
72
|
-
geometryRenderer.addCircle(center3, radius, color, segments, depthTest,
|
|
72
|
+
geometryRenderer.addCircle(center3, radius, color, segments, depthTest, wireframe, transformMatrix);
|
|
73
73
|
};
|
|
74
74
|
})();
|
|
75
75
|
//# sourceMappingURL=legacy.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyclonium/debug-draw",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/shrinktofit/cyclonium",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@cyclonium/algorithm": "1.0.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@cyclonium/core": "
|
|
20
|
+
"@cyclonium/core": "1.0.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"typescript": "^6.0.2",
|