abstract-3d 3.1.1 → 4.0.0-beta.0
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/README.md +21 -1
- package/lib/renderers/dxf/dxf-encoding/dxf-build.d.ts.map +1 -1
- package/lib/renderers/dxf/dxf-encoding/dxf-build.js +1 -2
- package/lib/renderers/dxf/dxf-encoding/dxf-build.js.map +1 -1
- package/lib/renderers/ifc/ifc.test.d.ts +2 -0
- package/lib/renderers/ifc/ifc.test.d.ts.map +1 -0
- package/lib/renderers/ifc/ifc.test.js +380 -0
- package/lib/renderers/ifc/ifc.test.js.map +1 -0
- package/lib/renderers/index.d.ts +1 -0
- package/lib/renderers/index.d.ts.map +1 -1
- package/lib/renderers/index.js +1 -0
- package/lib/renderers/index.js.map +1 -1
- package/lib/renderers/react/index.d.ts +2 -5
- package/lib/renderers/react/index.d.ts.map +1 -1
- package/lib/renderers/react/index.js +1 -2
- package/lib/renderers/react/index.js.map +1 -1
- package/lib/renderers/react/react.d.ts +16 -42
- package/lib/renderers/react/react.d.ts.map +1 -1
- package/lib/renderers/react/react.js +49 -32
- package/lib/renderers/react/react.js.map +1 -1
- package/lib/renderers/three/appearance/appearance.d.ts +41 -0
- package/lib/renderers/three/appearance/appearance.d.ts.map +1 -0
- package/lib/renderers/three/appearance/appearance.js +89 -0
- package/lib/renderers/three/appearance/appearance.js.map +1 -0
- package/lib/renderers/three/appearance/appearance.test.d.ts +2 -0
- package/lib/renderers/three/appearance/appearance.test.d.ts.map +1 -0
- package/lib/renderers/three/appearance/appearance.test.js +97 -0
- package/lib/renderers/three/appearance/appearance.test.js.map +1 -0
- package/lib/renderers/three/appearance.d.ts +41 -0
- package/lib/renderers/three/appearance.d.ts.map +1 -0
- package/lib/renderers/three/appearance.js +100 -0
- package/lib/renderers/three/appearance.js.map +1 -0
- package/lib/renderers/three/build/build.d.ts +51 -0
- package/lib/renderers/three/build/build.d.ts.map +1 -0
- package/lib/renderers/three/build/build.js +174 -0
- package/lib/renderers/three/build/build.js.map +1 -0
- package/lib/renderers/three/build/build.test.d.ts +2 -0
- package/lib/renderers/three/build/build.test.d.ts.map +1 -0
- package/lib/renderers/three/build/build.test.js +120 -0
- package/lib/renderers/three/build/build.test.js.map +1 -0
- package/lib/renderers/three/build/materials.d.ts +12 -0
- package/lib/renderers/three/build/materials.d.ts.map +1 -0
- package/lib/renderers/three/build/materials.js +55 -0
- package/lib/renderers/three/build/materials.js.map +1 -0
- package/lib/renderers/three/build/parts.d.ts +65 -0
- package/lib/renderers/three/build/parts.d.ts.map +1 -0
- package/lib/renderers/three/build/parts.js +203 -0
- package/lib/renderers/three/build/parts.js.map +1 -0
- package/lib/renderers/three/build.d.ts +50 -0
- package/lib/renderers/three/build.d.ts.map +1 -0
- package/lib/renderers/three/build.js +210 -0
- package/lib/renderers/three/build.js.map +1 -0
- package/lib/renderers/three/camera/camera.d.ts +40 -0
- package/lib/renderers/three/camera/camera.d.ts.map +1 -0
- package/lib/renderers/three/camera/camera.js +51 -0
- package/lib/renderers/three/camera/camera.js.map +1 -0
- package/lib/renderers/three/camera/camera.test.d.ts +2 -0
- package/lib/renderers/three/camera/camera.test.d.ts.map +1 -0
- package/lib/renderers/three/camera/camera.test.js +46 -0
- package/lib/renderers/three/camera/camera.test.js.map +1 -0
- package/lib/renderers/three/camera/controls.d.ts +24 -0
- package/lib/renderers/three/camera/controls.d.ts.map +1 -0
- package/lib/renderers/three/camera/controls.js +39 -0
- package/lib/renderers/three/camera/controls.js.map +1 -0
- package/lib/renderers/three/camera/gizmo.d.ts +44 -0
- package/lib/renderers/three/camera/gizmo.d.ts.map +1 -0
- package/lib/renderers/three/camera/gizmo.js +42 -0
- package/lib/renderers/three/camera/gizmo.js.map +1 -0
- package/lib/renderers/three/camera.d.ts +63 -0
- package/lib/renderers/three/camera.d.ts.map +1 -0
- package/lib/renderers/three/camera.js +85 -0
- package/lib/renderers/three/camera.js.map +1 -0
- package/lib/renderers/three/compile/compile.d.ts +59 -0
- package/lib/renderers/three/compile/compile.d.ts.map +1 -0
- package/lib/renderers/three/compile/compile.js +88 -0
- package/lib/renderers/three/compile/compile.js.map +1 -0
- package/lib/renderers/three/compile/compile.test.d.ts +2 -0
- package/lib/renderers/three/compile/compile.test.d.ts.map +1 -0
- package/lib/renderers/three/compile/compile.test.js +93 -0
- package/lib/renderers/three/compile/compile.test.js.map +1 -0
- package/lib/renderers/three/compile.d.ts +58 -0
- package/lib/renderers/three/compile.d.ts.map +1 -0
- package/lib/renderers/three/compile.js +89 -0
- package/lib/renderers/three/compile.js.map +1 -0
- package/lib/renderers/three/controls.d.ts +27 -0
- package/lib/renderers/three/controls.d.ts.map +1 -0
- package/lib/renderers/three/controls.js +115 -0
- package/lib/renderers/three/controls.js.map +1 -0
- package/lib/renderers/three/geometry/geometry.d.ts +21 -0
- package/lib/renderers/three/geometry/geometry.d.ts.map +1 -0
- package/lib/renderers/three/geometry/geometry.js +132 -0
- package/lib/renderers/three/geometry/geometry.js.map +1 -0
- package/lib/renderers/three/geometry/geometry.test.d.ts +2 -0
- package/lib/renderers/three/geometry/geometry.test.d.ts.map +1 -0
- package/lib/renderers/three/geometry/geometry.test.js +80 -0
- package/lib/renderers/three/geometry/geometry.test.js.map +1 -0
- package/lib/renderers/three/geometry.d.ts +20 -0
- package/lib/renderers/three/geometry.d.ts.map +1 -0
- package/lib/renderers/three/geometry.js +164 -0
- package/lib/renderers/three/geometry.js.map +1 -0
- package/lib/renderers/three/gizmo.d.ts +49 -0
- package/lib/renderers/three/gizmo.d.ts.map +1 -0
- package/lib/renderers/three/gizmo.js +172 -0
- package/lib/renderers/three/gizmo.js.map +1 -0
- package/lib/renderers/three/index.d.ts +16 -0
- package/lib/renderers/three/index.d.ts.map +1 -0
- package/lib/renderers/three/index.js +6 -0
- package/lib/renderers/three/index.js.map +1 -0
- package/lib/renderers/three/input.d.ts +25 -0
- package/lib/renderers/three/input.d.ts.map +1 -0
- package/lib/renderers/three/input.js +71 -0
- package/lib/renderers/three/input.js.map +1 -0
- package/lib/renderers/three/lines.d.ts +16 -0
- package/lib/renderers/three/lines.d.ts.map +1 -0
- package/lib/renderers/three/lines.js +63 -0
- package/lib/renderers/three/lines.js.map +1 -0
- package/lib/renderers/three/materials.d.ts +15 -0
- package/lib/renderers/three/materials.d.ts.map +1 -0
- package/lib/renderers/three/materials.js +70 -0
- package/lib/renderers/three/materials.js.map +1 -0
- package/lib/renderers/three/options.d.ts +68 -0
- package/lib/renderers/three/options.d.ts.map +1 -0
- package/lib/renderers/three/options.js +64 -0
- package/lib/renderers/three/options.js.map +1 -0
- package/lib/renderers/three/overlays.d.ts +25 -0
- package/lib/renderers/three/overlays.d.ts.map +1 -0
- package/lib/renderers/three/overlays.js +57 -0
- package/lib/renderers/three/overlays.js.map +1 -0
- package/lib/renderers/three/quality/quality.d.ts +37 -0
- package/lib/renderers/three/quality/quality.d.ts.map +1 -0
- package/lib/renderers/three/quality/quality.js +64 -0
- package/lib/renderers/three/quality/quality.js.map +1 -0
- package/lib/renderers/three/quality/quality.test.d.ts +2 -0
- package/lib/renderers/three/quality/quality.test.d.ts.map +1 -0
- package/lib/renderers/three/quality/quality.test.js +23 -0
- package/lib/renderers/three/quality/quality.test.js.map +1 -0
- package/lib/renderers/three/quality.d.ts +24 -0
- package/lib/renderers/three/quality.d.ts.map +1 -0
- package/lib/renderers/three/quality.js +67 -0
- package/lib/renderers/three/quality.js.map +1 -0
- package/lib/renderers/three/text/text.d.ts +55 -0
- package/lib/renderers/three/text/text.d.ts.map +1 -0
- package/lib/renderers/three/text/text.js +90 -0
- package/lib/renderers/three/text/text.js.map +1 -0
- package/lib/renderers/three/text/text.test.d.ts +2 -0
- package/lib/renderers/three/text/text.test.d.ts.map +1 -0
- package/lib/renderers/three/text/text.test.js +70 -0
- package/lib/renderers/three/text/text.test.js.map +1 -0
- package/lib/renderers/three/text.d.ts +53 -0
- package/lib/renderers/three/text.d.ts.map +1 -0
- package/lib/renderers/three/text.js +151 -0
- package/lib/renderers/three/text.js.map +1 -0
- package/lib/renderers/three/viewer/options.d.ts +71 -0
- package/lib/renderers/three/viewer/options.d.ts.map +1 -0
- package/lib/renderers/three/viewer/options.js +31 -0
- package/lib/renderers/three/viewer/options.js.map +1 -0
- package/lib/renderers/three/viewer/options.test.d.ts +2 -0
- package/lib/renderers/three/viewer/options.test.d.ts.map +1 -0
- package/lib/renderers/three/viewer/options.test.js +38 -0
- package/lib/renderers/three/viewer/options.test.js.map +1 -0
- package/lib/renderers/three/viewer/overlays.d.ts +31 -0
- package/lib/renderers/three/viewer/overlays.d.ts.map +1 -0
- package/lib/renderers/three/viewer/overlays.js +43 -0
- package/lib/renderers/three/viewer/overlays.js.map +1 -0
- package/lib/renderers/three/viewer/viewer.d.ts +90 -0
- package/lib/renderers/three/viewer/viewer.d.ts.map +1 -0
- package/lib/renderers/three/viewer/viewer.js +432 -0
- package/lib/renderers/three/viewer/viewer.js.map +1 -0
- package/lib/renderers/three/viewer.d.ts +38 -0
- package/lib/renderers/three/viewer.d.ts.map +1 -0
- package/lib/renderers/three/viewer.js +435 -0
- package/lib/renderers/three/viewer.js.map +1 -0
- package/package.json +26 -9
- package/src/abstract-3d.ts +1 -1
- package/src/custom_typings/n8ao.d.ts +11 -0
- package/src/renderers/dxf/dxf-encoding/dxf-build.ts +1 -2
- package/src/renderers/index.ts +1 -0
- package/src/renderers/react/index.ts +2 -5
- package/src/renderers/react/react.tsx +96 -181
- package/src/renderers/three/appearance/appearance.test.ts +116 -0
- package/src/renderers/three/appearance/appearance.ts +132 -0
- package/src/renderers/three/build/build.test.ts +141 -0
- package/src/renderers/three/build/build.ts +270 -0
- package/src/renderers/three/build/materials.ts +85 -0
- package/src/renderers/three/build/parts.ts +277 -0
- package/src/renderers/three/camera/camera.test.ts +53 -0
- package/src/renderers/three/camera/camera.ts +82 -0
- package/src/renderers/three/camera/controls.ts +65 -0
- package/src/renderers/three/camera/gizmo.ts +93 -0
- package/src/renderers/three/compile/compile.test.ts +113 -0
- package/src/renderers/three/compile/compile.ts +151 -0
- package/src/renderers/three/geometry/geometry.test.ts +95 -0
- package/src/renderers/three/geometry/geometry.ts +179 -0
- package/src/renderers/three/index.ts +15 -0
- package/src/renderers/three/quality/quality.test.ts +30 -0
- package/src/renderers/three/quality/quality.ts +95 -0
- package/src/renderers/three/text/text.test.ts +79 -0
- package/src/renderers/three/text/text.ts +128 -0
- package/src/renderers/three/viewer/options.ts +98 -0
- package/src/renderers/three/viewer/overlays.ts +71 -0
- package/src/renderers/three/viewer/viewer.ts +540 -0
- package/lib/renderers/dxf/color.d.ts +0 -7
- package/lib/renderers/dxf/color.d.ts.map +0 -1
- package/lib/renderers/dxf/color.js +0 -311
- package/lib/renderers/dxf/color.js.map +0 -1
- package/lib/renderers/dxf/dxf-encoding.d.ts +0 -17
- package/lib/renderers/dxf/dxf-encoding.d.ts.map +0 -1
- package/lib/renderers/dxf/dxf-encoding.js +0 -18467
- package/lib/renderers/dxf/dxf-encoding.js.map +0 -1
- package/lib/renderers/react/react-hotspot.d.ts +0 -27
- package/lib/renderers/react/react-hotspot.d.ts.map +0 -1
- package/lib/renderers/react/react-hotspot.js +0 -37
- package/lib/renderers/react/react-hotspot.js.map +0 -1
- package/lib/renderers/shared.d.ts +0 -30
- package/lib/renderers/shared.d.ts.map +0 -1
- package/lib/renderers/shared.js +0 -164
- package/lib/renderers/shared.js.map +0 -1
- package/src/custom_typings/react-three-fiber.d.ts +0 -9
- package/src/custom_typings/react-three-postprocessing.d.ts +0 -1
- package/src/renderers/react/react-camera.tsx +0 -391
- package/src/renderers/react/react-dimension.tsx +0 -122
- package/src/renderers/react/react-group.test.ts +0 -56
- package/src/renderers/react/react-group.tsx +0 -202
- package/src/renderers/react/react-image-material.tsx +0 -139
- package/src/renderers/react/react-material.tsx +0 -91
- package/src/renderers/react/react-mesh.tsx +0 -512
- package/src/renderers/react/react-relation.tsx +0 -86
- package/src/renderers/react/react-scene.tsx +0 -111
- package/src/renderers/react/react-types.ts +0 -9
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { BatchedMesh, type BufferGeometry, InstancedBufferAttribute, InstancedMesh, type InterleavedBuffer, type Intersection, type Material, Matrix4, Mesh, type MeshBasicMaterial, Vector3, type Vector4 } from "three";
|
|
2
|
+
import { LineSegments2 } from "three/addons/lines/LineSegments2.js";
|
|
3
|
+
import type { Vec3 } from "../../../abstract-3d.js";
|
|
4
|
+
import type { GlyphAtlas } from "../text/text.js";
|
|
5
|
+
/** The drawn objects: solids of a material class in one batch, all text in one instanced mesh, lines per thickness, images as meshes; each item a slot */
|
|
6
|
+
export type Segment = {
|
|
7
|
+
readonly start: Vec3;
|
|
8
|
+
readonly end: Vec3;
|
|
9
|
+
/** The front facing direction of a culled line, hidden while it faces away from the camera */
|
|
10
|
+
readonly normal?: Vec3;
|
|
11
|
+
};
|
|
12
|
+
export type TextEntry = {
|
|
13
|
+
readonly text: string;
|
|
14
|
+
readonly fontSize: number;
|
|
15
|
+
readonly local: Matrix4;
|
|
16
|
+
};
|
|
17
|
+
export type Part = {
|
|
18
|
+
readonly kind: "solid";
|
|
19
|
+
readonly object: BatchedMesh;
|
|
20
|
+
readonly locals: ReadonlyArray<Matrix4>;
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: "text";
|
|
23
|
+
readonly object: InstancedMesh;
|
|
24
|
+
readonly locals: ReadonlyArray<Matrix4>;
|
|
25
|
+
readonly glyphs: ReadonlyArray<Matrix4>;
|
|
26
|
+
/** The first glyph of each slot, and one past the last */
|
|
27
|
+
readonly firsts: ReadonlyArray<number>;
|
|
28
|
+
readonly slotOfGlyph: Int32Array;
|
|
29
|
+
readonly colors: InstancedBufferAttribute;
|
|
30
|
+
} | {
|
|
31
|
+
readonly kind: "line";
|
|
32
|
+
readonly object: LineSegments2;
|
|
33
|
+
readonly segments: ReadonlyArray<Segment>;
|
|
34
|
+
/** World start, end and normal of each segment, while the drawn positions collapse hidden ones */
|
|
35
|
+
readonly world: Float32Array;
|
|
36
|
+
readonly visible: Uint8Array;
|
|
37
|
+
readonly positions: InterleavedBuffer;
|
|
38
|
+
readonly colors: InterleavedBuffer;
|
|
39
|
+
} | {
|
|
40
|
+
readonly kind: "image";
|
|
41
|
+
readonly object: Mesh<BufferGeometry, MeshBasicMaterial>;
|
|
42
|
+
readonly local: Matrix4;
|
|
43
|
+
};
|
|
44
|
+
/** Per-instance color for hover and selection, as three.js's BatchedMesh examples color instances */
|
|
45
|
+
export declare function createSolidPart(entries: ReadonlyArray<{
|
|
46
|
+
readonly geometry: BufferGeometry;
|
|
47
|
+
readonly local: Matrix4;
|
|
48
|
+
}>, material: Material): Part;
|
|
49
|
+
export declare function createTextPart(entries: ReadonlyArray<TextEntry>, atlas: GlyphAtlas): Part;
|
|
50
|
+
export declare function createLinePart(segments: ReadonlyArray<Segment>, thickness: number): Part;
|
|
51
|
+
/** Hidden until its texture is set */
|
|
52
|
+
export declare function createImagePart(geometry: BufferGeometry, local: Matrix4, material: MeshBasicMaterial): Extract<Part, {
|
|
53
|
+
readonly kind: "image";
|
|
54
|
+
}>;
|
|
55
|
+
/** Places the slot's item by its world matrix */
|
|
56
|
+
export declare function placeSlot(part: Part, slot: number, matrix: Matrix4): void;
|
|
57
|
+
export declare function paintSlot(part: Part, slot: number, rgba: Vector4): void;
|
|
58
|
+
/** Uploads what placing and painting changed, and the bounds for culling and picking when slots moved */
|
|
59
|
+
export declare function flushPart(part: Part, moved: boolean): void;
|
|
60
|
+
/** The slot of a hit on the part's object; lines aren't picked */
|
|
61
|
+
export declare function getHitSlot(part: Part, hit: Intersection): number | undefined;
|
|
62
|
+
/** Hides the culled lines facing away from a camera at `cameraPosition`; the r3f renderer's culled line shader's test, on the CPU per camera move */
|
|
63
|
+
export declare function cullLines(part: Part, cameraPosition: Vector3): void;
|
|
64
|
+
export declare function disposePart(part: Part): void;
|
|
65
|
+
//# sourceMappingURL=parts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parts.d.ts","sourceR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AG,OAAO,CAAC,IAAI,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAIhJ;AAED,iDAAiD;AACjD,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAwBzE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAiBvE;AAED,yGAAyG;AACzG,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAmB1D;AAED,kEAAkE;AAClE,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAW5E;AAED,qJAAqJ;AACrJ,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,GAAG,IAAI,CAiBnE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAQ5C"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { BatchedMesh, FrontSide, InstancedBufferAttribute, InstancedMesh, Matrix4, Mesh, PlaneGeometry, ShaderMaterial, Vector3, } from "three";
|
|
2
|
+
import { LineMaterial } from "three/addons/lines/LineMaterial.js";
|
|
3
|
+
import { LineSegments2 } from "three/addons/lines/LineSegments2.js";
|
|
4
|
+
import { LineSegmentsGeometry } from "three/addons/lines/LineSegmentsGeometry.js";
|
|
5
|
+
import { layoutText, SDF_EDGE } from "../text/text.js";
|
|
6
|
+
/** Per-instance color for hover and selection, as three.js's BatchedMesh examples color instances */
|
|
7
|
+
export function createSolidPart(entries, material) {
|
|
8
|
+
const geometries = [...new Set(entries.map((e) => e.geometry))];
|
|
9
|
+
const vertexCount = geometries.reduce((sum, g) => sum + g.getAttribute("position").count, 0);
|
|
10
|
+
const batch = new BatchedMesh(entries.length, vertexCount, geometries.reduce((sum, g) => sum + g.index.count, 0), material);
|
|
11
|
+
const ids = new Map(geometries.map((g) => [g, batch.addGeometry(g)]));
|
|
12
|
+
entries.forEach((e) => batch.addInstance(ids.get(e.geometry)));
|
|
13
|
+
return { kind: "solid", object: batch, locals: entries.map((e) => e.local) };
|
|
14
|
+
}
|
|
15
|
+
export function createTextPart(entries, atlas) {
|
|
16
|
+
const layouts = entries.map((e) => layoutText(atlas, e.text, e.fontSize));
|
|
17
|
+
const quads = layouts.flat();
|
|
18
|
+
const geometry = new PlaneGeometry();
|
|
19
|
+
geometry.setAttribute("glyphRect", new InstancedBufferAttribute(Float32Array.from(quads.flatMap((q) => q.glyph.rect)), 4));
|
|
20
|
+
const colors = new InstancedBufferAttribute(new Float32Array(quads.length * 4), 4);
|
|
21
|
+
geometry.setAttribute("glyphColor", colors);
|
|
22
|
+
// Glyphs colored per instance, one draw call as troika's BatchedText; edges antialiased by the distance field's fwidth, as troika does
|
|
23
|
+
const material = new ShaderMaterial({
|
|
24
|
+
side: FrontSide,
|
|
25
|
+
transparent: true,
|
|
26
|
+
depthWrite: false,
|
|
27
|
+
uniforms: { atlas: { value: atlas.texture } },
|
|
28
|
+
defines: { SDF_EDGE },
|
|
29
|
+
vertexShader: textVertexShader,
|
|
30
|
+
fragmentShader: textFragmentShader,
|
|
31
|
+
});
|
|
32
|
+
const mesh = new InstancedMesh(geometry, material, quads.length);
|
|
33
|
+
// Drawn after the opaque batches, and never culled as a whole, as its glyphs move with their items
|
|
34
|
+
Object.assign(mesh, { renderOrder: 1, frustumCulled: false });
|
|
35
|
+
return {
|
|
36
|
+
kind: "text",
|
|
37
|
+
object: mesh,
|
|
38
|
+
locals: entries.map((e) => e.local),
|
|
39
|
+
glyphs: quads.map((q) => new Matrix4().makeTranslation(q.x, q.y, 0).scale(new Vector3(q.width, q.height, 1))),
|
|
40
|
+
firsts: layouts.reduce((acc, l, i) => [...acc, acc[i] + l.length], [0]),
|
|
41
|
+
slotOfGlyph: Int32Array.from(layouts.flatMap((l, slot) => l.map(() => slot))),
|
|
42
|
+
colors,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function createLinePart(segments, thickness) {
|
|
46
|
+
const geometry = new LineSegmentsGeometry().setPositions(new Float32Array(segments.length * 6)).setColors(new Float32Array(segments.length * 6));
|
|
47
|
+
const line = new LineSegments2(geometry, new LineMaterial({ linewidth: thickness, vertexColors: true }));
|
|
48
|
+
// Positions change after the geometry's bounds were computed
|
|
49
|
+
line.frustumCulled = false;
|
|
50
|
+
return {
|
|
51
|
+
kind: "line",
|
|
52
|
+
object: line,
|
|
53
|
+
segments,
|
|
54
|
+
world: new Float32Array(segments.length * 9),
|
|
55
|
+
visible: new Uint8Array(segments.length).fill(1),
|
|
56
|
+
positions: geometry.getAttribute("instanceStart").data,
|
|
57
|
+
colors: geometry.getAttribute("instanceColorStart").data,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Hidden until its texture is set */
|
|
61
|
+
export function createImagePart(geometry, local, material) {
|
|
62
|
+
const mesh = new Mesh(geometry, material);
|
|
63
|
+
Object.assign(mesh, { matrixAutoUpdate: false, visible: false });
|
|
64
|
+
return { kind: "image", object: mesh, local };
|
|
65
|
+
}
|
|
66
|
+
/** Places the slot's item by its world matrix */
|
|
67
|
+
export function placeSlot(part, slot, matrix) {
|
|
68
|
+
switch (part.kind) {
|
|
69
|
+
case "solid":
|
|
70
|
+
part.object.setMatrixAt(slot, scratch.multiplyMatrices(matrix, part.locals[slot]));
|
|
71
|
+
break;
|
|
72
|
+
case "text": {
|
|
73
|
+
const text = scratch.multiplyMatrices(matrix, part.locals[slot]);
|
|
74
|
+
for (let i = part.firsts[slot]; i < part.firsts[slot + 1]; i++) {
|
|
75
|
+
part.object.setMatrixAt(i, glyph.multiplyMatrices(text, part.glyphs[i]));
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case "line": {
|
|
80
|
+
const { start, end, normal } = part.segments[slot];
|
|
81
|
+
part.world.set(vector.set(start.x, start.y, start.z).applyMatrix4(matrix).toArray(), slot * 9);
|
|
82
|
+
part.world.set(vector.set(end.x, end.y, end.z).applyMatrix4(matrix).toArray(), slot * 9 + 3);
|
|
83
|
+
part.world.set(normal ? vector.set(normal.x, normal.y, normal.z).transformDirection(matrix).toArray() : [0, 0, 0], slot * 9 + 6);
|
|
84
|
+
writeSegment(part, slot);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
part.object.matrix.multiplyMatrices(matrix, part.local);
|
|
89
|
+
part.object.matrixWorldNeedsUpdate = true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export function paintSlot(part, slot, rgba) {
|
|
93
|
+
switch (part.kind) {
|
|
94
|
+
case "solid":
|
|
95
|
+
part.object.setColorAt(slot, rgba);
|
|
96
|
+
break;
|
|
97
|
+
case "text":
|
|
98
|
+
for (let i = part.firsts[slot]; i < part.firsts[slot + 1]; i++) {
|
|
99
|
+
part.colors.setXYZW(i, rgba.x, rgba.y, rgba.z, rgba.w);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
case "line":
|
|
103
|
+
part.colors.array.set([rgba.x, rgba.y, rgba.z, rgba.x, rgba.y, rgba.z], slot * 6);
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
part.object.material.color.setRGB(rgba.x, rgba.y, rgba.z);
|
|
107
|
+
part.object.material.opacity = rgba.w;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** Uploads what placing and painting changed, and the bounds for culling and picking when slots moved */
|
|
111
|
+
export function flushPart(part, moved) {
|
|
112
|
+
switch (part.kind) {
|
|
113
|
+
case "solid":
|
|
114
|
+
if (moved) {
|
|
115
|
+
part.object.computeBoundingBox();
|
|
116
|
+
part.object.computeBoundingSphere();
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
case "text":
|
|
120
|
+
part.object.instanceMatrix.needsUpdate = true;
|
|
121
|
+
part.colors.needsUpdate = true;
|
|
122
|
+
part.object.boundingSphere = null;
|
|
123
|
+
break;
|
|
124
|
+
case "line":
|
|
125
|
+
part.positions.needsUpdate = true;
|
|
126
|
+
part.colors.needsUpdate = true;
|
|
127
|
+
break;
|
|
128
|
+
default:
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** The slot of a hit on the part's object; lines aren't picked */
|
|
132
|
+
export function getHitSlot(part, hit) {
|
|
133
|
+
switch (part.kind) {
|
|
134
|
+
case "solid":
|
|
135
|
+
return hit.batchId;
|
|
136
|
+
case "text":
|
|
137
|
+
return hit.instanceId === undefined ? undefined : part.slotOfGlyph[hit.instanceId];
|
|
138
|
+
case "line":
|
|
139
|
+
return undefined;
|
|
140
|
+
default:
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** Hides the culled lines facing away from a camera at `cameraPosition`; the r3f renderer's culled line shader's test, on the CPU per camera move */
|
|
145
|
+
export function cullLines(part, cameraPosition) {
|
|
146
|
+
if (part.kind !== "line") {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
part.segments.forEach((segment, slot) => {
|
|
150
|
+
const w = slot * 9;
|
|
151
|
+
const mid = vector
|
|
152
|
+
.fromArray(part.world, w)
|
|
153
|
+
.add(normal.fromArray(part.world, w + 3))
|
|
154
|
+
.multiplyScalar(0.5);
|
|
155
|
+
const facing = !segment.normal || normal.fromArray(part.world, w + 6).dot(mid.subVectors(cameraPosition, mid)) > 0 ? 1 : 0;
|
|
156
|
+
if (facing !== part.visible[slot]) {
|
|
157
|
+
part.visible[slot] = facing;
|
|
158
|
+
writeSegment(part, slot);
|
|
159
|
+
part.positions.needsUpdate = true;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
export function disposePart(part) {
|
|
164
|
+
if (part.kind === "solid") {
|
|
165
|
+
part.object.dispose();
|
|
166
|
+
}
|
|
167
|
+
else if (part.kind !== "image") {
|
|
168
|
+
part.object.geometry.dispose();
|
|
169
|
+
}
|
|
170
|
+
const materials = part.object.material;
|
|
171
|
+
(Array.isArray(materials) ? materials : [materials]).forEach((m) => m.dispose());
|
|
172
|
+
}
|
|
173
|
+
/** A hidden segment collapses to its start */
|
|
174
|
+
function writeSegment(part, slot) {
|
|
175
|
+
const w = slot * 9;
|
|
176
|
+
part.positions.array.set(part.visible[slot] ? part.world.subarray(w, w + 6) : [...part.world.subarray(w, w + 3), ...part.world.subarray(w, w + 3)], slot * 6);
|
|
177
|
+
}
|
|
178
|
+
const textVertexShader = /* glsl */ `
|
|
179
|
+
attribute vec4 glyphRect;
|
|
180
|
+
attribute vec4 glyphColor;
|
|
181
|
+
varying vec2 vUv;
|
|
182
|
+
varying vec4 vColor;
|
|
183
|
+
void main() {
|
|
184
|
+
vUv = glyphRect.xy + uv * glyphRect.zw;
|
|
185
|
+
vColor = glyphColor;
|
|
186
|
+
gl_Position = projectionMatrix * modelViewMatrix * instanceMatrix * vec4(position, 1.0);
|
|
187
|
+
}`;
|
|
188
|
+
const textFragmentShader = /* glsl */ `
|
|
189
|
+
uniform sampler2D atlas;
|
|
190
|
+
varying vec2 vUv;
|
|
191
|
+
varying vec4 vColor;
|
|
192
|
+
void main() {
|
|
193
|
+
float distance = texture2D(atlas, vUv).r;
|
|
194
|
+
float edge = fwidth(distance) * 0.7;
|
|
195
|
+
gl_FragColor = vec4(vColor.rgb, vColor.a * smoothstep(SDF_EDGE - edge, SDF_EDGE + edge, distance));
|
|
196
|
+
#include <tonemapping_fragment>
|
|
197
|
+
#include <colorspace_fragment>
|
|
198
|
+
}`;
|
|
199
|
+
const scratch = new Matrix4();
|
|
200
|
+
const glyph = new Matrix4();
|
|
201
|
+
const vector = new Vector3();
|
|
202
|
+
const normal = new Vector3();
|
|
203
|
+
//# sourceMappingURL=parts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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C;AAED,MAAM,gBAAgB,GAAG,UAAU,CAAC;;;;;;;;;EASlC,CAAC;AAEH,MAAM,kBAAkB,GAAG,UAAU,CAAC;;;;;;;;;;EAUpC,CAAC;AAEH,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAC9B,MAAM,KAAK,GAAG,IAAI,OAAO,EAAE,CAAC;AAC5B,MAAM,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;AAC7B,MAAM,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Group, type Intersection, Matrix4, type Object3D, type Vector3, Vector4 } from "three";
|
|
2
|
+
import type { PaintState, StructureState } from "./appearance.js";
|
|
3
|
+
import type { CompiledScene } from "./compile.js";
|
|
4
|
+
import type { GeometryCache } from "./geometry.js";
|
|
5
|
+
import type { TextureLoad } from "./materials.js";
|
|
6
|
+
import type { GlyphAtlas } from "./text.js";
|
|
7
|
+
/** Compiled items → three.js objects: a batch per material class, one text mesh and a line mesh per thickness, images as meshes */
|
|
8
|
+
/** Drawn objects of items, each item a slot */
|
|
9
|
+
export type Part = {
|
|
10
|
+
readonly object: Object3D;
|
|
11
|
+
/** Places the slot's item by its world matrix */
|
|
12
|
+
readonly place: (slot: number, matrix: Matrix4) => void;
|
|
13
|
+
readonly paint: (slot: number, color: Vector4) => void;
|
|
14
|
+
/** Uploads what place and paint changed */
|
|
15
|
+
readonly flush: () => void;
|
|
16
|
+
/** The slot of a hit on the object, for parts that can be picked */
|
|
17
|
+
readonly pickSlot?: (hit: Intersection) => number | undefined;
|
|
18
|
+
readonly dispose: () => void;
|
|
19
|
+
};
|
|
20
|
+
export type BuildOptions = {
|
|
21
|
+
readonly structure: StructureState;
|
|
22
|
+
readonly activeRelations?: ReadonlyArray<string>;
|
|
23
|
+
readonly geometries: GeometryCache;
|
|
24
|
+
readonly glyphs: GlyphAtlas;
|
|
25
|
+
/** Loads images' textures; without it images aren't shown */
|
|
26
|
+
readonly loadTexture?: TextureLoad;
|
|
27
|
+
readonly materialStateImages?: Record<string, string>;
|
|
28
|
+
readonly useAlphaTest?: boolean;
|
|
29
|
+
readonly onTextureLoaded?: () => void;
|
|
30
|
+
};
|
|
31
|
+
export type BuiltScene = {
|
|
32
|
+
readonly root: Group;
|
|
33
|
+
/** Holds the dimensions, shown or hidden by its `visible` */
|
|
34
|
+
readonly dimensions: Group;
|
|
35
|
+
/** The shown objects that can be picked */
|
|
36
|
+
readonly getPickables: () => ReadonlyArray<Object3D>;
|
|
37
|
+
/** The index of the compiled item hit */
|
|
38
|
+
readonly getPickedItem: (hit: Intersection) => number | undefined;
|
|
39
|
+
/** Repaints the targets whose highlight changed */
|
|
40
|
+
readonly paint: (state: PaintState) => void;
|
|
41
|
+
readonly animated: boolean;
|
|
42
|
+
/** Moves the animated items to `seconds` into their animations */
|
|
43
|
+
readonly animate: (seconds: number) => void;
|
|
44
|
+
/** Hides the culled lines facing away from a camera at `cameraPosition` */
|
|
45
|
+
readonly cull: (cameraPosition: Vector3) => void;
|
|
46
|
+
readonly drawCalls: number;
|
|
47
|
+
readonly dispose: () => void;
|
|
48
|
+
};
|
|
49
|
+
export declare function buildScene(compiled: CompiledScene, options: BuildOptions): BuiltScene;
|
|
50
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/renderers/three/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,EACL,KAAK,YAAY,EAEjB,OAAO,EAGP,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,OAAO,EACR,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAElE,OAAO,KAAK,EAAE,aAAa,EAAQ,MAAM,cAAc,CAAC;AAExD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGnD,OAAO,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;IAC7D,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC;IAC3B,2CAA2C;IAC3C,QAAQ,CAAC,YAAY,EAAE,MAAM,aAAa,CAAC,QAAQ,CAAC,CAAC;IACrD,yCAAyC;IACzC,QAAQ,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,MAAM,GAAG,SAAS,CAAC;IAClE,mDAAmD;IACnD,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IAC5C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,kEAAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,CAAC,cAAc,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAC;AAEF,wBAAgB,UAAU,CAAC,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,GAAG,UAAU,CA+JrF"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { BatchedMesh, Group, Matrix4, Mesh, Vector4, } from "three";
|
|
2
|
+
import { vec3Zero } from "../../abstract-3d.js";
|
|
3
|
+
import { getHighlight, getItemColor, getMaterialClass, getMaterialState, materialClassKey } from "./appearance.js";
|
|
4
|
+
import { itemWorldMatrix, transform } from "./compile.js";
|
|
5
|
+
import { getSolidShape } from "./geometry.js";
|
|
6
|
+
import { createLinePart } from "./lines.js";
|
|
7
|
+
import { createClassMaterial, createImageMaterial, getImageUrl } from "./materials.js";
|
|
8
|
+
import { createTextPart } from "./text.js";
|
|
9
|
+
export function buildScene(compiled, options) {
|
|
10
|
+
const { items, targets } = compiled;
|
|
11
|
+
const root = new Group();
|
|
12
|
+
const dimensions = new Group();
|
|
13
|
+
root.add(dimensions);
|
|
14
|
+
const disposed = { current: false };
|
|
15
|
+
const active = new Set(options.activeRelations);
|
|
16
|
+
const included = items.flatMap((item, i) => {
|
|
17
|
+
const target = targets[item.target];
|
|
18
|
+
return target.kind !== "relation" || active.has(target.relation.id) ? [i] : [];
|
|
19
|
+
});
|
|
20
|
+
// Items grouped by the part that draws them, in the order they're first met
|
|
21
|
+
const groups = new Map();
|
|
22
|
+
included.forEach((i) => {
|
|
23
|
+
const key = getPartKey(items[i], i, options.structure, compiled);
|
|
24
|
+
groups.set(key, [...(groups.get(key) ?? []), i]);
|
|
25
|
+
});
|
|
26
|
+
const usedShapes = new Set();
|
|
27
|
+
const partOfItem = new Int32Array(items.length).fill(-1);
|
|
28
|
+
const slotOfItem = new Int32Array(items.length).fill(-1);
|
|
29
|
+
const itemsOfPart = [];
|
|
30
|
+
const lineParts = [];
|
|
31
|
+
const parts = Array.from(groups.values(), (indices, p) => {
|
|
32
|
+
indices.forEach((i, slot) => {
|
|
33
|
+
partOfItem[i] = p;
|
|
34
|
+
slotOfItem[i] = slot;
|
|
35
|
+
});
|
|
36
|
+
itemsOfPart.push(indices);
|
|
37
|
+
const part = createPart(indices.map((i) => items[i]));
|
|
38
|
+
(items[indices[0]].style === "dimension" ? dimensions : root).add(part.object);
|
|
39
|
+
return part;
|
|
40
|
+
});
|
|
41
|
+
function createPart(partItems) {
|
|
42
|
+
const first = partItems[0];
|
|
43
|
+
switch (first.role) {
|
|
44
|
+
case "text":
|
|
45
|
+
return createTextPart(partItems.map(toTextEntry), options.glyphs);
|
|
46
|
+
case "line": {
|
|
47
|
+
const part = createLinePart(partItems.map(toSegment), getThickness(first));
|
|
48
|
+
lineParts.push(part);
|
|
49
|
+
return part;
|
|
50
|
+
}
|
|
51
|
+
case "image":
|
|
52
|
+
return createImagePart(first);
|
|
53
|
+
default: {
|
|
54
|
+
const shapes = partItems.map((item) => getSolidShape(item.mesh.geometry));
|
|
55
|
+
shapes.forEach((shape) => usedShapes.add(shape.key));
|
|
56
|
+
const material = createClassMaterial(getMaterialClass(first, targets[first.target], options.structure));
|
|
57
|
+
return createSolidPart(shapes.map((shape) => ({ geometry: options.geometries.get(shape), local: shape.local })), material);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function createImagePart(item) {
|
|
62
|
+
const g = item.mesh.geometry;
|
|
63
|
+
const shape = getSolidShape(g.type === "Image" ? { type: "Plane", pos: g.pos, rot: g.rot, size: g.size } : g);
|
|
64
|
+
usedShapes.add(shape.key);
|
|
65
|
+
const material = createImageMaterial(item.mesh.material.backfaceCulling, options.useAlphaTest ?? true);
|
|
66
|
+
const mesh = new Mesh(options.geometries.get(shape), material);
|
|
67
|
+
mesh.matrixAutoUpdate = false;
|
|
68
|
+
mesh.visible = false;
|
|
69
|
+
if (g.type === "Image" && options.loadTexture) {
|
|
70
|
+
const url = getImageUrl(g.image, getMaterialState(targets[item.target], options.structure), options.materialStateImages);
|
|
71
|
+
void options.loadTexture(url).then((texture) => {
|
|
72
|
+
if (texture && !disposed.current) {
|
|
73
|
+
material.map = texture;
|
|
74
|
+
material.needsUpdate = true;
|
|
75
|
+
mesh.visible = true;
|
|
76
|
+
options.onTextureLoaded?.();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
object: mesh,
|
|
82
|
+
place: (_, matrix) => {
|
|
83
|
+
mesh.matrix.multiplyMatrices(matrix, shape.local);
|
|
84
|
+
mesh.matrixWorldNeedsUpdate = true;
|
|
85
|
+
},
|
|
86
|
+
paint: (_, color) => paintImage(material, color),
|
|
87
|
+
flush: () => undefined,
|
|
88
|
+
pickSlot: () => 0,
|
|
89
|
+
dispose: () => material.dispose(),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
options.geometries.keepOnly(usedShapes);
|
|
93
|
+
const itemsOfTarget = targets.map(() => []);
|
|
94
|
+
included.forEach((i) => itemsOfTarget[items[i].target].push(i));
|
|
95
|
+
const highlights = new Int8Array(targets.length).fill(-1);
|
|
96
|
+
const color = new Vector4();
|
|
97
|
+
const world = new Matrix4();
|
|
98
|
+
const flush = (partIndices) => {
|
|
99
|
+
for (const p of partIndices) {
|
|
100
|
+
parts[p].flush();
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const paint = (state) => {
|
|
104
|
+
const touched = new Set();
|
|
105
|
+
targets.forEach((target, t) => {
|
|
106
|
+
const highlight = getHighlight(target, t, state);
|
|
107
|
+
if (highlight === highlights[t]) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
highlights[t] = highlight;
|
|
111
|
+
itemsOfTarget[t].forEach((i) => {
|
|
112
|
+
const item = items[i];
|
|
113
|
+
parts[partOfItem[i]].paint(slotOfItem[i], getItemColor(item, target, highlight, options.structure, color));
|
|
114
|
+
touched.add(partOfItem[i]);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
flush(touched);
|
|
118
|
+
};
|
|
119
|
+
const animatedItems = included.filter((i) => items[i].animation !== undefined);
|
|
120
|
+
const animate = (seconds) => {
|
|
121
|
+
animatedItems.forEach((i) => parts[partOfItem[i]].place(slotOfItem[i], itemWorldMatrix(compiled, items[i], seconds, world)));
|
|
122
|
+
flush(new Set(animatedItems.map((i) => partOfItem[i])));
|
|
123
|
+
};
|
|
124
|
+
included.forEach((i) => parts[partOfItem[i]].place(slotOfItem[i], itemWorldMatrix(compiled, items[i], 0, world)));
|
|
125
|
+
paint({ ...options.structure, dimensionsClickable: false });
|
|
126
|
+
flush(parts.keys());
|
|
127
|
+
const partOfObject = new Map(parts.map((part, p) => [part.object, p]));
|
|
128
|
+
const isShown = (object) => object.visible && (object.parent === null || isShown(object.parent));
|
|
129
|
+
return {
|
|
130
|
+
root,
|
|
131
|
+
dimensions,
|
|
132
|
+
getPickables: () => parts.filter((part) => part.pickSlot && isShown(part.object)).map((part) => part.object),
|
|
133
|
+
getPickedItem: (hit) => {
|
|
134
|
+
const p = partOfObject.get(hit.object);
|
|
135
|
+
const slot = p === undefined ? undefined : parts[p].pickSlot?.(hit);
|
|
136
|
+
return slot === undefined ? undefined : itemsOfPart[p][slot];
|
|
137
|
+
},
|
|
138
|
+
paint,
|
|
139
|
+
animated: animatedItems.length > 0,
|
|
140
|
+
animate,
|
|
141
|
+
cull: (cameraPosition) => lineParts.forEach((part) => {
|
|
142
|
+
part.cull(cameraPosition);
|
|
143
|
+
}),
|
|
144
|
+
drawCalls: parts.length,
|
|
145
|
+
dispose: () => {
|
|
146
|
+
disposed.current = true;
|
|
147
|
+
parts.forEach((part) => part.dispose());
|
|
148
|
+
root.clear();
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/** Items of the same part key are drawn by one part */
|
|
153
|
+
function getPartKey(item, index, structure, compiled) {
|
|
154
|
+
const container = item.style === "dimension" ? "dimension" : "scene";
|
|
155
|
+
switch (item.role) {
|
|
156
|
+
case "text":
|
|
157
|
+
return `${container}|text`;
|
|
158
|
+
case "line":
|
|
159
|
+
return `${container}|line|${getThickness(item)}`;
|
|
160
|
+
case "image":
|
|
161
|
+
return `image|${index}`;
|
|
162
|
+
default:
|
|
163
|
+
return `${container}|solid|${materialClassKey(getMaterialClass(item, compiled.targets[item.target], structure))}`;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** Solids of one material class as instances of one BatchedMesh, each slot an instance */
|
|
167
|
+
function createSolidPart(entries, material) {
|
|
168
|
+
const geometries = [...new Set(entries.map((e) => e.geometry))];
|
|
169
|
+
const vertexCount = geometries.reduce((sum, g) => sum + g.getAttribute("position").count, 0);
|
|
170
|
+
const indexCount = geometries.reduce((sum, g) => sum + (g.index?.count ?? 0), 0);
|
|
171
|
+
const batch = new BatchedMesh(entries.length, vertexCount, indexCount, material);
|
|
172
|
+
const geometryIds = new Map(geometries.map((g) => [g, batch.addGeometry(g)]));
|
|
173
|
+
entries.forEach((e) => batch.addInstance(geometryIds.get(e.geometry)));
|
|
174
|
+
const bounds = { dirty: true };
|
|
175
|
+
return {
|
|
176
|
+
object: batch,
|
|
177
|
+
place: (slot, matrix) => {
|
|
178
|
+
batch.setMatrixAt(slot, scratch.multiplyMatrices(matrix, entries[slot].local));
|
|
179
|
+
bounds.dirty = true;
|
|
180
|
+
},
|
|
181
|
+
paint: (slot, color) => {
|
|
182
|
+
batch.setColorAt(slot, color);
|
|
183
|
+
},
|
|
184
|
+
flush: () => {
|
|
185
|
+
if (bounds.dirty) {
|
|
186
|
+
batch.computeBoundingBox();
|
|
187
|
+
batch.computeBoundingSphere();
|
|
188
|
+
bounds.dirty = false;
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
pickSlot: (hit) => hit.batchId,
|
|
192
|
+
dispose: () => {
|
|
193
|
+
batch.dispose();
|
|
194
|
+
material.dispose();
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function paintImage(material, color) {
|
|
199
|
+
material.color.setRGB(color.x, color.y, color.z);
|
|
200
|
+
material.opacity = color.w;
|
|
201
|
+
}
|
|
202
|
+
const toTextEntry = ({ mesh: { geometry: g } }) => g.type === "Text" ? { text: g.text, fontSize: g.fontSize, local: transform(g.pos, g.rot) } : { text: "", fontSize: 0, local: new Matrix4() };
|
|
203
|
+
const toSegment = ({ mesh: { geometry: g } }) => g.type === "CulledLine"
|
|
204
|
+
? { start: g.start, end: g.end, normal: g.normal }
|
|
205
|
+
: g.type === "Line"
|
|
206
|
+
? { start: g.start, end: g.end }
|
|
207
|
+
: { start: vec3Zero, end: vec3Zero };
|
|
208
|
+
const getThickness = ({ mesh: { geometry: g } }) => (g.type === "Line" || g.type === "CulledLine" ? g.thickness : 0);
|
|
209
|
+
const scratch = new Matrix4();
|
|
210
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/renderers/three/build.ts"],"names":[],"mappings":"AAAA,OAAO,EACL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E,QAAQ,EAAE,CAAC;AAE3C,MAAM,YAAY,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAQ,EAAU,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnI,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { OrthographicCamera, PerspectiveCamera } from "three";
|
|
2
|
+
import type { Vec3, View } from "../../../abstract-3d.js";
|
|
3
|
+
/** Fitting the camera to the scene, inside buffer zones of the canvas that UI covers; the fit math of the r3f renderer's react-camera.tsx */
|
|
4
|
+
export type CameraOptions = {
|
|
5
|
+
readonly type: "Perspective";
|
|
6
|
+
readonly near?: number;
|
|
7
|
+
readonly far?: number;
|
|
8
|
+
readonly fov?: number;
|
|
9
|
+
} | {
|
|
10
|
+
readonly type: "Orthographic";
|
|
11
|
+
readonly near?: number;
|
|
12
|
+
readonly far?: number;
|
|
13
|
+
};
|
|
14
|
+
/** Margins of the canvas, in CSS pixels, that the scene is fitted inside of */
|
|
15
|
+
export type BufferZones = {
|
|
16
|
+
readonly left?: number;
|
|
17
|
+
readonly right?: number;
|
|
18
|
+
readonly top?: number;
|
|
19
|
+
readonly bottom?: number;
|
|
20
|
+
};
|
|
21
|
+
export type FitInput = {
|
|
22
|
+
readonly view: View;
|
|
23
|
+
/** The scene's size */
|
|
24
|
+
readonly size: Vec3;
|
|
25
|
+
/** In CSS pixels */
|
|
26
|
+
readonly canvas: {
|
|
27
|
+
readonly width: number;
|
|
28
|
+
readonly height: number;
|
|
29
|
+
};
|
|
30
|
+
readonly bufferZones: BufferZones;
|
|
31
|
+
readonly fitPadding: number;
|
|
32
|
+
};
|
|
33
|
+
/** Where to place the camera: its distance from the target, and the direction from the target to it */
|
|
34
|
+
export type Placement = {
|
|
35
|
+
readonly distance: number;
|
|
36
|
+
readonly direction: Vec3;
|
|
37
|
+
};
|
|
38
|
+
/** Sets the camera's projection to fit the scene into the usable area of the canvas, and returns where to place it */
|
|
39
|
+
export declare function fitCamera(camera: PerspectiveCamera | OrthographicCamera, { view, size: sceneSize, canvas, bufferZones, fitPadding }: FitInput): Placement | undefined;
|
|
40
|
+
//# sourceMappingURL=camera.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camera.d.ts","sourceRoot":"","sources":["../../../../src/renderers/three/camera/camera.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAEnE,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAG1D,6IAA6I;AAE7I,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GACtG;IAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAErF,+EAA+E;AAC/E,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/H,MAAM,MAAM,QAAQ,GAA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