@maucwerk/glimmer 0.0.0-stage → 1.0.13
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/LICENSE +43 -0
- package/README.md +884 -2
- package/dist/components/__edge_decorator.d.ts +36 -0
- package/dist/components/conditional_lines/conditional_edges_geometry.d.ts +7 -0
- package/dist/components/conditional_lines/conditional_line_segments_geometry.d.ts +24 -0
- package/dist/components/conditional_lines/outside_edges_geometry.d.ts +7 -0
- package/dist/components/glimmer_viewer.d.ts +9 -0
- package/dist/environment/environment.d.ts +42 -0
- package/dist/environment/index.d.ts +2 -0
- package/dist/environment/sun.d.ts +21 -0
- package/dist/gizmos/index.d.ts +4 -0
- package/dist/gizmos/move_gizmo.d.ts +89 -0
- package/dist/gizmos/rotate_gizmo.d.ts +86 -0
- package/dist/gizmos/section_box_gizmo.d.ts +91 -0
- package/dist/gizmos/section_box_manager.d.ts +82 -0
- package/dist/glimmer.d.ts +26 -0
- package/dist/index.d.ts +13 -0
- package/dist/main.d.ts +1 -0
- package/dist/model/index.d.ts +3 -0
- package/dist/model/model.d.ts +88 -0
- package/dist/model/model_loader.d.ts +9 -0
- package/dist/model/model_manager.d.ts +55 -0
- package/dist/outline/index.d.ts +2 -0
- package/dist/outline/outline_material.d.ts +13 -0
- package/dist/outline/outline_mesh.d.ts +10 -0
- package/dist/section/index.d.ts +3 -0
- package/dist/section/plane_handle.d.ts +39 -0
- package/dist/section/section_box.d.ts +78 -0
- package/dist/section/section_cap.d.ts +15 -0
- package/dist/settings/index.d.ts +2 -0
- package/dist/settings/schema.d.ts +353 -0
- package/dist/settings/settings.d.ts +20 -0
- package/dist/shaders/colored_shadow_material.d.ts +7 -0
- package/dist/shaders/conditional_edges_shader.d.ts +16 -0
- package/dist/shaders/conditional_line_material.d.ts +16 -0
- package/dist/story/anchor_marker.d.ts +74 -0
- package/dist/story/anchor_marker_manager.d.ts +102 -0
- package/dist/story/annotation_2d_renderer.d.ts +24 -0
- package/dist/story/annotation_3d_renderer.d.ts +29 -0
- package/dist/story/annotation_renderer.d.ts +35 -0
- package/dist/story/index.d.ts +7 -0
- package/dist/story/schema.d.ts +1154 -0
- package/dist/story/slide_transition_manager.d.ts +30 -0
- package/dist/story/story_manager.d.ts +170 -0
- package/dist/story/trigger_manager.d.ts +43 -0
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/cursor_3d.d.ts +48 -0
- package/dist/utils/error.d.ts +54 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/log.d.ts +8 -0
- package/dist/utils/utils.d.ts +2 -0
- package/dist/viewer/index.d.ts +1 -0
- package/dist/viewer/orbit_controller.d.ts +62 -0
- package/dist/viewer/raycast_helper.d.ts +37 -0
- package/dist/viewer/viewer.d.ts +141 -0
- package/dist/vite/glimmer.mjs +11522 -0
- package/dist/vite/glimmer.umd.js +914 -0
- package/package.json +64 -4
package/README.md
CHANGED
|
@@ -1,3 +1,885 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Glimmer 3D Viewer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight, interactive 3D model viewer for web applications with full TypeScript support. Drop it into any HTML element and display interactive 3D models with professional lighting and controls.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
✅ **Full TypeScript Support** - Complete type definitions and IntelliSense
|
|
8
|
+
✅ **Multiple Formats** - ESM and CommonJS compatibility
|
|
9
|
+
✅ **Professional Lighting** - HDR environment maps and dynamic sun positioning
|
|
10
|
+
✅ **Interactive Controls** - Built-in orbit controls and model framing
|
|
11
|
+
✅ **Story Mode** - Create guided 3D presentations with slides and annotations
|
|
12
|
+
✅ **Section Box** - Interactive architectural section cutting with 6-axis clipping planes and filled caps
|
|
13
|
+
✅ **Outlines** - Angle-threshold edge outlines with clipping support for technical visualization
|
|
14
|
+
✅ **Transform Gizmos** - Move, rotate, and section-box gizmos for interactive editing
|
|
15
|
+
✅ **Edge Rendering** - Conditional and threshold edge detection for technical visualization
|
|
16
|
+
✅ **Framework Agnostic** - Works with React, Vue, Angular, or vanilla JavaScript
|
|
17
|
+
✅ **Mobile Optimized** - Responsive design with touch controls
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @maucwerk/glimmer
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Basic Implementation
|
|
26
|
+
|
|
27
|
+
### 1. HTML Setup
|
|
28
|
+
|
|
29
|
+
Create a container element in your HTML:
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<!DOCTYPE html>
|
|
33
|
+
<html lang="en">
|
|
34
|
+
<head>
|
|
35
|
+
<meta charset="UTF-8" />
|
|
36
|
+
<title>My 3D Viewer</title>
|
|
37
|
+
</head>
|
|
38
|
+
<body>
|
|
39
|
+
<div id="model-viewer"></div>
|
|
40
|
+
<script type="module" src="main.js"></script>
|
|
41
|
+
</body>
|
|
42
|
+
</html>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. TypeScript/JavaScript Implementation
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { Glimmer } from '@maucwerk/glimmer'
|
|
49
|
+
|
|
50
|
+
// Get your container element
|
|
51
|
+
const container = document.getElementById('model-viewer')!
|
|
52
|
+
|
|
53
|
+
// Create the viewer with your 3D model
|
|
54
|
+
const viewer = new Glimmer(container, {
|
|
55
|
+
models: [
|
|
56
|
+
{
|
|
57
|
+
url: '/path/to/your-model.glb',
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
// Initialize and you're done!
|
|
63
|
+
await viewer.initialize()
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
That's it! Your website now has a fully interactive 3D viewer with complete TypeScript support.
|
|
67
|
+
|
|
68
|
+
## TypeScript Integration
|
|
69
|
+
|
|
70
|
+
### Complete Type Safety
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { Glimmer, type GlimmerSettings, type ModelSettings } from '@maucwerk/glimmer'
|
|
74
|
+
|
|
75
|
+
// Fully typed configuration
|
|
76
|
+
const config: GlimmerSettings = {
|
|
77
|
+
environment: {
|
|
78
|
+
type: 'hdr',
|
|
79
|
+
url: '/studio.hdr',
|
|
80
|
+
transparent: false,
|
|
81
|
+
},
|
|
82
|
+
models: [
|
|
83
|
+
{
|
|
84
|
+
url: '/model.glb',
|
|
85
|
+
color: 0xff0000,
|
|
86
|
+
shadow: true,
|
|
87
|
+
conditional_edges: {
|
|
88
|
+
color: 0x000000,
|
|
89
|
+
line_width: 2,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
] satisfies ModelSettings[],
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const viewer = new Glimmer(container, config)
|
|
96
|
+
await viewer.initialize()
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Available Types
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import type {
|
|
103
|
+
GlimmerSettings,
|
|
104
|
+
ModelSettings,
|
|
105
|
+
EnvironmentSettings,
|
|
106
|
+
SunSettings,
|
|
107
|
+
EdgeSettings,
|
|
108
|
+
Story,
|
|
109
|
+
StorySlide,
|
|
110
|
+
StoryManager,
|
|
111
|
+
SectionBox,
|
|
112
|
+
SectionBoxBounds,
|
|
113
|
+
SectionCapOptions,
|
|
114
|
+
OutlineMesh,
|
|
115
|
+
OutlineMaterial,
|
|
116
|
+
SectionBoxGizmo,
|
|
117
|
+
SectionBoxManager,
|
|
118
|
+
MoveGizmo,
|
|
119
|
+
RotateGizmo,
|
|
120
|
+
} from '@maucwerk/glimmer'
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Integration Examples
|
|
124
|
+
|
|
125
|
+
### React Component
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
import React, { useEffect, useRef } from 'react'
|
|
129
|
+
import { Glimmer } from '@maucwerk/glimmer'
|
|
130
|
+
|
|
131
|
+
interface ModelViewerProps {
|
|
132
|
+
modelUrl: string
|
|
133
|
+
width?: string
|
|
134
|
+
height?: string
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function ModelViewer({ modelUrl, width = '100%', height = '400px' }: ModelViewerProps) {
|
|
138
|
+
const containerRef = useRef<HTMLDivElement>(null)
|
|
139
|
+
const glimmerRef = useRef<Glimmer>()
|
|
140
|
+
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (!containerRef.current) return
|
|
143
|
+
|
|
144
|
+
// Create viewer
|
|
145
|
+
glimmerRef.current = new Glimmer(containerRef.current, {
|
|
146
|
+
models: [{ url: modelUrl }],
|
|
147
|
+
environment: { type: 'sky' },
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
glimmerRef.current.initialize()
|
|
151
|
+
|
|
152
|
+
// Cleanup on unmount
|
|
153
|
+
return () => {
|
|
154
|
+
glimmerRef.current?.dispose()
|
|
155
|
+
}
|
|
156
|
+
}, [modelUrl])
|
|
157
|
+
|
|
158
|
+
return <div ref={containerRef} style={{ width, height }} className="model-viewer" />
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Usage in your React app
|
|
162
|
+
function ProductPage() {
|
|
163
|
+
return (
|
|
164
|
+
<div>
|
|
165
|
+
<h1>Our Latest Product</h1>
|
|
166
|
+
<ModelViewer modelUrl="/products/chair.glb" height="500px" />
|
|
167
|
+
</div>
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Vue Component
|
|
173
|
+
|
|
174
|
+
```vue
|
|
175
|
+
<template>
|
|
176
|
+
<div ref="container" class="model-viewer" :style="{ width, height }" />
|
|
177
|
+
</template>
|
|
178
|
+
|
|
179
|
+
<script setup lang="ts">
|
|
180
|
+
import { ref, onMounted, onUnmounted } from 'vue'
|
|
181
|
+
import { Glimmer } from '@maucwerk/glimmer'
|
|
182
|
+
|
|
183
|
+
interface Props {
|
|
184
|
+
modelUrl: string
|
|
185
|
+
width?: string
|
|
186
|
+
height?: string
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
190
|
+
width: '100%',
|
|
191
|
+
height: '400px',
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
const container = ref<HTMLDivElement>()
|
|
195
|
+
let glimmer: Glimmer
|
|
196
|
+
|
|
197
|
+
onMounted(async () => {
|
|
198
|
+
if (!container.value) return
|
|
199
|
+
|
|
200
|
+
glimmer = new Glimmer(container.value, {
|
|
201
|
+
models: [{ url: props.modelUrl }],
|
|
202
|
+
environment: { type: 'hdr', url: '/lighting.hdr' },
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
await glimmer.initialize()
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
onUnmounted(() => {
|
|
209
|
+
glimmer?.dispose()
|
|
210
|
+
})
|
|
211
|
+
</script>
|
|
212
|
+
|
|
213
|
+
<style scoped>
|
|
214
|
+
.model-viewer {
|
|
215
|
+
border-radius: 8px;
|
|
216
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
217
|
+
}
|
|
218
|
+
</style>
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Vanilla JavaScript (ES6)
|
|
222
|
+
|
|
223
|
+
```html
|
|
224
|
+
<!DOCTYPE html>
|
|
225
|
+
<html>
|
|
226
|
+
<head>
|
|
227
|
+
<style>
|
|
228
|
+
.viewer {
|
|
229
|
+
width: 100%;
|
|
230
|
+
height: 500px;
|
|
231
|
+
border: 1px solid #ddd;
|
|
232
|
+
border-radius: 8px;
|
|
233
|
+
}
|
|
234
|
+
</style>
|
|
235
|
+
</head>
|
|
236
|
+
<body>
|
|
237
|
+
<div id="viewer" class="viewer"></div>
|
|
238
|
+
|
|
239
|
+
<script type="module">
|
|
240
|
+
import { Glimmer } from '@maucwerk/glimmer'
|
|
241
|
+
|
|
242
|
+
const container = document.getElementById('viewer')
|
|
243
|
+
|
|
244
|
+
const glimmer = new Glimmer(container, {
|
|
245
|
+
environment: {
|
|
246
|
+
type: 'sky',
|
|
247
|
+
sun: { intensity: 1.5 },
|
|
248
|
+
},
|
|
249
|
+
models: [
|
|
250
|
+
{
|
|
251
|
+
url: './models/demo.glb',
|
|
252
|
+
shadow: true,
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
glimmer.initialize().then(() => {
|
|
258
|
+
console.log('3D viewer ready!')
|
|
259
|
+
})
|
|
260
|
+
</script>
|
|
261
|
+
</body>
|
|
262
|
+
</html>
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Multiple Models
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
const glimmer = new Glimmer(container, {
|
|
269
|
+
environment: {
|
|
270
|
+
type: 'hdr',
|
|
271
|
+
url: '/studio-lighting.hdr',
|
|
272
|
+
},
|
|
273
|
+
models: [
|
|
274
|
+
{
|
|
275
|
+
url: '/models/chair.glb',
|
|
276
|
+
color: 0x8b4513, // Brown chair
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
url: '/models/table.glb',
|
|
280
|
+
color: 0x654321, // Dark brown table
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
await glimmer.initialize()
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Dynamic Model Loading
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
// Start with empty viewer
|
|
292
|
+
const glimmer = new Glimmer(container)
|
|
293
|
+
await glimmer.initialize()
|
|
294
|
+
|
|
295
|
+
// Load models dynamically based on user selection
|
|
296
|
+
function showProduct(productId) {
|
|
297
|
+
const modelUrl = `/products/${productId}.glb`
|
|
298
|
+
glimmer.model_manager.clear_all()
|
|
299
|
+
glimmer.model_manager.load_model(modelUrl)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Example usage
|
|
303
|
+
document.getElementById('product-1').onclick = () => showProduct('chair')
|
|
304
|
+
document.getElementById('product-2').onclick = () => showProduct('table')
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## StoryManager: Interactive 3D Presentations
|
|
308
|
+
|
|
309
|
+
Create guided 3D tours, architectural walkthroughs, and interactive presentations with the StoryManager. Think PowerPoint but for 3D scenes.
|
|
310
|
+
|
|
311
|
+
### Quick Example
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
import { Glimmer, StoryManager } from '@maucwerk/glimmer'
|
|
315
|
+
|
|
316
|
+
// Initialize Glimmer
|
|
317
|
+
const glimmer = new Glimmer(container, {
|
|
318
|
+
models: [{ url: '/building.glb' }],
|
|
319
|
+
})
|
|
320
|
+
await glimmer.initialize()
|
|
321
|
+
|
|
322
|
+
// Create a story with multiple slides
|
|
323
|
+
const story = {
|
|
324
|
+
title: 'Building Walkthrough',
|
|
325
|
+
description: 'Guided tour of our architectural design',
|
|
326
|
+
slides: [
|
|
327
|
+
{
|
|
328
|
+
title: 'Welcome',
|
|
329
|
+
description: 'Overview of the entire building',
|
|
330
|
+
camera: {
|
|
331
|
+
position: [50, 30, 50],
|
|
332
|
+
target: [0, 0, 0],
|
|
333
|
+
},
|
|
334
|
+
settings: {
|
|
335
|
+
environment: { type: 'sky' },
|
|
336
|
+
},
|
|
337
|
+
annotations: [
|
|
338
|
+
{
|
|
339
|
+
type: '2d',
|
|
340
|
+
position: [50, 50, 0],
|
|
341
|
+
content: '<h2>Welcome!</h2><p>Use arrow keys to navigate</p>',
|
|
342
|
+
},
|
|
343
|
+
],
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
title: 'Main Entrance',
|
|
347
|
+
description: 'Front facade with detail callouts',
|
|
348
|
+
camera: {
|
|
349
|
+
position: [20, 5, 0],
|
|
350
|
+
target: [0, 3, 0],
|
|
351
|
+
},
|
|
352
|
+
settings: {
|
|
353
|
+
environment: {
|
|
354
|
+
type: 'sky',
|
|
355
|
+
sun: { position: [10, 10, 5], intensity: 1.2 },
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
annotations: [
|
|
359
|
+
{
|
|
360
|
+
type: '3d',
|
|
361
|
+
position: [0, 3, 0],
|
|
362
|
+
content: 'Main Entrance',
|
|
363
|
+
},
|
|
364
|
+
],
|
|
365
|
+
},
|
|
366
|
+
],
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// Create StoryManager
|
|
370
|
+
const story_manager = new StoryManager(glimmer, story)
|
|
371
|
+
|
|
372
|
+
// Register navigation controls
|
|
373
|
+
story_manager.register_forward('#next-button')
|
|
374
|
+
story_manager.register_backward('#prev-button')
|
|
375
|
+
story_manager.register_home('#home-button')
|
|
376
|
+
|
|
377
|
+
// Or use keyboard shortcuts
|
|
378
|
+
story_manager.register_forward('ArrowRight')
|
|
379
|
+
story_manager.register_backward('ArrowLeft')
|
|
380
|
+
story_manager.register_home('Home')
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
### Navigation Methods
|
|
384
|
+
|
|
385
|
+
```typescript
|
|
386
|
+
// Programmatic navigation
|
|
387
|
+
story_manager.next() // Go to next slide
|
|
388
|
+
story_manager.prev() // Go to previous slide
|
|
389
|
+
story_manager.home() // Go to first slide
|
|
390
|
+
story_manager.goto(2) // Go to specific slide (0-based)
|
|
391
|
+
|
|
392
|
+
// Get current state
|
|
393
|
+
const current = story_manager.current_slide // Index of current slide
|
|
394
|
+
const total = story_manager.total_slides // Total number of slides
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### Story Events
|
|
398
|
+
|
|
399
|
+
Listen for slide changes to update your UI:
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
window.addEventListener('storySlideChange', (event) => {
|
|
403
|
+
const { current_slide, total_slides, slide } = event.detail
|
|
404
|
+
|
|
405
|
+
// Update UI
|
|
406
|
+
document.getElementById('title').textContent = slide.title
|
|
407
|
+
document.getElementById('description').textContent = slide.description
|
|
408
|
+
document.getElementById('counter').textContent = `${current_slide + 1} / ${total_slides}`
|
|
409
|
+
})
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### Authoring Stories
|
|
413
|
+
|
|
414
|
+
Create stories programmatically by capturing the current view:
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
// User positions camera and adjusts settings
|
|
418
|
+
// Then capture current state as a new slide
|
|
419
|
+
const new_slide = story_manager.capture_current_state('New View', 'Description of this perspective')
|
|
420
|
+
|
|
421
|
+
// Export the entire story as JSON
|
|
422
|
+
const story_json = story_manager.export_story()
|
|
423
|
+
console.log(JSON.stringify(story_json, null, 2))
|
|
424
|
+
|
|
425
|
+
// Save for later use
|
|
426
|
+
localStorage.setItem('my-story', story_json)
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
### Story JSON Format
|
|
430
|
+
|
|
431
|
+
Stories can be loaded from JSON files:
|
|
432
|
+
|
|
433
|
+
```json
|
|
434
|
+
{
|
|
435
|
+
"title": "Architecture Walkthrough",
|
|
436
|
+
"description": "A guided tour of the building",
|
|
437
|
+
"slides": [
|
|
438
|
+
{
|
|
439
|
+
"id": "slide-1",
|
|
440
|
+
"title": "Slide Title",
|
|
441
|
+
"description": "Slide description",
|
|
442
|
+
"camera": {
|
|
443
|
+
"position": [x, y, z],
|
|
444
|
+
"target": [x, y, z]
|
|
445
|
+
},
|
|
446
|
+
"settings": {
|
|
447
|
+
"environment": {
|
|
448
|
+
"type": "sky",
|
|
449
|
+
"transparent": false,
|
|
450
|
+
"sun": {
|
|
451
|
+
"position": [x, y, z],
|
|
452
|
+
"intensity": 1.0,
|
|
453
|
+
"color": 16777215,
|
|
454
|
+
"shadow": false
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
"annotations": [
|
|
459
|
+
{
|
|
460
|
+
"type": "2d",
|
|
461
|
+
"position": [x, y, 0],
|
|
462
|
+
"content": "<h3>HTML Content</h3>"
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
"type": "3d",
|
|
466
|
+
"position": [x, y, z],
|
|
467
|
+
"content": "Label Text"
|
|
468
|
+
}
|
|
469
|
+
]
|
|
470
|
+
}
|
|
471
|
+
]
|
|
472
|
+
}
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
Load from JSON:
|
|
476
|
+
|
|
477
|
+
```typescript
|
|
478
|
+
const response = await fetch('/stories/walkthrough.json')
|
|
479
|
+
const story_data = await response.json()
|
|
480
|
+
const story_manager = new StoryManager(glimmer, story_data)
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
### Annotation Types
|
|
484
|
+
|
|
485
|
+
**2D Annotations** - HTML overlays positioned on screen:
|
|
486
|
+
|
|
487
|
+
```typescript
|
|
488
|
+
{
|
|
489
|
+
type: '2d',
|
|
490
|
+
position: [50, 80, 0], // x%, y% from top-left, z unused (set to 0)
|
|
491
|
+
content: '<p><strong>Title</strong><br/>Description</p>'
|
|
492
|
+
}
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
**3D Annotations** - Sprite labels positioned in 3D space:
|
|
496
|
+
|
|
497
|
+
```typescript
|
|
498
|
+
{
|
|
499
|
+
type: '3d',
|
|
500
|
+
position: [10, 5, 0], // x, y, z in world coordinates
|
|
501
|
+
content: 'Point of Interest'
|
|
502
|
+
}
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
### Example: Architecture Presentation
|
|
506
|
+
|
|
507
|
+
See `examples/story-demo.html` for a complete working example with:
|
|
508
|
+
|
|
509
|
+
- Navigation UI with buttons and keyboard shortcuts
|
|
510
|
+
- Slide counter and title display
|
|
511
|
+
- Styled 2D and 3D annotations
|
|
512
|
+
- Responsive layout
|
|
513
|
+
|
|
514
|
+
### Cleanup
|
|
515
|
+
|
|
516
|
+
```typescript
|
|
517
|
+
// Dispose StoryManager when done
|
|
518
|
+
story_manager.dispose()
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
## Configuration for Common Scenarios
|
|
522
|
+
|
|
523
|
+
### E-commerce Product Display
|
|
524
|
+
|
|
525
|
+
```typescript
|
|
526
|
+
const glimmer = new Glimmer(container, {
|
|
527
|
+
environment: {
|
|
528
|
+
type: 'hdr',
|
|
529
|
+
url: '/assets/studio.hdr', // Professional product lighting
|
|
530
|
+
transparent: false,
|
|
531
|
+
},
|
|
532
|
+
models: [
|
|
533
|
+
{
|
|
534
|
+
url: '/products/item.glb',
|
|
535
|
+
shadow: true,
|
|
536
|
+
color: 0xffffff, // Let original materials show
|
|
537
|
+
},
|
|
538
|
+
],
|
|
539
|
+
})
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
### Architectural Visualization
|
|
543
|
+
|
|
544
|
+
```typescript
|
|
545
|
+
const glimmer = new Glimmer(container, {
|
|
546
|
+
environment: {
|
|
547
|
+
type: 'sky',
|
|
548
|
+
sun: {
|
|
549
|
+
intensity: 2.0,
|
|
550
|
+
position: [100, 100, 50], // Natural daylight
|
|
551
|
+
shadow: true,
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
models: [
|
|
555
|
+
{
|
|
556
|
+
url: '/buildings/house.glb',
|
|
557
|
+
threshold_edges: {
|
|
558
|
+
color: 0x333333, // Architectural edge lines
|
|
559
|
+
threshold_angle: 30,
|
|
560
|
+
line_width: 1,
|
|
561
|
+
},
|
|
562
|
+
},
|
|
563
|
+
],
|
|
564
|
+
})
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
### Technical Documentation
|
|
568
|
+
|
|
569
|
+
```typescript
|
|
570
|
+
const glimmer = new Glimmer(container, {
|
|
571
|
+
environment: {
|
|
572
|
+
type: 'none',
|
|
573
|
+
transparent: true, // Clean background
|
|
574
|
+
background_color: 0xffffff,
|
|
575
|
+
},
|
|
576
|
+
models: [
|
|
577
|
+
{
|
|
578
|
+
url: '/technical/part.glb',
|
|
579
|
+
conditional_edges: {
|
|
580
|
+
color: 0x000000, // Technical drawing style
|
|
581
|
+
line_width: 2,
|
|
582
|
+
threshold_angle: 1,
|
|
583
|
+
},
|
|
584
|
+
},
|
|
585
|
+
],
|
|
586
|
+
})
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
## Styling and Layout
|
|
590
|
+
|
|
591
|
+
### CSS Styling
|
|
592
|
+
|
|
593
|
+
```css
|
|
594
|
+
.model-viewer {
|
|
595
|
+
width: 100%;
|
|
596
|
+
height: 400px;
|
|
597
|
+
border-radius: 12px;
|
|
598
|
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
|
|
599
|
+
overflow: hidden;
|
|
600
|
+
background: #f5f5f5;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/* Responsive sizing */
|
|
604
|
+
@media (max-width: 768px) {
|
|
605
|
+
.model-viewer {
|
|
606
|
+
height: 300px;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/* Full screen viewer */
|
|
611
|
+
.fullscreen-viewer {
|
|
612
|
+
position: fixed;
|
|
613
|
+
top: 0;
|
|
614
|
+
left: 0;
|
|
615
|
+
width: 100vw;
|
|
616
|
+
height: 100vh;
|
|
617
|
+
z-index: 1000;
|
|
618
|
+
}
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
### Grid Layout Integration
|
|
622
|
+
|
|
623
|
+
```html
|
|
624
|
+
<div class="product-grid">
|
|
625
|
+
<div class="product-info">
|
|
626
|
+
<h2>Product Name</h2>
|
|
627
|
+
<p>Description...</p>
|
|
628
|
+
<button>Add to Cart</button>
|
|
629
|
+
</div>
|
|
630
|
+
|
|
631
|
+
<div class="model-viewer-container">
|
|
632
|
+
<div id="viewer"></div>
|
|
633
|
+
</div>
|
|
634
|
+
</div>
|
|
635
|
+
|
|
636
|
+
<style>
|
|
637
|
+
.product-grid {
|
|
638
|
+
display: grid;
|
|
639
|
+
grid-template-columns: 1fr 1fr;
|
|
640
|
+
gap: 2rem;
|
|
641
|
+
align-items: center;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
@media (max-width: 768px) {
|
|
645
|
+
.product-grid {
|
|
646
|
+
grid-template-columns: 1fr;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
</style>
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
## User Interaction
|
|
653
|
+
|
|
654
|
+
### Custom Controls
|
|
655
|
+
|
|
656
|
+
```typescript
|
|
657
|
+
const glimmer = new Glimmer(container, {
|
|
658
|
+
models: [{ url: '/model.glb' }],
|
|
659
|
+
})
|
|
660
|
+
|
|
661
|
+
await glimmer.initialize()
|
|
662
|
+
|
|
663
|
+
// Add custom buttons
|
|
664
|
+
document.getElementById('zoom-in').onclick = () => {
|
|
665
|
+
// Glimmer uses OrbitControls - zoom programmatically
|
|
666
|
+
glimmer.viewer.controls.dollyIn(1.2)
|
|
667
|
+
glimmer.viewer.controls.update()
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
document.getElementById('reset-view').onclick = () => {
|
|
671
|
+
glimmer.viewer.frame_model() // Reset to default view
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
document.getElementById('animate').onclick = () => {
|
|
675
|
+
glimmer.viewer.animate_orbit(true) // Start rotation
|
|
676
|
+
}
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
### Loading States
|
|
680
|
+
|
|
681
|
+
```typescript
|
|
682
|
+
// Show loading indicator
|
|
683
|
+
const loadingDiv = document.getElementById('loading')
|
|
684
|
+
loadingDiv.style.display = 'block'
|
|
685
|
+
|
|
686
|
+
try {
|
|
687
|
+
const glimmer = new Glimmer(container, {
|
|
688
|
+
models: [{ url: '/large-model.glb' }],
|
|
689
|
+
})
|
|
690
|
+
|
|
691
|
+
await glimmer.initialize()
|
|
692
|
+
loadingDiv.style.display = 'none'
|
|
693
|
+
} catch (error) {
|
|
694
|
+
loadingDiv.innerHTML = 'Error loading 3D model'
|
|
695
|
+
console.error('Failed to load model:', error)
|
|
696
|
+
}
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
## Performance Tips
|
|
700
|
+
|
|
701
|
+
### Optimize for Mobile
|
|
702
|
+
|
|
703
|
+
```typescript
|
|
704
|
+
const glimmer = new Glimmer(container, {
|
|
705
|
+
environment: {
|
|
706
|
+
type: 'color', // Simpler than HDR on mobile
|
|
707
|
+
background_color: 0xf0f0f0,
|
|
708
|
+
},
|
|
709
|
+
models: [
|
|
710
|
+
{
|
|
711
|
+
url: '/models/optimized.glb', // Use lower-poly models
|
|
712
|
+
shadow: window.innerWidth > 768, // Disable shadows on mobile
|
|
713
|
+
},
|
|
714
|
+
],
|
|
715
|
+
})
|
|
716
|
+
```
|
|
717
|
+
|
|
718
|
+
### Memory Management
|
|
719
|
+
|
|
720
|
+
```typescript
|
|
721
|
+
// Clean up when navigating away or hiding viewer
|
|
722
|
+
window.addEventListener('beforeunload', () => {
|
|
723
|
+
glimmer.dispose()
|
|
724
|
+
})
|
|
725
|
+
|
|
726
|
+
// Or for Single Page Applications
|
|
727
|
+
function hideViewer() {
|
|
728
|
+
glimmer.dispose()
|
|
729
|
+
glimmer = null
|
|
730
|
+
}
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
## File Preparation
|
|
734
|
+
|
|
735
|
+
### Supported Formats
|
|
736
|
+
|
|
737
|
+
- **glTF 2.0** (.glb recommended) - Best performance and compatibility
|
|
738
|
+
- **HDR** environment maps for professional lighting
|
|
739
|
+
|
|
740
|
+
### Optimization Tips
|
|
741
|
+
|
|
742
|
+
- Keep models under 10MB for web performance
|
|
743
|
+
- Use glTF 2.0 binary format (.glb) for fastest loading
|
|
744
|
+
- Optimize textures (1024px max recommended for web)
|
|
745
|
+
- Use Draco compression when possible
|
|
746
|
+
- Test on mobile devices for performance validation
|
|
747
|
+
|
|
748
|
+
## Browser Support
|
|
749
|
+
|
|
750
|
+
- **Chrome 80+** ✅ Full support
|
|
751
|
+
- **Firefox 75+** ✅ Full support
|
|
752
|
+
- **Safari 13+** ✅ Full support
|
|
753
|
+
- **Edge 80+** ✅ Full support
|
|
754
|
+
- **Mobile browsers** ✅ Touch controls included
|
|
755
|
+
|
|
756
|
+
_Requires WebGL 2.0 support_
|
|
757
|
+
|
|
758
|
+
## Troubleshooting
|
|
759
|
+
|
|
760
|
+
### Model Not Loading
|
|
761
|
+
|
|
762
|
+
```typescript
|
|
763
|
+
// Check if model URL is accessible
|
|
764
|
+
try {
|
|
765
|
+
const response = await fetch('/path/to/model.glb')
|
|
766
|
+
if (!response.ok) {
|
|
767
|
+
console.error('Model file not found:', response.status)
|
|
768
|
+
}
|
|
769
|
+
} catch (error) {
|
|
770
|
+
console.error('Network error:', error)
|
|
771
|
+
}
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
### TypeScript Errors
|
|
775
|
+
|
|
776
|
+
Ensure you have the correct import paths:
|
|
777
|
+
|
|
778
|
+
```typescript
|
|
779
|
+
// ✅ Correct
|
|
780
|
+
import { Glimmer } from '@maucwerk/glimmer'
|
|
781
|
+
|
|
782
|
+
// ❌ Incorrect
|
|
783
|
+
import { Glimmer } from '@maucwerk/glimmer/dist/index.js'
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
### CORS Issues
|
|
787
|
+
|
|
788
|
+
Ensure your 3D models are served from the same domain or with proper CORS headers:
|
|
789
|
+
|
|
790
|
+
```
|
|
791
|
+
Access-Control-Allow-Origin: *
|
|
792
|
+
Access-Control-Allow-Methods: GET
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
### Performance Issues
|
|
796
|
+
|
|
797
|
+
- Reduce model complexity and polygon count
|
|
798
|
+
- Disable shadows on mobile devices
|
|
799
|
+
- Use simpler lighting (type: 'color' instead of 'hdr')
|
|
800
|
+
- Consider model optimization tools like gltfpack
|
|
801
|
+
|
|
802
|
+
## Package Structure
|
|
803
|
+
|
|
804
|
+
```
|
|
805
|
+
@maucwerk/glimmer@1.0.13
|
|
806
|
+
├── dist/
|
|
807
|
+
│ ├── index.d.ts # Main TypeScript declarations
|
|
808
|
+
│ ├── vite/
|
|
809
|
+
│ │ ├── glimmer.mjs # ESM build
|
|
810
|
+
│ │ └── glimmer.umd.js # CommonJS/UMD build
|
|
811
|
+
│ └── **/*.d.ts # Complete type definitions
|
|
812
|
+
├── LICENSE
|
|
813
|
+
└── README.md
|
|
814
|
+
```
|
|
815
|
+
|
|
816
|
+
The package supports both ESM and CommonJS with complete TypeScript declarations.
|
|
817
|
+
|
|
818
|
+
## Version History
|
|
819
|
+
|
|
820
|
+
### v1.0.13 (Current)
|
|
821
|
+
|
|
822
|
+
- ✅ **Renamed to `@maucwerk/glimmer`** - new npm scope under the maucwerk org
|
|
823
|
+
- ✅ Clipping-plane section box, outlines, gizmos (see v1.0.12)
|
|
824
|
+
- ✅ GitHub-based release workflow (build, test, type-check, publish)
|
|
825
|
+
|
|
826
|
+
### v1.0.12
|
|
827
|
+
|
|
828
|
+
- ✅ **Section Box (clipping planes)** - Live 6-plane clipping with earcut-filled section caps
|
|
829
|
+
- ✅ **Outline** - Angle-threshold outlines (`OutlineMesh` / `OutlineMaterial`) with clipping support
|
|
830
|
+
- ✅ **Gizmos** - `SectionBoxGizmo`, `SectionBoxManager`, `MoveGizmo`, `RotateGizmo` public API
|
|
831
|
+
- ✅ Removed `CSGSectionOperator` and `three-bvh-csg` / `three-mesh-bvh` dependencies
|
|
832
|
+
- ✅ Comprehensive test suite (200 tests passing)
|
|
833
|
+
- ✅ Complete TypeScript support with full type definitions
|
|
834
|
+
- ✅ Dual package format (ESM + CommonJS)
|
|
835
|
+
|
|
836
|
+
### v1.0.10
|
|
837
|
+
|
|
838
|
+
- ✅ **StoryManager** - Interactive 3D presentations with slides and annotations
|
|
839
|
+
- ✅ Comprehensive test suite (107 tests passing)
|
|
840
|
+
- ✅ Story authoring tools (capture, export, import)
|
|
841
|
+
- ✅ 2D HTML and 3D sprite annotations
|
|
842
|
+
- ✅ Complete TypeScript support with full type definitions
|
|
843
|
+
- ✅ Dual package format (ESM + CommonJS)
|
|
844
|
+
|
|
845
|
+
### v1.0.8
|
|
846
|
+
|
|
847
|
+
- ✅ Complete TypeScript support with full type definitions
|
|
848
|
+
- ✅ Dual package format (ESM + CommonJS)
|
|
849
|
+
- ✅ Comprehensive test suite (48 tests)
|
|
850
|
+
- ✅ Improved build process and development workflow
|
|
851
|
+
- ✅ Enhanced documentation and examples
|
|
852
|
+
|
|
853
|
+
_Note: Public repository and examples will be available when the package is published to npm._
|
|
854
|
+
|
|
855
|
+
## License & Legal
|
|
856
|
+
|
|
857
|
+
### MIT License
|
|
858
|
+
|
|
859
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
860
|
+
|
|
861
|
+
### Disclaimers
|
|
862
|
+
|
|
863
|
+
**Third-Party Dependencies:** This software uses Three.js and other open-source libraries. Users are responsible for compliance with all dependency licenses.
|
|
864
|
+
|
|
865
|
+
**Asset Rights:** Users must ensure they have proper rights to any 3D models, textures, or environment maps used with this library. The example assets in this repository are for demonstration only.
|
|
866
|
+
|
|
867
|
+
**Browser Compatibility:** While we support modern browsers, WebGL performance and compatibility vary across devices. Test thoroughly on your target platforms.
|
|
868
|
+
|
|
869
|
+
**Performance:** 3D rendering performance depends on device capabilities, model complexity, and browser implementation. No performance guarantees are provided.
|
|
870
|
+
|
|
871
|
+
**Production Use:** This library may be used in production, but users assume all responsibility for testing and validation in their specific environments.
|
|
872
|
+
|
|
873
|
+
### Contributing
|
|
874
|
+
|
|
875
|
+
1. Fork the repository
|
|
876
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
877
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
878
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
879
|
+
5. Open a Pull Request
|
|
880
|
+
|
|
881
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
|
|
882
|
+
|
|
883
|
+
---
|
|
884
|
+
|
|
885
|
+
**Ready to add 3D to your website? Start with the basic example above!**
|