Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/Scene.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import { tickAnimatedMixers } from '$lib/animatedImports';
import { tickSim } from '$lib/sim/runtime.js'; // 36-sim: jiggle, splashes, fluid tanks
import { tickTextPathsLazy } from '$lib/textPathTick.js'; // 64 D2: text on a path
import { tickArraysLazy } from '$lib/arrayTick.js'; // 102b-arrange: array copies (lazy runtime)
import { startPackBehaviors, tickPackBehaviors } from '$lib/packBehavior';
import { startArchParts } from '$lib/arch/archParts.js';
import { tickAnimationPreview, captureAutoKey, playheadOf } from '$lib/animationPreview';
Expand Down Expand Up @@ -459,6 +460,7 @@
tickPackBehaviors(); // 33 P2: doors/lids/levers pose from their shared state (rest in Edit)
tickSim($objectsGroup, camera.current, renderer, performance.now()); // 36-sim (after mixers: jiggle rides the posed bones)
tickTextPathsLazy($objectsGroup, performance.now()); // 64 D2: letters follow their carriers (and linked paths)
tickArraysLazy($objectsGroup, performance.now()); // 102b-arrange: every peer draws its arrays' copies
tickAnimationPreview(); // Animation window: local transform preview (not synced)
tickSequences(); // 48 S2: shots / clips / audio / events of running sequences
tickMeshEdit(); // vertex handles follow the object if it moves (119)
Expand Down Expand Up @@ -1112,7 +1114,11 @@
const area = $marqueeRect;
const picked = [];
const center = new THREE.Vector3();
// 102b-arrange: a box skips objects on a LOCKED layer and on a layer hidden here
const locked: Set<string> | undefined = (editorPass() as any).lockedLayers;
for (const object of $objectsGroup?.children ?? []) {
const layer = object.userData?.layer;
if (layer && (locked?.has(layer) || object.visible === false)) continue;
const box = new THREE.Box3().setFromObject(object);
if (!isFinite(box.min.x)) continue;
box.getCenter(center).project(camera.current);
Expand Down
13 changes: 13 additions & 0 deletions src/components/menu/Inspector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2411,6 +2411,9 @@
</div>
</Section>

<!-- 102b-arrange row 2: the scene's layers (a lazy chunk) -->
<Section variant="panel" label="Layers" closed aliases={['Layer', 'Hide layer', 'Lock layer']}>{#await import('./inspector/LayersSection.svelte') then m}<m.default />{/await}</Section>

<Section variant="panel" label="Levels" closed aliases={['Level', 'Portals', 'Checkpoints', 'Loading screen', 'Keep across levels']} note={sectionNote('Levels')}><LevelsSection /></Section>

<Section variant="panel" label="Physics" closed note={sectionNote('Physics')}>
Expand Down Expand Up @@ -3781,6 +3784,11 @@
<ArrangeSection count={multiCount} />
{/if}

<!-- 102b-arrange row 2: Tidy (layer, select similar, rename many, randomise) — a lazy chunk -->
{#if $selectedObjects?.length}
{#await import('./inspector/TidySection.svelte') then m}<m.default />{/await}
{/if}

{#if !isLight}
<Section variant="panel" label="Object" clip={{ count: () => insTargets.length, fans: true }}>
<PropRow label="Render order" labelFor="inspector-render-order" valueBox={false}>
Expand Down Expand Up @@ -3846,6 +3854,11 @@
<ScatterSection object={$selectedObject} />
{/if}

{#if !isLight && !multiCount && $selectedObject?.uuid && $selectedObject?.isObject3D}
<!-- 102b-arrange row 1: Array (a lazy chunk — nothing here is paid at boot) -->
{#await import('./inspector/ArraySection.svelte') then m}<m.default object={$selectedObject} />{/await}
{/if}

{#if devPrimary}
<Section variant="panel" label="Device">
<!-- 23-B4: the device's declared params, fanned over the selection; presets and
Expand Down
12 changes: 12 additions & 0 deletions src/components/menu/Objects.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
// THREE children/userData aren't reactive — re-derive on each objectsGroup poke
const kids = $derived.by(() => { void $objectsGroup; return (element?.children ?? []).filter((/** @type {any} */ c) => !c.userData?.archPart); }); // 37 R3: a door's leaf is not a row
const isLocal = $derived.by(() => { void $objectsGroup; return !!element?.userData?.__localOnly; });
// 102b-arrange: the layer this row is on (a colour dot; absent = no layer, the row is unchanged)
const layerRow = $derived.by(() => {
void $objectsGroup;
const id = element?.userData?.layer;
if (!id) return null;
const list = $scenePhysicsState_?.layers;
return (Array.isArray(list) && list.find((/** @type {any} */ l) => l?.id === id)) || null;
});
// groups on the path to a match auto-expand while filtering
$effect(() => {
if ($objectFilter && kids.length > 0 && $objectFilter.has(element.uuid))
Expand All @@ -37,6 +45,7 @@
import { withExpanded } from '$lib/objectListNav';
import { objectsGroup, TControls, selectedObject, selectedObjects, lockedObjects } from '../../stores/sceneStore';
import { sceneCommand } from '$lib/commandsHandler.svelte';
import { scenePhysicsState_ } from '$lib/scenePhysics';
import { selectObject, renameObject, toggleObjectVisibility, dragUuidsFor, moveObjectsToParent } from '$lib/objectActions';
import { nameOf, peerColor } from '$lib/lockControl';
import { objectName, objectTypeLabel } from '$lib/a11y/announce';
Expand Down Expand Up @@ -333,6 +342,9 @@
{element.name}
</p>
{/if}
{#if layerRow}
<span class="layer-dot h-2 w-2 shrink-0 rounded-full" style={'background:' + layerRow.color} title={'Layer: ' + layerRow.name + (layerRow.locked ? ' (locked)' : '')} aria-label={'Layer ' + layerRow.name}></span>
{/if}

<!-- quick actions: appear on hover; lock badge when held by a peer -->
{#if lockEntry}
Expand Down
129 changes: 129 additions & 0 deletions src/components/menu/inspector/ArraySection.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<script>
// 102b-arrange row 1 — Inspector ▸ Array: repeat the object in a line, a grid, a circle or along a
// path. The copies are drawn from ONE record on the object (arrayRuntime), so every field is a live
// preview, one undo step per edit (a scrub folds into one) and one message to peers per edit.
// "Make real objects" turns the copies into ordinary objects (one undo). Loaded lazily by the
// Inspector, so nothing here is paid at boot.
// @ts-ignore - no bundled three type declarations (project-wide)
import * as THREE from 'three';
import Section from '../../ui/Section.svelte';
import PropRow from '../../ui/PropRow.svelte';
import DragRow from '../../ui/DragRow.svelte';
import Segmented from '../../ui/Segmented.svelte';
import Toggle from '../../ui/Toggle.svelte';
import ThemedSelect from '../../ui/ThemedSelect.svelte';
import UiButton from '../../ui/Button.svelte';
import { objectsGroup, sceneRevision } from '../../../stores/sceneStore';
import { normalizeArray, arraySummary, ARRAY_MAX } from '$lib/arrayCore.js';
import { setArray, makeArrayReal } from '$lib/arrayActions.js';
import { textPathTargets } from '$lib/textPathSources.js';

/** @type {{ object: any }} */
let { object } = $props();

const uuid = $derived(object?.uuid ?? '');
const rec = $derived.by(() => {
void $sceneRevision;
return object?.userData?.array ? normalizeArray(object.userData.array) : null;
});
const pathItems = $derived.by(() => {
void $sceneRevision;
return textPathTargets($objectsGroup).filter((t) => t.value !== uuid);
});
const AXES = /** @type {const} */ (['x', 'y', 'z']);

/** @param {any} patch */
const set = (patch) => setArray(uuid, patch);
/** @param {'step'|'grid'|'gridStep'|'rotStep'} key @param {number} axis @param {number} v */
function setAxis(key, axis, v) {
if (!rec) return;
const next = [...rec[key]];
next[axis] = v;
set({ [key]: next });
}

/** a first array: five copies in a row along X, spaced by the object's own width plus a little */
function start() {
const box = new THREE.Box3().setFromObject(object);
const width = box.isEmpty() ? 1 : Math.max(0.1, box.max.x - box.min.x);
const parentScale = object.parent ? object.parent.getWorldScale(new THREE.Vector3()).x || 1 : 1;
const step = Math.round(((width + 0.25) / parentScale) * 100) / 100;
set({ mode: 'line', count: 5, step: [step, 0, 0], gridStep: [step, step, step], radius: Math.max(1, step * 1.5) });
}
</script>

<Section variant="panel" label="Array">
<div id="array-section" class="flex flex-col gap-1">
{#if !rec}
<p class="text-[length:var(--fs-badge)] text-text-faint">Repeat this object in a line, a grid, a circle or along a path. The copies follow every change you make to it.</p>
<div class="flex justify-end">
<UiButton id="array-start" size="sm" variant="outline" icon="repeat" text="Make an array" title="Repeat this object: five copies in a row to start with (one undo)" onclick={start} />
</div>
{:else}
<p id="array-summary" class="text-[length:var(--fs-badge)] text-text-2">{arraySummary(rec)}</p>
<PropRow label="Shape" valueBox={false}>
{#snippet control()}
<Segmented
id="array-mode"
label="Array shape"
options={[
{ value: 'line', label: 'Line', title: 'Copies in a row, each one step further on' },
{ value: 'grid', label: 'Grid', title: 'Copies in rows and columns (and layers)' },
{ value: 'circle', label: 'Circle', title: 'Copies around a centre (a full ring or an arc)' },
{ value: 'path', label: 'Path', title: 'Copies along a Path, a spline or a flow path' }
]}
value={rec.mode}
onchange={(/** @type {string} */ v) => set({ mode: v })}
/>
{/snippet}
</PropRow>
{#if rec.mode !== 'grid'}
<DragRow id="array-count" label="Count" title={`How many objects, this one included (2-${ARRAY_MAX})`} value={rec.count} min={2} max={ARRAY_MAX} step={1} decimals={0} onchange={(v) => set({ count: v })} />
{/if}
{#if rec.mode === 'line'}
{#each AXES as axis, i (axis)}
<DragRow id={`array-step-${axis}`} label={`Step ${axis.toUpperCase()}`} title={`Distance from one copy to the next on ${axis.toUpperCase()}`} unit="length" value={rec.step[i]} step={0.05} onchange={(v) => setAxis('step', i, v)} />
{/each}
{:else if rec.mode === 'grid'}
{#each AXES as axis, i (axis)}
<DragRow id={`array-grid-${axis}`} label={`Count ${axis.toUpperCase()}`} title={`How many on ${axis.toUpperCase()} (the grid holds up to ${ARRAY_MAX})`} value={rec.grid[i]} min={1} max={50} step={1} decimals={0} onchange={(v) => setAxis('grid', i, v)} />
{/each}
{#each AXES as axis, i (axis)}
<DragRow id={`array-gridstep-${axis}`} label={`Spacing ${axis.toUpperCase()}`} title={`Distance between neighbours on ${axis.toUpperCase()}`} unit="length" value={rec.gridStep[i]} step={0.05} onchange={(v) => setAxis('gridStep', i, v)} />
{/each}
{:else if rec.mode === 'circle'}
<DragRow id="array-radius" label="Radius" title="How far the copies sit from the centre (the centre is this far to the object's left, -X)" unit="length" value={rec.radius} min={0} max={1000} step={0.05} onchange={(v) => set({ radius: v })} />
<DragRow id="array-arc" label="Arc" title="How much of the circle to fill, in degrees (360 = a full ring)" value={rec.arc} min={1} max={360} step={1} decimals={0} onchange={(v) => set({ arc: v })} />
<PropRow label="Face out" valueBox={false}>
{#snippet control()}
<Toggle id="array-face-out" label="Face out" title="Turn each copy to face away from the centre" checked={rec.faceOut} onchange={(v) => set({ faceOut: v })} />
{/snippet}
</PropRow>
{:else}
<PropRow label="Path" valueBox={false}>
{#snippet control()}
<ThemedSelect id="array-path" class="min-w-0" title="The Path the copies follow; its shape starts at this object" placeholder={pathItems.length ? 'Pick a path' : 'No paths in the scene'} items={pathItems.map((t) => ({ value: t.value, name: t.name }))} value={rec.path || undefined} onchange={(v) => set({ path: String(v ?? '') })} />
{/snippet}
</PropRow>
{#if !rec.path}
<p id="array-path-hint" class="text-[length:var(--fs-badge)] text-text-faint">Pick a Path (Add ▸ Path), a spline or a flow path. The copies follow its shape, starting at this object.</p>
{/if}
<DragRow id="array-spacing" label="Spacing" title="Distance between copies along the path (0 = spread them evenly over its whole length)" unit="length" value={rec.spacing} min={0} max={1000} step={0.05} onchange={(v) => set({ spacing: v })} />
<PropRow label="Follow" valueBox={false}>
{#snippet control()}
<Toggle id="array-follow" label="Turn with the path" title="Turn each copy with the path's direction" checked={rec.follow} onchange={(v) => set({ follow: v })} />
{/snippet}
</PropRow>
{/if}
{#each AXES as axis, i (axis)}
<DragRow id={`array-rot-${axis}`} label={`Turn ${axis.toUpperCase()}`} title={`Each copy turns this many more degrees about its own ${axis.toUpperCase()} than the one before`} value={rec.rotStep[i]} min={-360} max={360} step={1} decimals={1} onchange={(v) => setAxis('rotStep', i, v)} />
{/each}
<DragRow id="array-scale-step" label="Grow" title="Size change per copy (0.1 = each copy 10 % bigger than the one before; negative shrinks)" value={rec.scaleStep} min={-0.9} max={10} step={0.01} decimals={2} onchange={(v) => set({ scaleStep: v })} />
<p class="text-[length:var(--fs-badge)] text-text-faint">Copies are drawn, not objects: they have no physics or logic and you cannot click them. Make them real objects to give them their own.</p>
<div class="flex flex-wrap justify-end gap-1">
<UiButton id="array-remove" size="sm" variant="ghost" icon="trash-2" text="Remove array" title="Take the copies away; the object stays (one undo)" onclick={() => set(null)} />
<UiButton id="array-make-real" size="sm" variant="outline" icon="boxes" text="Make real objects" title="Turn every copy into an ordinary object you can move, give physics and logic to (one undo)" onclick={() => makeArrayReal(uuid)} />
</div>
{/if}
</div>
</Section>
80 changes: 80 additions & 0 deletions src/components/menu/inspector/LayersSection.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<script>
// 102b-arrange row 2 — Configure Scene ▸ Layers: name, colour and lock (scene data: saved, shared,
// one undo per edit) and hide (THIS screen only). A lazy chunk: the Inspector imports it on demand.
import UiButton from '../../ui/Button.svelte';
import { scenePhysicsState_ } from '$lib/scenePhysics';
import { sceneRevision } from '../../../stores/sceneStore';
import { normalizeLayers } from '$lib/layersCore.js';
import { addLayer, updateLayer, removeLayer, selectLayer, setLayerHidden, membersOf } from '$lib/tidyActions.js';
import { hiddenLayers } from '$lib/layersRuntime.js';

const layers = $derived(normalizeLayers($scenePhysicsState_?.layers) ?? []);
const counts = $derived.by(() => {
void $sceneRevision;
/** @type {Record<string, number>} */
const out = {};
for (const l of layers) out[l.id] = membersOf(l.id).length;
return out;
});
</script>

<div id="layers-section" class="flex flex-col gap-1">
{#if !layers.length}
<p class="text-[length:var(--fs-badge)] text-text-faint">Layers group objects across the scene so you can hide, lock or select them together. Put an object on a layer in its Inspector (Tidy ▸ Layer).</p>
{/if}
{#each layers as l (l.id)}
<div class="layer-row flex items-center gap-1" data-layer-id={l.id}>
<input
class="layer-swatch"
type="color"
value={l.color}
aria-label={`Colour of layer ${l.name}`}
title="The layer's colour (shown beside its objects' layer)"
onchange={(e) => updateLayer(l.id, { color: e.currentTarget.value })}
/>
<input
class="ui-input min-w-0 flex-1"
value={l.name}
aria-label="Layer name"
title="Rename the layer"
onchange={(e) => updateLayer(l.id, { name: e.currentTarget.value })}
/>
<span class="text-[length:var(--fs-badge)] text-text-faint" title="Objects on this layer">{counts[l.id] ?? 0}</span>
<UiButton
variant="icon"
size="sm"
icon={$hiddenLayers.has(l.id) ? 'eye-off' : 'eye'}
label={$hiddenLayers.has(l.id) ? `Show layer ${l.name}` : `Hide layer ${l.name}`}
title={$hiddenLayers.has(l.id) ? 'Show this layer again (this screen only)' : 'Hide this layer on your screen only; nobody else is affected and saves keep it'}
pressed={$hiddenLayers.has(l.id)}
onclick={() => setLayerHidden(l.id, !$hiddenLayers.has(l.id))}
/>
<UiButton
variant="icon"
size="sm"
icon={l.locked ? 'lock' : 'lock-open'}
label={l.locked ? `Unlock layer ${l.name}` : `Lock layer ${l.name}`}
title={l.locked ? 'Unlock: its objects can be clicked again' : 'Lock for everyone: clicks in the viewport pass through its objects (pick them in the object list)'}
pressed={!!l.locked}
onclick={() => updateLayer(l.id, { locked: !l.locked })}
/>
<UiButton variant="icon" size="sm" icon="box-select" label={`Select layer ${l.name}`} title="Select every object on this layer" onclick={() => selectLayer(l.id)} />
<UiButton variant="icon" size="sm" icon="trash-2" label={`Remove layer ${l.name}`} title="Remove the layer; its objects stay, on no layer (one undo)" onclick={() => removeLayer(l.id)} />
</div>
{/each}
<div class="flex justify-end">
<UiButton id="layers-add" size="sm" variant="outline" icon="layers" text="Add layer" title="Add a layer to this scene (one undo)" onclick={() => addLayer()} />
</div>
</div>

<style>
.layer-swatch {
width: 1.5rem;
height: 1.5rem;
padding: 0;
border: 1px solid var(--border-input);
border-radius: 0.25rem;
background: none;
flex: none;
}
</style>
Loading
Loading