diff --git a/docs/P1_BENCHMARKS.md b/docs/P1_BENCHMARKS.md new file mode 100644 index 0000000..506b8e6 --- /dev/null +++ b/docs/P1_BENCHMARKS.md @@ -0,0 +1,139 @@ +# GLB Viewer — P1 Benchmark Specification + +## Purpose + +This document defines how GLB Viewer performance and editing behavior are to be evaluated. It separates intended product behavior, performance targets, and measurements collected from real runs. + +A benchmark result is meaningful only when its environment and model are recorded. A result from one computer must not be presented as a universal guarantee. + +## Product benchmark principles + +1. Keep the viewer usable on modest Windows laptops, not only workstation-class hardware. +2. Prefer predictable interaction and stable resource use over visual effects that make editing unreliable. +3. Do not silently discard model content during editing or export. +4. Keep model files and diagnostics local unless a user explicitly chooses to share them. +5. Compare the same model, browser, resolution, and quality settings when measuring changes. + +## Hardware profiles + +Record the actual machine; do not assume a machine belongs to a profile from its model name alone. + +| Profile | Intended use | Record | +|---|---|---| +| Minimum / constrained | Older dual-core CPU, 8 GB RAM, integrated graphics, HDD | CPU, RAM, GPU, storage type, OS | +| Recommended | Modern quad-core CPU, 16 GB RAM, integrated or entry GPU, SSD | CPU, RAM, GPU, storage type, OS | +| Higher capacity | Dedicated GPU and 16 GB+ RAM | Exact GPU and driver, CPU, RAM, storage | + +The minimum profile is a compatibility target, not a promise that every arbitrarily large GLB will run smoothly. + +## Model profiles + +Use real GLB files and preserve the exact files used for each benchmark. Record filename, file size, mesh count, vertex count, triangle count, material count, texture count, animation count, and approximate texture dimensions. + +| Profile | Suggested characteristics | Purpose | +|---|---|---| +| Small | Under 5 MB, simple geometry, few materials | Startup and basic editing baseline | +| Medium | 5–30 MB, multiple meshes/materials, some textures | Typical editing workflow | +| Large | 30–100 MB or high geometry/texture complexity | Resource and stability behavior | +| Stress | Above 100 MB or unusually dense/texture-heavy | Limits and failure handling, not a minimum-device guarantee | + +These are test groupings, not strict file-size-only complexity definitions. Geometry and texture memory can dominate compressed file size. + +## Measurements to record + +### Loading +- Time from selecting the file to the model becoming visible and interactive. +- Whether progress feedback remains responsive. +- Whether a failed load leaves the previously loaded model usable. +- Whether replacing models repeatedly causes visible resource accumulation. + +### Viewport and editing +- Approximate frame rate or frame-time behavior while orbiting. +- Selection response and Outliner responsiveness. +- Transform responsiveness for one object and multiple objects. +- Whether locked objects remain unchanged. +- Whether undo and redo restore the exact prior state. +- Whether material, lighting, visibility, and hierarchy edits remain coherent. + +### Export +- Time from export action to completed download. +- Output file size. +- Whether the exported file reopens. +- Whether hierarchy, transforms, materials, textures, visibility expectations, and animations are preserved. +- Any source features that the exporter or format cannot preserve must be recorded explicitly. + +### Resource observations +- Browser memory observations where available. +- Three.js renderer memory counters and geometry/texture counts. +- WebGL context loss, tab crashes, and out-of-memory symptoms. +- Note that renderer counters are not total browser-process or system memory. + +## Measurement procedure + +For every run, record: + +- Date and GLB Viewer commit/version. +- Operating system and browser version. +- CPU, installed RAM, GPU, graphics driver, and storage type. +- Display resolution, browser zoom, and device pixel ratio. +- Model profile and exact source filename. +- Whether the run was cold (first load) or warm (subsequent load). +- Any other applications consuming significant resources. + +Run each scenario at least three times where practical. Report individual results and the median; do not report only the best run. Keep cold and warm loads separate. + +## P1 workflow benchmark + +Use one representative model containing multiple selectable meshes and at least one material with a texture when possible. + +1. Open the model. +2. Inspect its metadata. +3. Select one object and manipulate it with the gizmo. +4. Select multiple objects and manipulate them together. +5. Apply numeric transforms. +6. Exercise X/Y/Z axis constraints and Local/World space. +7. Edit material properties and supported texture channels. +8. Change lighting and viewport settings. +9. Undo and redo representative edits. +10. Export the edited GLB and reopen it. +11. Compare the reopened result with the expected edited scene. + +## Results template + +Copy this block for each machine/model combination: + +- Date: +- Viewer commit: +- OS / browser: +- CPU: +- RAM: +- GPU / driver: +- Storage: +- Resolution / device pixel ratio: +- Model filename / profile: +- File size: +- Meshes / vertices / triangles: +- Materials / textures / animations: +- Cold load time: +- Warm load time: +- Viewport observations: +- Multi-object transform observations: +- Undo/redo observations: +- Export duration / output size: +- Reopen and content-preservation observations: +- Memory / renderer observations: +- Errors or limitations: + +## Targets versus measured results + +Do not fill this document with guessed performance numbers. Numeric acceptance thresholds should be set only after baseline measurements on the minimum and recommended profiles. + +A future benchmark report should publish: +- The exact environment and source models. +- Median and range, not only a best run. +- Known limitations and failed scenarios. +- Whether a result is a target, an observed measurement, or a regression comparison. + +## Current status + +This document is the benchmark protocol. It does not claim that the benchmarks have been run or that any performance target has been achieved. diff --git a/scripts/update-viewer.ps1 b/scripts/update-viewer.ps1 index e983f3c..25c6372 100644 --- a/scripts/update-viewer.ps1 +++ b/scripts/update-viewer.ps1 @@ -30,13 +30,18 @@ try { 'src/editor/WorkspaceManager.js', 'src/editor/ViewportInteraction.js', 'src/editor/SceneRuntime.js', + 'src/editor/CommandPalette.js', + 'src/editor/OrbitPreview.js', + 'src/editor/ViewportWorkspace.js', + 'src/editor/MultiObjectTransform.js', 'src/core/ResourceDisposer.js', 'src/core/PerformanceMonitor.js', 'src/core/HardwareProviders.js', 'src/core/AdaptiveQualityPolicy.js', 'src/core/SceneStore.js', 'src/core/CommandHistory.js', - 'src/core/SceneCommands.js' + 'src/core/SceneCommands.js', + 'src/core/ModelInspector.js' ) $stageRoot = Join-Path $UpdateRoot ('.staging-' + [guid]::NewGuid().ToString('N')) $bundleRoot = Join-Path $UpdateRoot $commitSha diff --git a/src/core/ModelInspector.js b/src/core/ModelInspector.js new file mode 100644 index 0000000..fa711c5 --- /dev/null +++ b/src/core/ModelInspector.js @@ -0,0 +1,52 @@ +/** + * Inspect a loaded Three.js Object3D tree without mutating it. + * Returns primitive counts, material/texture totals, bounds and review warnings. + */ +export function inspectModel(root, THREE) { + if (!root || typeof root.traverse !== 'function' || !THREE?.Box3 || !THREE?.Vector3) { + throw new TypeError('A model and Three.js namespace are required.'); + } + let meshes = 0, vertices = 0, triangles = 0, groups = 0; + const materials = new Set(), textures = new Set(), warnings = new Set(); + const visited = new Set(); + root.updateWorldMatrix?.(true, true); + const collectTextures = value => { + if (!value || typeof value !== 'object' || visited.has(value)) return; + visited.add(value); + if (value.isTexture) { textures.add(value); return; } + if (Array.isArray(value)) { value.forEach(collectTextures); return; } + for (const nested of Object.values(value)) collectTextures(nested); + }; + root.traverse(object => { + if (object.isGroup) groups++; + if (object.isMesh) { + meshes++; + const geometry = object.geometry; + const position = geometry?.attributes?.position; + const count = geometry?.index ? geometry.index.count : position?.count || 0; + if (!position) warnings.add('A mesh has no position attribute.'); + else { + vertices += position.count; + triangles += Math.floor(count / 3); + if (count % 3 !== 0) warnings.add('Some mesh geometry is not a complete set of triangles.'); + } + if (geometry?.morphAttributes && Object.keys(geometry.morphAttributes).length) warnings.add('Morph targets are present; verify animation after export.'); + if (object.isSkinnedMesh) warnings.add('Skinned mesh detected; verify skinning after export.'); + const slots = Array.isArray(object.material) ? object.material : [object.material]; + for (const material of slots) { + if (!material) continue; + materials.add(material); + collectTextures(material); + } + } + if (object.isLine || object.isPoints) warnings.add('Line or point geometry is present; GLB export compatibility should be checked.'); + }); + const bounds = new THREE.Box3().setFromObject(root); + const size = bounds.getSize(new THREE.Vector3()); + if (bounds.isEmpty()) warnings.add('Model bounds could not be calculated.'); + return { + meshes, vertices, triangles: Math.round(triangles), groups, + materials: materials.size, textures: textures.size, + warnings: [...warnings], size, + }; +} diff --git a/src/core/SceneCommands.js b/src/core/SceneCommands.js index 121b748..9d3e8b3 100644 --- a/src/core/SceneCommands.js +++ b/src/core/SceneCommands.js @@ -171,3 +171,77 @@ export class ReparentObjectCommand { this.sceneStore.reparentObject(this.objectId, this.snapshot.oldParent, this.snapshot.oldIndex); } } + +export class RenameObjectCommand { + constructor(sceneStore, objectId, name) { + requireSceneMutationApi(sceneStore, 'requireObject'); + this.sceneStore=sceneStore;this.objectId=String(objectId);this.name=String(name).trim(); + if(!this.name)throw new TypeError('Object name cannot be empty.'); + this.previousName=null; + } + do(){ + const object=this.sceneStore.requireObject(this.objectId); + if(this.previousName===null)this.previousName=object.name||''; + object.name=this.name; + this.sceneStore.emit?.('object:changed',{action:'rename',object}); + this.sceneStore.emit?.('scene:changed',{action:'rename',object}); + } + undo(){ + if(this.previousName===null)throw new Error('Cannot undo a rename before it executes.'); + const object=this.sceneStore.requireObject(this.objectId);object.name=this.previousName; + this.sceneStore.emit?.('object:changed',{action:'rename',object}); + this.sceneStore.emit?.('scene:changed',{action:'rename',object}); + } +} + + +/** + * Reversible material-property edit. Values with clone()/copy() (for example + * THREE.Color) are snapshotted by value; textures and other resource objects + * are retained by reference so undo can restore the original resource. + */ +export class SetMaterialPropertiesCommand { + constructor(material, properties) { + if (!material || typeof material !== 'object') { + throw new TypeError('A material object is required.'); + } + if (!properties || typeof properties !== 'object' || Array.isArray(properties) || + Object.keys(properties).length === 0) { + throw new TypeError('At least one material property is required.'); + } + this.material = material; + this.properties = { ...properties }; + this.previous = null; + } + + snapshot() { + const values = {}; + for (const key of Object.keys(this.properties)) { + const value = this.material[key]; + values[key] = value && !value.isTexture && typeof value.clone === 'function' ? value.clone() : value; + } + return values; + } + + apply(values) { + for (const [key, value] of Object.entries(values)) { + const current = this.material[key]; + if (current && value && !current.isTexture && !value.isTexture && typeof current.copy === 'function' && typeof value === 'object') { + current.copy(value); + } else { + this.material[key] = value; + } + } + this.material.needsUpdate = true; + } + + do() { + if (this.previous === null) this.previous = this.snapshot(); + this.apply(this.properties); + } + + undo() { + if (this.previous === null) throw new Error('Cannot undo a material edit before it executes.'); + this.apply(this.previous); + } +} diff --git a/src/editor/CommandPalette.js b/src/editor/CommandPalette.js new file mode 100644 index 0000000..3621e8f --- /dev/null +++ b/src/editor/CommandPalette.js @@ -0,0 +1,88 @@ +/** CommandPalette — state-aware keyboard command search for the editor. */ +const normalize = (value) => String(value || "").trim().toUpperCase().replace(/\\s+/g, " "); + +export class CommandPalette { + constructor({ root = document, input, overlay, registry, onExecute = () => {} }) { + if (!input || !overlay || !registry) throw new TypeError("CommandPalette requires input, overlay and registry."); + this.root=root; this.input=input; this.overlay=overlay; this.registry=registry; this.onExecute=onExecute; + this.query=""; this.activeIndex=0; this.opened=false; this.commands=new Map(); this.runningGroups=new Set(); + this.onKeyDown=(event)=>this.handleKeyDown(event); + this.onInput=()=>{this.query=this.input.value;this.activeIndex=0;this.render();}; + this.onClick=(event)=>{const item=event.target.closest("[data-command-id]");if(item)this.execute(item.dataset.commandId);}; + this.root.addEventListener("keydown",this.onKeyDown,true); + this.input.addEventListener("input",this.onInput); + this.overlay.addEventListener("click",this.onClick); + } + register(command) { + if(!command||!/^[a-z0-9][a-z0-9-]*$/i.test(command.id||"")||typeof command.execute!=="function") throw new TypeError("A command requires a valid id and execute function."); + if(this.commands.has(command.id)) throw new Error(`Command "${command.id}" is already registered.`); + const entry={label:command.id.toUpperCase(),description:"",aliases:[],keywords:[],enabled:()=>true,disabledReason:()=>"Unavailable",...command}; + this.commands.set(entry.id,entry);this.refresh();return()=>{this.commands.delete(entry.id);this.refresh();}; + } + state(command) { + let enabled=false,reason=""; + try { enabled=Boolean(command.enabled()); if(!enabled) reason=typeof command.disabledReason==="function"?command.disabledReason():command.disabledReason||"Currently unavailable"; } + catch(error){reason=error?.message||"Availability check failed";} + if(command.exclusiveGroup&&this.runningGroups.has(command.exclusiveGroup)){enabled=false;reason="Another "+command.exclusiveGroup+" operation is running";} + return {enabled,reason}; + } + list(query=this.query) { + const q=normalize(query),tokens=q.split(" ").filter(Boolean); + return [...this.commands.values()].map(command=>{ + const candidates=[command.label,command.id,...command.aliases,...command.keywords].map(normalize); + let score=0; + if(!q)score=1;else if(candidates.some(v=>v===q))score=100;else if(candidates.some(v=>v.startsWith(q)))score=80;else if(tokens.every(t=>candidates.some(v=>v.includes(t))))score=50;else return null; + return {id:command.id,command,score,...this.state(command)}; + }).filter(Boolean).sort((a,b)=>b.score-a.score||a.command.label.localeCompare(b.command.label)); + } + refresh(){if(this.opened)this.render();} + open(initial=""){this.opened=true;this.query=initial;this.activeIndex=0;this.overlay.hidden=false;this.input.value=initial;this.render();this.input.focus();this.input.setSelectionRange(this.input.value.length,this.input.value.length);} + close(){this.opened=false;this.overlay.hidden=true;this.input.value="";this.query="";} + handleKeyDown(event){ + const target=event.target,isEditable=target?.matches?.("input, textarea, select, [contenteditable='true']")||target?.isContentEditable; + if(this.opened){ + if(event.key==="Escape"){event.preventDefault();event.stopPropagation();this.close();return;} + const items=this.list(),available=items.map((item,index)=>item.enabled?index:-1).filter(index=>index>=0); + if(event.key==="ArrowDown"||event.key==="ArrowUp"){event.preventDefault();if(available.length){const current=available.indexOf(this.activeIndex),step=event.key==="ArrowDown"?1:-1;this.activeIndex=available[(current+step+available.length)%available.length];}this.render();return;} + if(event.key==="Tab"){const selected=items[this.activeIndex];if(selected?.enabled){event.preventDefault();this.input.value=selected.command.label;this.query=selected.command.label;this.activeIndex=0;this.render();}return;} + if(event.key==="Enter"){event.preventDefault();event.stopPropagation();const selected=items[this.activeIndex];if(selected?.enabled)this.execute(selected.command.id);return;} + return; + } + if(isEditable||event.defaultPrevented||event.ctrlKey||event.metaKey||event.altKey)return; + if(event.key==="F3"||(event.key===" "&&event.shiftKey)){event.preventDefault();this.open();return;} + if(event.key.length===1&&!event.repeat){event.preventDefault();this.open(event.key);} + } + execute(id){ + const command=this.commands.get(id);if(!command)return false; + const status=this.state(command);if(!status.enabled)return false; + this.close(); + const group=command.exclusiveGroup;if(group)this.runningGroups.add(group); + this.refresh(); + const release=()=>{if(group)this.runningGroups.delete(group);this.refresh();}; + let result; + try{result=command.execute();} + catch(error){this.onExecute(command,error);release();throw error;} + if(result&&typeof result.then==="function"){ + return Promise.resolve(result) + .then(()=>{this.onExecute(command);return true;}) + .catch(error=>{this.onExecute(command,error);throw error;}) + .finally(release); + } + this.onExecute(command); + release(); + return true; + } + render(){ + const items=this.list(),list=this.overlay.querySelector("[data-command-results]");list.replaceChildren(); + if(!items.length){const empty=this.root.createElement("div");empty.className="command-empty";empty.textContent="No matching commands";list.append(empty);return;} + if(this.activeIndex>=items.length||!items[this.activeIndex]?.enabled)this.activeIndex=Math.max(0,items.findIndex(item=>item.enabled)); + items.forEach(({command,enabled,reason},index)=>{ + const button=this.root.createElement("button");button.type="button";button.className="command-result"+(enabled?"":" is-disabled"); + button.dataset.commandId=command.id;button.disabled=!enabled;button.setAttribute("aria-disabled",String(!enabled));button.setAttribute("aria-selected",String(index===this.activeIndex)); + const title=this.root.createElement("span");title.textContent=command.label; + const description=this.root.createElement("small");description.textContent=enabled?command.description:(reason||command.description); + button.append(title,description);list.append(button); + }); + } + dispose(){this.root.removeEventListener("keydown",this.onKeyDown,true);this.input.removeEventListener("input",this.onInput);this.overlay.removeEventListener("click",this.onClick);this.close();this.commands.clear();this.runningGroups.clear();} +} diff --git a/src/editor/MultiObjectTransform.js b/src/editor/MultiObjectTransform.js new file mode 100644 index 0000000..8ab88ae --- /dev/null +++ b/src/editor/MultiObjectTransform.js @@ -0,0 +1,188 @@ +/** + * MultiObjectTransform — applies a TransformControls proxy delta to a selection. + * Objects keep their original parents; only their local transforms are updated. + */ +export class MultiObjectTransform { + constructor({ THREE, scene, controls, onCommit = () => {} }) { + if (!THREE || !scene || !controls) throw new TypeError('THREE, scene and TransformControls are required.'); + Object.assign(this, { THREE, scene, controls, onCommit }); + this.proxy = new THREE.Object3D(); + this.proxy.name = 'GLB Viewer multi-selection pivot'; + this.proxy.userData.editorHelper = true; + this.objects = []; + this.active = null; + this.before = null; + this.startPivot = null; + this.startPivotPosition = null; + this.startPivotQuaternion = null; + this.startPivotScale = null; + this.dragMode = 'translate'; + this.axisLocks = { x: false, y: false, z: false }; + this.space = 'world'; + } + + setSelection(objects, active, space = this.space) { + this.objects = [...new Set(objects)].filter(Boolean); + this.active = active && this.objects.includes(active) ? active : this.objects[0] || null; + this.space = space; + if (this.objects.length <= 1) { + if (this.scene.children.includes(this.proxy)) this.scene.remove(this.proxy); + if (this.objects[0]) this.controls.attach(this.objects[0]); + else this.controls.detach(); + return; + } + this.scene.add(this.proxy); + this.syncPivot(); + this.controls.attach(this.proxy); + } + + setSpace(space) { + this.space = space; + if (this.objects.length > 1) this.syncPivot(); + } + + syncPivot() { + if (this.objects.length < 2) return; + const { THREE } = this; + this.scene.updateMatrixWorld(true); + const bounds = new THREE.Box3(); + this.objects.forEach(object => bounds.expandByObject(object)); + bounds.getCenter(this.proxy.position); + this.proxy.quaternion.identity(); + if (this.space === 'local' && this.active) { + this.active.getWorldQuaternion(this.proxy.quaternion); + } + this.proxy.scale.set(1, 1, 1); + this.proxy.updateMatrixWorld(true); + } + + begin(mode = 'translate', axisLocks = {}) { + if (this.objects.length < 2) return null; + // Capture the mode and lock state once per drag so the constraint basis + // cannot drift while TransformControls updates the proxy. + this.dragMode = mode; + this.axisLocks = { x: Boolean(axisLocks.x), y: Boolean(axisLocks.y), z: Boolean(axisLocks.z) }; + this.scene.updateMatrixWorld(true); + this.proxy.updateMatrixWorld(true); + this.before = this.objects.map(object => ({ + object, + position: object.position.clone(), + quaternion: object.quaternion.clone(), + rotation: object.rotation.clone(), + scale: object.scale.clone(), + world: object.matrixWorld.clone(), + parentWorldInverse: object.parent ? object.parent.matrixWorld.clone().invert() : new this.THREE.Matrix4() + })); + this.startPivot = this.proxy.matrixWorld.clone(); + this.startPivotPosition = this.proxy.position.clone(); + this.startPivotQuaternion = this.proxy.quaternion.clone(); + this.startPivotScale = this.proxy.scale.clone(); + return this.before; + } + + constrainPivot() { + if (!this.startPivotPosition || !this.startPivotQuaternion) return; + const { THREE } = this; + const locked = this.axisLocks; + if (this.dragMode === 'translate') { + const delta = this.proxy.position.clone().sub(this.startPivotPosition); + if (this.space === 'local') delta.applyQuaternion(this.startPivotQuaternion.clone().invert()); + for (const axis of ['x', 'y', 'z']) if (locked[axis]) delta[axis] = 0; + if (this.space === 'local') delta.applyQuaternion(this.startPivotQuaternion); + this.proxy.position.copy(this.startPivotPosition).add(delta); + } else if (this.dragMode === 'rotate') { + const delta = this.space === 'local' + ? this.startPivotQuaternion.clone().invert().multiply(this.proxy.quaternion) + : this.proxy.quaternion.clone().multiply(this.startPivotQuaternion.clone().invert()); + const euler = new THREE.Euler().setFromQuaternion(delta, 'XYZ'); + for (const axis of ['x', 'y', 'z']) if (locked[axis]) euler[axis] = 0; + const constrained = new THREE.Quaternion().setFromEuler(euler); + this.proxy.quaternion.copy(this.space === 'local' + ? this.startPivotQuaternion.clone().multiply(constrained) + : constrained.multiply(this.startPivotQuaternion)); + } else if (this.dragMode === 'scale') { + for (const axis of ['x', 'y', 'z']) { + if (locked[axis]) this.proxy.scale[axis] = this.startPivotScale[axis]; + } + } + this.proxy.updateMatrixWorld(true); + } + + update() { + if (!this.before || !this.startPivot) return; + const { THREE } = this; + this.constrainPivot(); + this.proxy.updateMatrixWorld(true); + const delta = this.proxy.matrixWorld.clone().multiply(this.startPivot.clone().invert()); + for (const snapshot of this.before) { + const world = delta.clone().multiply(snapshot.world); + const local = snapshot.parentWorldInverse.clone().multiply(world); + local.decompose(snapshot.object.position, snapshot.object.quaternion, snapshot.object.scale); + snapshot.object.rotation.setFromQuaternion(snapshot.object.quaternion, snapshot.object.rotation.order); + snapshot.object.updateMatrixWorld(true); + } + this.scene.updateMatrixWorld(true); + } + + finish() { + if (!this.before) return null; + const before = this.before; + const after = before.map(snapshot => ({ + object: snapshot.object, + position: snapshot.object.position.clone(), + quaternion: snapshot.object.quaternion.clone(), + rotation: snapshot.object.rotation.clone(), + scale: snapshot.object.scale.clone() + })); + this.before = null; + this.startPivot = null; + this.startPivotPosition = null; + this.startPivotQuaternion = null; + this.startPivotScale = null; + const changed = after.some((item, index) => + !item.position.equals(before[index].position) || + !item.quaternion.equals(before[index].quaternion) || + !item.scale.equals(before[index].scale) + ); + if (!changed) return null; + const apply = snapshots => { + snapshots.forEach(value => { + value.object.position.copy(value.position); + value.object.quaternion.copy(value.quaternion); + value.object.rotation.setFromQuaternion(value.object.quaternion, value.object.rotation.order); + value.object.scale.copy(value.scale); + value.object.updateMatrixWorld(true); + }); + this.scene.updateMatrixWorld(true); + }; + const command = { do: () => apply(after), undo: () => apply(before) }; + this.onCommit(command); + this.syncPivot(); + return command; + } + + cancel() { + if (!this.before) return; + this.before.forEach(snapshot => { + snapshot.object.position.copy(snapshot.position); + snapshot.object.quaternion.copy(snapshot.quaternion); + snapshot.object.rotation.copy(snapshot.rotation); + snapshot.object.scale.copy(snapshot.scale); + snapshot.object.updateMatrixWorld(true); + }); + this.before = null; + this.startPivot = null; + this.startPivotPosition = null; + this.startPivotQuaternion = null; + this.startPivotScale = null; + this.syncPivot(); + } + + dispose() { + this.cancel(); + if (this.controls.object === this.proxy) this.controls.detach(); + this.scene.remove(this.proxy); + this.objects = []; + this.active = null; + } +} diff --git a/src/editor/OrbitPreview.js b/src/editor/OrbitPreview.js new file mode 100644 index 0000000..8d82746 --- /dev/null +++ b/src/editor/OrbitPreview.js @@ -0,0 +1,88 @@ +/** + * OrbitPreview — non-destructive camera turntable around the active model. + * It changes the camera only; model transforms and animation state are untouched. + */ +export class OrbitPreview { + constructor({ THREE, camera, controls, getModel, speed = 0.45, axis = "y" }) { + if (!THREE || !camera || !controls || typeof getModel !== "function") throw new TypeError("OrbitPreview requires THREE, camera, controls and getModel."); + this.THREE = THREE; + this.camera = camera; + this.controls = controls; + this.getModel = getModel; + this.speed = speed; + this.axis = axis; + this.active = false; + this.paused = false; + this.center = null; + this.radius = 0; + this.angle = 0; + this.height = 0; + this.onManualStart = () => this.pause(); + this.controls.addEventListener?.("start", this.onManualStart); + } + + start() { + const model = this.getModel(); + if (!model) return false; + model.updateWorldMatrix?.(true, true); + const box = new this.THREE.Box3().setFromObject(model); + if (box.isEmpty()) return false; + this.center = box.getCenter(new this.THREE.Vector3()); + this.syncFromCamera(); + this.controls.target.copy(this.center); + this.controls.update(); + this.active = true; + this.paused = false; + return true; + } + + syncFromCamera() { + if (!this.center) return; + const offset = this.camera.position.clone().sub(this.center); + this.radius = Math.max(Math.hypot(offset.x, offset.z), 0.001); + this.angle = Math.atan2(offset.x, offset.z); + this.height = offset.y; + } + + pause() { if (this.active) this.paused = true; } + resume() { + if (!this.active) return this.start(); + this.syncFromCamera(); + this.paused = false; + return true; + } + stop() { this.active = false; this.paused = false; } + toggle() { return this.active ? (this.stop(), false) : this.start(); } + + setSpeed(value) { + const speed = Number(value); + if (!Number.isFinite(speed) || speed < 0.02 || speed > 3) throw new RangeError("Orbit speed must be between 0.02 and 3 radians per second."); + this.speed = speed; + } + + setAxis(axis) { + if (!["x", "y", "z"].includes(axis)) throw new TypeError("Orbit axis must be x, y or z."); + this.axis = axis; + if (this.active) this.start(); + } + + update(deltaSeconds) { + if (!this.active || this.paused || !this.center) return; + const dt = Math.max(0, Math.min(Number(deltaSeconds) || 0, 0.1)); + this.angle += this.speed * dt; + const c = Math.cos(this.angle), s = Math.sin(this.angle); + let offset; + if (this.axis === "x") offset = new this.THREE.Vector3(this.height, this.radius * s, this.radius * c); + else if (this.axis === "z") offset = new this.THREE.Vector3(this.radius * c, this.radius * s, this.height); + else offset = new this.THREE.Vector3(this.radius * s, this.height, this.radius * c); + this.camera.position.copy(this.center).add(offset); + this.camera.lookAt(this.center); + this.controls.target.copy(this.center); + this.controls.update(); + } + + dispose() { + this.stop(); + this.controls.removeEventListener?.("start", this.onManualStart); + } +} diff --git a/src/editor/ViewportInteraction.js b/src/editor/ViewportInteraction.js index 6441bf6..d01f2a3 100644 --- a/src/editor/ViewportInteraction.js +++ b/src/editor/ViewportInteraction.js @@ -15,7 +15,7 @@ export class ViewportInteraction { const pointer = { x: ((e.clientX-rect.left)/rect.width)*2-1, y: -((e.clientY-rect.top)/rect.height)*2+1 }; this.raycaster.setFromCamera(pointer, this.camera); const hits = this.raycaster.intersectObjects(this.scene.children, true); - this.onSelect(hits.find(hit => hit.object?.isMesh)?.object || null, hits); + this.onSelect(hits.find(hit => hit.object?.isMesh)?.object || null, hits, e); }; element.addEventListener("pointerdown", this.handleDown); element.addEventListener("pointerup", this.handleUp); diff --git a/src/editor/ViewportWorkspace.js b/src/editor/ViewportWorkspace.js new file mode 100644 index 0000000..173c831 --- /dev/null +++ b/src/editor/ViewportWorkspace.js @@ -0,0 +1,103 @@ +/** + * ViewportWorkspace — lightweight viewport presentation and navigation controls. + * Grid/axes are editor helpers; shading changes material presentation only. + */ +export class ViewportWorkspace { + constructor({ THREE, scene, camera, controls, renderer, getModel, getSelection }) { + Object.assign(this,{THREE,scene,camera,controls,renderer,getModel,getSelection}); + this.grid=new THREE.GridHelper(20,20,0x777777,0x3b3b3b); + this.grid.name="__editor_grid";this.grid.userData.editorHelper=true;this.grid.visible=true; + this.axes=new THREE.AxesHelper(2);this.axes.name="__editor_axes";this.axes.userData.editorHelper=true;this.axes.visible=true; + scene.add(this.grid,this.axes); + this.originalMaterials=new Map(); + this.mode="material"; + this.savedCamera={position:camera.position.clone(),target:controls.target.clone()}; + this.selectionHelper=null; + } + setGrid(visible){this.grid.visible=Boolean(visible);} + setAxes(visible){this.axes.visible=Boolean(visible);} + setShading(mode){ + if(!["material","wireframe","normal"].includes(mode))throw new TypeError("Unsupported viewport shading mode."); + const model=this.getModel();if(!model)return; + if(this.mode!=="material")this.restoreMaterials(model); + this.mode=mode; + if(mode==="material")return; + model.traverse(object=>{ + if(!object.isMesh||!object.material)return; + const materials=Array.isArray(object.material)?object.material:[object.material]; + if(!this.originalMaterials.has(object))this.originalMaterials.set(object,object.material); + const replacement=materials.map(material=>{ + const next=mode==="wireframe" + ? new this.THREE.MeshBasicMaterial({color:0xc4cbd4,wireframe:true}) + : new this.THREE.MeshNormalMaterial(); + next.side=material.side;return next; + }); + object.material=Array.isArray(object.material)?replacement:replacement[0]; + }); + } + restoreMaterials(model=this.getModel()){ + if(!model)return; + for(const [object,original] of this.originalMaterials){ + const temporary=object.material; + const temporaryMaterials=Array.isArray(temporary)?temporary:[temporary]; + const originalMaterials=Array.isArray(original)?original:[original]; + // Dispose only the temporary viewport materials created by setShading. + // Original GLB materials and their textures remain owned by the model. + temporaryMaterials.forEach(material=>{ + if(material&&!originalMaterials.includes(material))material.dispose?.(); + }); + if(object.parent||object===model||model.getObjectById?.(object.id))object.material=original; + } + this.originalMaterials.clear(); + } + frame(object=this.getSelection()||this.getModel()){ + if(!object)return false; + object.updateWorldMatrix?.(true,true); + const box=new this.THREE.Box3().setFromObject(object); + if(box.isEmpty())return false; + const center=box.getCenter(new this.THREE.Vector3()); + const size=box.getSize(new this.THREE.Vector3()); + const radius=Math.max(size.x,size.y,size.z,0.01); + const distance=radius/(2*Math.tan(this.THREE.MathUtils.degToRad(this.camera.fov||45)/2))*1.5; + const direction=this.camera.position.clone().sub(this.controls.target); + if(direction.lengthSq()<1e-8)direction.set(0,0,1); + direction.normalize(); + this.camera.position.copy(center).addScaledVector(direction,distance); + this.controls.target.copy(center);this.controls.update(); + this.camera.near=Math.max(distance/1000,0.001);this.camera.far=Math.max(distance*100,1000); + this.camera.updateProjectionMatrix();return true; + } + preset(name){ + const model=this.getModel();if(!model)return false; + model.updateWorldMatrix?.(true,true); + const box=new this.THREE.Box3().setFromObject(model); + if(box.isEmpty())return false; + const center=box.getCenter(new this.THREE.Vector3()); + const size=box.getSize(new this.THREE.Vector3()); + const distance=Math.max(size.x,size.y,size.z,1)*2.2; + const directions={front:[0,0,1],back:[0,0,-1],right:[1,0,0],left:[-1,0,0],top:[0,1,0],bottom:[0,-1,0]}; + const direction=directions[name];if(!direction)throw new TypeError("Unknown camera preset."); + this.controls.target.copy(center); + this.camera.position.copy(center).add(new this.THREE.Vector3(...direction).multiplyScalar(distance)); + this.camera.up.set(0,1,0); + if(name==="top")this.camera.up.set(0,0,-1); + if(name==="bottom")this.camera.up.set(0,0,1); + this.camera.lookAt(center);this.controls.update();return true; + } + resetView(){const model=this.getModel();if(!model)return false;return this.frame(model);} + dispose(){ + this.restoreMaterials(); + this.scene.remove(this.grid,this.axes); + const disposeHelper = helper => { + if (!helper) return; + helper.geometry?.dispose?.(); + const materials = Array.isArray(helper.material) ? helper.material : [helper.material]; + materials.forEach(material => material?.dispose?.()); + this.scene.remove(helper); + }; + disposeHelper(this.grid); + disposeHelper(this.axes); + disposeHelper(this.selectionHelper); + this.selectionHelper = null; + } +} diff --git a/tests/command-palette.test.js b/tests/command-palette.test.js new file mode 100644 index 0000000..3b4384c --- /dev/null +++ b/tests/command-palette.test.js @@ -0,0 +1,76 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { CommandPalette } from '../src/editor/CommandPalette.js'; + +test('CommandPalette ranks prefix matches and executes selected commands', () => { + const listeners = new Map(); + const makeElement = () => ({ + hidden: true, value: '', children: [], dataset: {}, + addEventListener(type, fn) { (this.listeners ||= new Map()).set(type, fn); }, + removeEventListener() {}, + querySelector() { return this.list ||= { replaceChildren() { this.children = []; }, append(item) { this.children.push(item); } }; }, + append(...items) { this.children.push(...items); }, + replaceChildren() { this.children = []; }, + setAttribute() {}, focus() {}, setSelectionRange() {} + }); + const root = { activeElement: null, addEventListener(type, fn) { listeners.set(type, fn); }, removeEventListener() {}, createElement: makeElement }; + const input = makeElement(), overlay = makeElement(); + const palette = new CommandPalette({ root, input, overlay, registry: {} }); + let opened = 0; + palette.register({ id: 'light', label: 'LIGHT', execute: () => opened++ }); + palette.register({ id: 'lighting-reset', label: 'LIGHTING RESET', execute: () => opened += 10 }); + assert.equal(palette.list('LIG')[0].id, 'light'); + assert.equal(palette.execute('light'), true); + assert.equal(opened, 1); + palette.dispose(); +}); + +test('CommandPalette ignores editable fields and rejects duplicate commands', () => { + const root = { addEventListener() {}, removeEventListener() {}, createElement: () => ({}) }; + const input = { addEventListener() {}, removeEventListener() {} }; + const overlay = { addEventListener() {}, removeEventListener() {}, hidden: true, querySelector: () => ({ replaceChildren() {} }) }; + const palette = new CommandPalette({ root, input, overlay, registry: {} }); + palette.register({ id: 'light', execute() {} }); + assert.throws(() => palette.register({ id: 'light', execute() {} }), /already registered/); + palette.dispose(); +}); + +test('unavailable commands remain visible with a reason and cannot execute', async () => { + const makeElement = () => ({ + hidden:true,value:'',children:[],dataset:{}, + addEventListener(){},removeEventListener(){}, + querySelector(){return this.list ||= {children:[],replaceChildren(){this.children=[];},append(item){this.children.push(item);}};}, + append(...items){this.children.push(...items);},setAttribute(){},focus(){},setSelectionRange(){} + }); + const root={activeElement:null,addEventListener(){},removeEventListener(){},createElement:makeElement}; + const input=makeElement(),overlay=makeElement(); + const palette=new CommandPalette({root,input,overlay,registry:{}}); + let runs=0; + palette.register({id:'orbit-preview',label:'ORBIT PREVIEW',execute:()=>runs++,enabled:()=>false,disabledReason:()=>'Already active'}); + const item=palette.list('ORBIT')[0]; + assert.equal(item.enabled,false); + assert.equal(item.reason,'Already active'); + assert.equal(await palette.execute('orbit-preview'),false); + assert.equal(runs,0); + palette.open('ORBIT'); + assert.equal(overlay.querySelector('[data-command-results]').children[0].disabled,true); + palette.dispose(); +}); + +test('exclusive command groups prevent overlapping operations and release after completion', async () => { + const root={addEventListener(){},removeEventListener(){},createElement:()=>({})}; + const input={addEventListener(){},removeEventListener(){}}; + const overlay={addEventListener(){},removeEventListener(){},querySelector:()=>({replaceChildren(){}})}; + const palette=new CommandPalette({root,input,overlay,registry:{}}); + let finish, runs=0; + palette.register({id:'load-a',exclusiveGroup:'file',execute:()=>new Promise(resolve=>{runs++;finish=resolve;})}); + palette.register({id:'load-b',exclusiveGroup:'file',execute:()=>{runs++;}}); + const pending=palette.execute('load-a'); + assert.equal(palette.state(palette.commands.get('load-b')).enabled,false); + assert.equal(await palette.execute('load-b'),false); + finish(); + await pending; + assert.equal(palette.state(palette.commands.get('load-b')).enabled,true); + assert.equal(runs,1); + palette.dispose(); +}); diff --git a/tests/model-inspector.test.js b/tests/model-inspector.test.js new file mode 100644 index 0000000..db88734 --- /dev/null +++ b/tests/model-inspector.test.js @@ -0,0 +1,56 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { inspectModel } from '../src/core/ModelInspector.js'; + +class Vector3 { + constructor(x=0,y=0,z=0){this.x=x;this.y=y;this.z=z;} + toArray(){return [this.x,this.y,this.z];} +} +class Box3 { + setFromObject(){return this;} + getSize(target){target.x=4;target.y=2;target.z=1;return target;} + isEmpty(){return false;} +} +const THREE={Box3,Vector3}; + +function makeModel(children) { + return {children,updateWorldMatrix(){},traverse(callback){ + const visit=node=>{callback(node);(node.children||[]).forEach(visit);}; + visit(this); + }}; +} + +test('inspectModel counts indexed and non-indexed mesh geometry and unique resources',()=>{ + const texture={isTexture:true}; + const sharedMaterial={map:texture,normalMap:texture}; + const indexed={isMesh:true,geometry:{attributes:{position:{count:4}},index:{count:6}},material:sharedMaterial}; + const plain={isMesh:true,geometry:{attributes:{position:{count:3}}},material:sharedMaterial}; + const root=makeModel([{isGroup:true,children:[indexed,plain]}]); + const result=inspectModel(root,THREE); + assert.equal(result.meshes,2); + assert.equal(result.vertices,7); + assert.equal(result.triangles,3); + assert.equal(result.groups,1); + assert.equal(result.materials,1); + assert.equal(result.textures,1); + assert.deepEqual(result.size.toArray(),[4,2,1]); + assert.deepEqual(result.warnings,[]); +}); + +test('inspectModel reports geometry and export-review warnings without mutating model',()=>{ + const malformed={isMesh:true,geometry:{attributes:{position:{count:4}},index:{count:4},morphAttributes:{position:[{}]}},material:null,isSkinnedMesh:true}; + const line={isLine:true}; + const root=makeModel([malformed,line]); + const result=inspectModel(root,THREE); + assert.equal(result.triangles,1); + assert.ok(result.warnings.some(value=>value.includes('complete set of triangles'))); + assert.ok(result.warnings.some(value=>value.includes('Morph targets'))); + assert.ok(result.warnings.some(value=>value.includes('Skinned mesh'))); + assert.ok(result.warnings.some(value=>value.includes('Line or point'))); + assert.equal(malformed.geometry.index.count,4); +}); + +test('inspectModel rejects missing model or Three.js bounds support',()=>{ + assert.throws(()=>inspectModel(null,THREE),/model and Three.js/i); + assert.throws(()=>inspectModel(makeModel([]),{}),/model and Three.js/i); +}); diff --git a/tests/orbit-preview.test.js b/tests/orbit-preview.test.js new file mode 100644 index 0000000..8368e4b --- /dev/null +++ b/tests/orbit-preview.test.js @@ -0,0 +1,70 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { OrbitPreview } from '../src/editor/OrbitPreview.js'; + +class Vector3 { + constructor(x=0,y=0,z=0) { Object.assign(this,{x,y,z}); } + clone() { return new Vector3(this.x,this.y,this.z); } + set(x,y,z) { Object.assign(this,{x,y,z}); return this; } + sub(v) { this.x-=v.x; this.y-=v.y; this.z-=v.z; return this; } + add(v) { this.x+=v.x; this.y+=v.y; this.z+=v.z; return this; } + length() { return Math.hypot(this.x,this.y,this.z); } + copy(v) { Object.assign(this,{x:v.x,y:v.y,z:v.z}); return this; } +} +class Box3 { + setFromObject() { return this; } + isEmpty() { return false; } + getCenter(target) { return target.set(0,0,0); } +} +const THREE = { Vector3, Box3 }; +function setup() { + const events = new Map(); + const controls = { + target: new Vector3(), + update() {}, + addEventListener(type, fn) { events.set(type, fn); }, + removeEventListener(type) { events.delete(type); }, + emit(type) { events.get(type)?.(); } + }; + const camera = { position: new Vector3(0,2,10), lookAt() {} }; + const model = { position: new Vector3(4,0,0), updateWorldMatrix() {} }; + const preview = new OrbitPreview({ THREE, camera, controls, getModel: () => model }); + return { preview, camera, controls, model }; +} + +test('OrbitPreview rotates the camera around the model center without changing model transforms', () => { + const { preview, camera, model } = setup(); + const original = model.position.clone(); + assert.equal(preview.start(), true); + const before = camera.position.clone(); + preview.update(0.1); + assert.notDeepEqual(camera.position, before); + assert.deepEqual(model.position, original); + preview.dispose(); +}); + +test('OrbitPreview pauses on manual camera interaction and can resume', () => { + const { preview, controls, camera } = setup(); + assert.equal(preview.start(), true); + controls.emit('start'); + assert.equal(preview.paused, true); + const before = camera.position.clone(); + preview.update(0.1); + assert.deepEqual(camera.position, before); + preview.resume(); + preview.update(0.1); + assert.notDeepEqual(camera.position, before); + preview.stop(); + assert.equal(preview.active, false); +}); + +test('OrbitPreview validates speed and axis', () => { + const { preview } = setup(); + assert.throws(() => preview.setSpeed(0), /between/); + assert.throws(() => preview.setAxis('q'), /axis/); + preview.setSpeed(1.2); + preview.setAxis('x'); + assert.equal(preview.speed, 1.2); + assert.equal(preview.axis, 'x'); + preview.dispose(); +}); diff --git a/tests/scene-commands.test.js b/tests/scene-commands.test.js index b4c35d2..183347c 100644 --- a/tests/scene-commands.test.js +++ b/tests/scene-commands.test.js @@ -8,6 +8,8 @@ import { ReparentObjectCommand, SetTransformCommand, SetVisibilityCommand, + RenameObjectCommand, + SetMaterialPropertiesCommand, } from '../src/core/SceneCommands.js'; function vector(x, y, z, extra = {}) { @@ -214,3 +216,60 @@ test('scene graph rejects cycles and unregistered destination parents', () => { assert.equal(parent.parent, root); assert.equal(child.parent, parent); }); + + +test('rename command is undoable and emits scene change events', () => { + const { object, store, history } = setup(); + const events = []; + store.on('object:changed', (event) => events.push(event.action)); + history.execute(new RenameObjectCommand(store, 'mesh', 'Renamed mesh')); + assert.equal(object.name, 'Renamed mesh'); + history.undo(); + assert.equal(object.name, ''); + history.redo(); + assert.equal(object.name, 'Renamed mesh'); + assert.deepEqual(events, ['rename', 'rename', 'rename']); +}); + +test('rename command rejects blank names and unknown objects', () => { + const { store, history } = setup(); + assert.throws(() => new RenameObjectCommand(store, 'mesh', ' '), /cannot be empty/i); + assert.throws(() => history.execute(new RenameObjectCommand(store, 'missing', 'Name')), /Unknown scene object/); +}); + + +test('material property command restores scalar values, cloned colors and texture references', () => { + const color = { + value: '#ffffff', + clone() { return { value: this.value, copy(other) { this.value = other.value; return this; } }; }, + copy(other) { this.value = other.value; return this; }, + }; + const originalTexture = { id: 'original' }; + const replacementTexture = { id: 'replacement' }; + const material = { color, roughness: 0.8, map: originalTexture, needsUpdate: false }; + const history = new CommandHistory(); + const targetColor = { value: '#ff0000', clone() { return { value: this.value }; } }; + + history.execute(new SetMaterialPropertiesCommand(material, { + color: targetColor, roughness: 0.25, map: replacementTexture, + })); + assert.equal(material.color.value, '#ff0000'); + assert.equal(material.roughness, 0.25); + assert.equal(material.map, replacementTexture); + assert.equal(material.needsUpdate, true); + + history.undo(); + assert.equal(material.color.value, '#ffffff'); + assert.equal(material.roughness, 0.8); + assert.equal(material.map, originalTexture); + + history.redo(); + assert.equal(material.color.value, '#ff0000'); + assert.equal(material.roughness, 0.25); + assert.equal(material.map, replacementTexture); +}); + +test('material property command rejects empty or invalid targets', () => { + assert.throws(() => new SetMaterialPropertiesCommand(null, { roughness: 0.2 }), /material object/i); + assert.throws(() => new SetMaterialPropertiesCommand({}, {}), /at least one material property/i); +}); diff --git a/viewer.html b/viewer.html index 84a39b5..41c9dd5 100644 --- a/viewer.html +++ b/viewer.html @@ -66,6 +66,8 @@ .editor-panel button:focus-visible,.editor-panel input:focus-visible { outline:2px solid #e59b52; outline-offset:2px; } .editor-panel h3 { font-size:11px; color:#a7afbb; margin:14px 0 7px; text-transform:uppercase; letter-spacing:.08em; } .editor-panel button,.editor-panel input { font:inherit; } + .material-texture-row { display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:end; gap:8px; margin:7px 0; } + .material-texture-row button { padding:5px 8px; border:1px solid rgba(255,255,255,.18); border-radius:5px; background:rgba(255,255,255,.07); color:inherit; cursor:pointer; } body.light .editor-panel { background:rgba(249,250,252,.98); color:#222; border-color:rgba(0,0,0,.16); } body.light .editor-panel-header { border-color:rgba(0,0,0,.1); background:rgba(0,0,0,.025); } body.light .editor-panel-close { color:#222; border-color:rgba(0,0,0,.14); background:rgba(0,0,0,.045); } @@ -115,6 +117,35 @@ body.light [data-tooltip]::after { background:#fff; color:#222; border-color:rgba(0,0,0,.14); } @media (max-width:700px) { #workspace-main { top:64px; right:62px; width:min(340px,calc(100vw - 78px)); height:calc(100vh - 88px); max-width:calc(100vw - 70px); } #toolbar { left:8px; top:8px; gap:5px; flex-wrap:wrap; max-width:calc(100vw - 70px); } #toolbar button { padding:7px 9px; font-size:11px; } #scene-panel { right:8px; } } + + /* P1 command mode */ + #command-overlay { position:fixed; inset:0; z-index:120; display:flex; align-items:flex-start; justify-content:center; padding:12vh 16px 16px; background:rgba(0,0,0,.28); pointer-events:auto; } + #command-overlay[hidden] { display:none; } + #command-box { width:min(560px,calc(100vw - 32px)); overflow:hidden; border:1px solid rgba(255,255,255,.18); border-radius:12px; background:rgba(27,29,34,.98); color:#f2f3f5; box-shadow:0 24px 80px rgba(0,0,0,.5); backdrop-filter:blur(18px); } + #command-input { width:100%; height:54px; padding:0 18px; border:0; border-bottom:1px solid rgba(255,255,255,.12); outline:none; background:transparent; color:inherit; font:500 16px/1.2 system-ui,sans-serif; } + #command-results { max-height:min(420px,55vh); overflow:auto; padding:7px; } + .command-result { width:100%; display:flex; align-items:center; justify-content:space-between; gap:16px; padding:11px 12px; border:0; border-radius:7px; background:transparent; color:inherit; text-align:left; cursor:pointer; } + .command-result[aria-selected="true"],.command-result:hover { background:rgba(229,155,82,.16); } + .command-result span { font-size:13px; font-weight:650; letter-spacing:.025em; } + .command-result small { color:#9ca5b2; font-size:11px; } + .command-result.is-disabled { opacity:.38; cursor:not-allowed; } + .command-result.is-disabled small { color:#d39a70; } + .command-empty { padding:18px 12px; color:#9ca5b2; font-size:12px; } + #command-hint { padding:9px 12px; border-top:1px solid rgba(255,255,255,.1); color:#8993a0; font-size:10px; } + body.light #command-box { background:rgba(250,251,253,.99); color:#222; border-color:rgba(0,0,0,.16); } + body.light #command-input { border-color:rgba(0,0,0,.12); } + body.light .command-result[aria-selected="true"],body.light .command-result:hover { background:rgba(170,105,42,.12); } + body.light .command-result small,body.light .command-empty,body.light #command-hint { color:#68717e; } + #orbit-controls { position:fixed; left:50%; bottom:22px; transform:translateX(-50%); z-index:25; display:flex; align-items:center; gap:12px; padding:10px 14px; border:1px solid rgba(255,255,255,.16); border-radius:10px; background:rgba(28,30,34,.94); color:#eee; pointer-events:auto; box-shadow:0 12px 34px rgba(0,0,0,.3); } + #orbit-controls[hidden] { display:none; } + #orbit-controls button { border:1px solid rgba(255,255,255,.18); border-radius:6px; padding:6px 9px; background:rgba(255,255,255,.08); color:inherit; cursor:pointer; } + #orbit-controls label { display:flex; align-items:center; gap:8px; color:#b8c0ca; font-size:11px; } + #orbit-speed { width:100px; accent-color:#e59b52; } + #orbit-status { min-width:52px; color:#9ca5b2; font-size:10px; } + body.light #orbit-controls { background:rgba(250,251,253,.98); color:#222; border-color:rgba(0,0,0,.16); } + body.light #orbit-controls button { color:#222; border-color:rgba(0,0,0,.14); background:rgba(0,0,0,.045); } + @media (max-width:600px) { #orbit-controls { bottom:58px; width:calc(100vw - 90px); justify-content:center; flex-wrap:wrap; } } + /* Light theme override */ body.light { background: #f5f5f5; color: #222; } body.light #loading { background: #f5f5f5; } @@ -134,15 +165,26 @@ - + + + +