lunchboxjs 0.1.4002 → 0.1.4006

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.
@@ -0,0 +1,175 @@
1
+ // list of all components to register out of the box
2
+ export const autoGeneratedComponents = [
3
+ // ThreeJS basics
4
+ 'mesh',
5
+ 'instancedMesh',
6
+ 'scene',
7
+ 'sprite',
8
+ 'object3D',
9
+
10
+ // geometry
11
+ 'instancedBufferGeometry',
12
+ 'bufferGeometry',
13
+ 'boxBufferGeometry',
14
+ 'circleBufferGeometry',
15
+ 'coneBufferGeometry',
16
+ 'cylinderBufferGeometry',
17
+ 'dodecahedronBufferGeometry',
18
+ 'extrudeBufferGeometry',
19
+ 'icosahedronBufferGeometry',
20
+ 'latheBufferGeometry',
21
+ 'octahedronBufferGeometry',
22
+ 'parametricBufferGeometry',
23
+ 'planeBufferGeometry',
24
+ 'polyhedronBufferGeometry',
25
+ 'ringBufferGeometry',
26
+ 'shapeBufferGeometry',
27
+ 'sphereBufferGeometry',
28
+ 'tetrahedronBufferGeometry',
29
+ 'textBufferGeometry',
30
+ 'torusBufferGeometry',
31
+ 'torusKnotBufferGeometry',
32
+ 'tubeBufferGeometry',
33
+ 'wireframeGeometry',
34
+ 'parametricGeometry',
35
+ 'tetrahedronGeometry',
36
+ 'octahedronGeometry',
37
+ 'icosahedronGeometry',
38
+ 'dodecahedronGeometry',
39
+ 'polyhedronGeometry',
40
+ 'tubeGeometry',
41
+ 'torusKnotGeometry',
42
+ 'torusGeometry',
43
+ // textgeometry has been moved to /examples/jsm/geometries/TextGeometry
44
+ // 'textGeometry',
45
+ 'sphereGeometry',
46
+ 'ringGeometry',
47
+ 'planeGeometry',
48
+ 'latheGeometry',
49
+ 'shapeGeometry',
50
+ 'extrudeGeometry',
51
+ 'edgesGeometry',
52
+ 'coneGeometry',
53
+ 'cylinderGeometry',
54
+ 'circleGeometry',
55
+ 'boxGeometry',
56
+
57
+ // materials
58
+ 'material',
59
+ 'shadowMaterial',
60
+ 'spriteMaterial',
61
+ 'rawShaderMaterial',
62
+ 'shaderMaterial',
63
+ 'pointsMaterial',
64
+ 'meshPhysicalMaterial',
65
+ 'meshStandardMaterial',
66
+ 'meshPhongMaterial',
67
+ 'meshToonMaterial',
68
+ 'meshNormalMaterial',
69
+ 'meshLambertMaterial',
70
+ 'meshDepthMaterial',
71
+ 'meshDistanceMaterial',
72
+ 'meshBasicMaterial',
73
+ 'meshMatcapMaterial',
74
+ 'lineDashedMaterial',
75
+ 'lineBasicMaterial',
76
+
77
+ // lights
78
+ 'light',
79
+ 'spotLightShadow',
80
+ 'spotLight',
81
+ 'pointLight',
82
+ 'rectAreaLight',
83
+ 'hemisphereLight',
84
+ 'directionalLightShadow',
85
+ 'directionalLight',
86
+ 'ambientLight',
87
+ 'lightShadow',
88
+ 'ambientLightProbe',
89
+ 'hemisphereLightProbe',
90
+ 'lightProbe',
91
+
92
+ // textures
93
+ 'texture',
94
+ 'videoTexture',
95
+ 'dataTexture',
96
+ 'dataTexture3D',
97
+ 'compressedTexture',
98
+ 'cubeTexture',
99
+ 'canvasTexture',
100
+ 'depthTexture',
101
+
102
+ // Texture loaders
103
+ 'textureLoader',
104
+
105
+ // misc
106
+ 'group',
107
+ 'catmullRomCurve3',
108
+ 'points',
109
+
110
+ // helpers
111
+ 'cameraHelper',
112
+
113
+ // cameras
114
+ 'camera',
115
+ 'perspectiveCamera',
116
+ 'orthographicCamera',
117
+ 'cubeCamera',
118
+ 'arrayCamera',
119
+
120
+ // renderers
121
+ 'webGLRenderer',
122
+
123
+ /*
124
+ // List copied from r3f:
125
+ // https://github.com/pmndrs/react-three-fiber/blob/master/packages/fiber/src/three-types.ts
126
+
127
+ // NOT IMPLEMENTED (can be added via Extend - docs.lunchboxjs.com/components/extend/):
128
+ audioListener: AudioListenerProps
129
+ positionalAudio: PositionalAudioProps
130
+
131
+ lOD: LODProps
132
+ skinnedMesh: SkinnedMeshProps
133
+ skeleton: SkeletonProps
134
+ bone: BoneProps
135
+ lineSegments: LineSegmentsProps
136
+ lineLoop: LineLoopProps
137
+ // see `audio`
138
+ // line: LineProps
139
+ immediateRenderObject: ImmediateRenderObjectProps
140
+
141
+ // primitive
142
+ primitive: PrimitiveProps
143
+
144
+ // helpers
145
+ spotLightHelper: SpotLightHelperProps
146
+ skeletonHelper: SkeletonHelperProps
147
+ pointLightHelper: PointLightHelperProps
148
+ hemisphereLightHelper: HemisphereLightHelperProps
149
+ gridHelper: GridHelperProps
150
+ polarGridHelper: PolarGridHelperProps
151
+ directionalLightHelper: DirectionalLightHelperProps
152
+ boxHelper: BoxHelperProps
153
+ box3Helper: Box3HelperProps
154
+ planeHelper: PlaneHelperProps
155
+ arrowHelper: ArrowHelperProps
156
+ axesHelper: AxesHelperProps
157
+
158
+
159
+ // misc
160
+ raycaster: RaycasterProps
161
+ vector2: Vector2Props
162
+ vector3: Vector3Props
163
+ vector4: Vector4Props
164
+ euler: EulerProps
165
+ matrix3: Matrix3Props
166
+ matrix4: Matrix4Props
167
+ quaternion: QuaternionProps
168
+ bufferAttribute: BufferAttributeProps
169
+ instancedBufferAttribute: InstancedBufferAttributeProps
170
+ color: ColorProps
171
+ fog: FogProps
172
+ fogExp2: FogExp2Props
173
+ shape: ShapeProps
174
+ */
175
+ ]
@@ -1,16 +1,11 @@
1
1
  import { h, defineComponent } from 'vue'
2
- // import Gltf from './Gltf'
3
- // import { Lunchbox } from '../types'
4
2
  import { LunchboxWrapper } from './LunchboxWrapper/LunchboxWrapper'
3
+ import { autoGeneratedComponents } from './autoGeneratedComponents'
5
4
 
6
5
  import { catalogue } from './catalogue'
7
6
  export { catalogue }
8
7
 
9
- export const lunchboxDomComponentNames = [
10
- 'canvas',
11
- 'div',
12
- 'LunchboxWrapper',
13
- ]
8
+ export const lunchboxDomComponentNames = ['canvas', 'div', 'LunchboxWrapper']
14
9
 
15
10
  // component creation utility
16
11
  const createComponent = (tag: string) =>
@@ -22,190 +17,12 @@ const createComponent = (tag: string) =>
22
17
  },
23
18
  })
24
19
 
25
- // list of all components to register out of the box
26
- const autoGeneratedComponents = [
27
-
28
- // ThreeJS basics
29
- 'mesh',
30
- 'instancedMesh',
31
- 'scene',
32
- 'sprite',
33
- 'object3D',
34
-
35
- // geometry
36
- 'instancedBufferGeometry',
37
- 'bufferGeometry',
38
- 'boxBufferGeometry',
39
- 'circleBufferGeometry',
40
- 'coneBufferGeometry',
41
- 'cylinderBufferGeometry',
42
- 'dodecahedronBufferGeometry',
43
- 'extrudeBufferGeometry',
44
- 'icosahedronBufferGeometry',
45
- 'latheBufferGeometry',
46
- 'octahedronBufferGeometry',
47
- 'parametricBufferGeometry',
48
- 'planeBufferGeometry',
49
- 'polyhedronBufferGeometry',
50
- 'ringBufferGeometry',
51
- 'shapeBufferGeometry',
52
- 'sphereBufferGeometry',
53
- 'tetrahedronBufferGeometry',
54
- 'textBufferGeometry',
55
- 'torusBufferGeometry',
56
- 'torusKnotBufferGeometry',
57
- 'tubeBufferGeometry',
58
- 'wireframeGeometry',
59
- 'parametricGeometry',
60
- 'tetrahedronGeometry',
61
- 'octahedronGeometry',
62
- 'icosahedronGeometry',
63
- 'dodecahedronGeometry',
64
- 'polyhedronGeometry',
65
- 'tubeGeometry',
66
- 'torusKnotGeometry',
67
- 'torusGeometry',
68
- // textgeometry has been moved to /examples/jsm/geometries/TextGeometry
69
- // 'textGeometry',
70
- 'sphereGeometry',
71
- 'ringGeometry',
72
- 'planeGeometry',
73
- 'latheGeometry',
74
- 'shapeGeometry',
75
- 'extrudeGeometry',
76
- 'edgesGeometry',
77
- 'coneGeometry',
78
- 'cylinderGeometry',
79
- 'circleGeometry',
80
- 'boxGeometry',
81
-
82
- // materials
83
- 'material',
84
- 'shadowMaterial',
85
- 'spriteMaterial',
86
- 'rawShaderMaterial',
87
- 'shaderMaterial',
88
- 'pointsMaterial',
89
- 'meshPhysicalMaterial',
90
- 'meshStandardMaterial',
91
- 'meshPhongMaterial',
92
- 'meshToonMaterial',
93
- 'meshNormalMaterial',
94
- 'meshLambertMaterial',
95
- 'meshDepthMaterial',
96
- 'meshDistanceMaterial',
97
- 'meshBasicMaterial',
98
- 'meshMatcapMaterial',
99
- 'lineDashedMaterial',
100
- 'lineBasicMaterial',
101
-
102
- // lights
103
- 'light',
104
- 'spotLightShadow',
105
- 'spotLight',
106
- 'pointLight',
107
- 'rectAreaLight',
108
- 'hemisphereLight',
109
- 'directionalLightShadow',
110
- 'directionalLight',
111
- 'ambientLight',
112
- 'lightShadow',
113
- 'ambientLightProbe',
114
- 'hemisphereLightProbe',
115
- 'lightProbe',
116
-
117
- // textures
118
- 'texture',
119
- 'videoTexture',
120
- 'dataTexture',
121
- 'dataTexture3D',
122
- 'compressedTexture',
123
- 'cubeTexture',
124
- 'canvasTexture',
125
- 'depthTexture',
126
-
127
- // Texture loaders
128
- 'textureLoader',
129
-
130
- // misc
131
- 'group',
132
- 'catmullRomCurve3',
133
- 'points',
134
-
135
- // helpers
136
- 'cameraHelper',
137
-
138
- // cameras
139
- 'camera',
140
- 'perspectiveCamera',
141
- 'orthographicCamera',
142
- 'cubeCamera',
143
- 'arrayCamera',
144
-
145
- // renderers
146
- 'webGLRenderer',
147
- ].map(createComponent).reduce((acc, curr) => {
148
- ; (acc as any)[curr.name] = curr
20
+ autoGeneratedComponents.map(createComponent).reduce((acc, curr) => {
21
+ ;(acc as any)[curr.name] = curr
149
22
  return acc
150
23
  })
151
24
 
152
25
  export const components = {
153
26
  ...autoGeneratedComponents,
154
- 'Lunchbox': LunchboxWrapper,
155
- // Gltf,
27
+ Lunchbox: LunchboxWrapper,
156
28
  }
157
-
158
- // console.log(components, Gltf)
159
-
160
- /*
161
- // List copied from r3f
162
- // https://github.com/pmndrs/react-three-fiber/blob/master/packages/fiber/src/three-types.ts
163
-
164
- // NOT IMPLEMENTED:
165
- audioListener: AudioListenerProps
166
- positionalAudio: PositionalAudioProps
167
-
168
- lOD: LODProps
169
- skinnedMesh: SkinnedMeshProps
170
- skeleton: SkeletonProps
171
- bone: BoneProps
172
- lineSegments: LineSegmentsProps
173
- lineLoop: LineLoopProps
174
- // see `audio`
175
- // line: LineProps
176
- immediateRenderObject: ImmediateRenderObjectProps
177
-
178
- // primitive
179
- primitive: PrimitiveProps
180
-
181
- // helpers
182
- spotLightHelper: SpotLightHelperProps
183
- skeletonHelper: SkeletonHelperProps
184
- pointLightHelper: PointLightHelperProps
185
- hemisphereLightHelper: HemisphereLightHelperProps
186
- gridHelper: GridHelperProps
187
- polarGridHelper: PolarGridHelperProps
188
- directionalLightHelper: DirectionalLightHelperProps
189
- boxHelper: BoxHelperProps
190
- box3Helper: Box3HelperProps
191
- planeHelper: PlaneHelperProps
192
- arrowHelper: ArrowHelperProps
193
- axesHelper: AxesHelperProps
194
-
195
-
196
- // misc
197
- raycaster: RaycasterProps
198
- vector2: Vector2Props
199
- vector3: Vector3Props
200
- vector4: Vector4Props
201
- euler: EulerProps
202
- matrix3: Matrix3Props
203
- matrix4: Matrix4Props
204
- quaternion: QuaternionProps
205
- bufferAttribute: BufferAttributeProps
206
- instancedBufferAttribute: InstancedBufferAttributeProps
207
- color: ColorProps
208
- fog: FogProps
209
- fogExp2: FogExp2Props
210
- shape: ShapeProps
211
- */
@@ -127,13 +127,35 @@ function buildEnsured<T extends THREE.Object3D>(
127
127
  // ENSURE CAMERA
128
128
  // ====================
129
129
  export const fallbackCameraUuid = 'FALLBACK_CAMERA'
130
- export const ensuredCamera = buildEnsured<THREE.Camera>(
130
+ export const defaultCamera = buildEnsured(
131
131
  ['PerspectiveCamera', 'OrthographicCamera'],
132
132
  fallbackCameraUuid,
133
- {
134
- args: [45, 0.5625, 1, 1000],
135
- }
136
- )
133
+ { args: [45, 0.5625, 1, 1000] }
134
+ ) as unknown as WritableComputedRef<Lunch.Node<THREE.Camera>>
135
+ /** Special value to be changed ONLY in `LunchboxWrapper`.
136
+ * Functions waiting for a Camera need to wait for this to be true. */
137
+ export const cameraReady = ref(false)
138
+
139
+ export const ensuredCamera = computed<Lunch.Node<THREE.Camera> | null>({
140
+ get() {
141
+ return (
142
+ cameraReady.value ? (defaultCamera.value as any) : (null as any)
143
+ ) as any
144
+ },
145
+ set(val: any) {
146
+ const t = val.type ?? ''
147
+ const pascalType = t[0].toUpperCase() + t.slice(1)
148
+ overrides[pascalType] = val as any
149
+ },
150
+ })
151
+
152
+ // export const ensuredCamera = buildEnsured<THREE.Camera>(
153
+ // ['PerspectiveCamera', 'OrthographicCamera'],
154
+ // fallbackCameraUuid,
155
+ // {
156
+ // args: [45, 0.5625, 1, 1000],
157
+ // }
158
+ // )
137
159
 
138
160
  // ENSURE RENDERER
139
161
  // ====================
@@ -53,6 +53,7 @@ export function addEventListener({
53
53
  const stop = watch(
54
54
  () => inputActive.value,
55
55
  (isDown) => {
56
+ console.log(isDown, currentIntersections)
56
57
  const idx = currentIntersections
57
58
  .map((v) => v.element)
58
59
  .findIndex(
@@ -7,21 +7,18 @@ let frameID: number
7
7
  export const beforeRender = [] as Lunch.UpdateCallback[]
8
8
  export const afterRender = [] as Lunch.UpdateCallback[]
9
9
 
10
- export const update: Lunch.UpdateCallback = (opts: {
11
- app: Lunch.App
12
- renderer?: THREE.Renderer | null
13
- scene?: THREE.Scene | null
14
- camera?: THREE.Camera | null
15
- }) => {
10
+ export const update: Lunch.UpdateCallback = (opts) => {
11
+ // request next frame
16
12
  frameID = requestAnimationFrame(() =>
17
13
  update({
18
14
  app: opts.app,
19
15
  renderer: ensureRenderer.value?.instance,
20
16
  scene: ensuredScene.value.instance,
21
- camera: ensuredCamera.value.instance,
17
+ camera: ensuredCamera.value?.instance,
22
18
  })
23
19
  )
24
20
 
21
+ // prep options
25
22
  const { app, renderer, scene, camera } = opts
26
23
 
27
24
  // BEFORE RENDER
@@ -32,9 +29,12 @@ export const update: Lunch.UpdateCallback = (opts: {
32
29
  })
33
30
 
34
31
  // RENDER
35
- // console.log(camera?.position.z)
36
32
  if (renderer && scene && camera) {
37
- renderer.render(toRaw(scene), toRaw(camera))
33
+ if (app.customRender) {
34
+ app.customRender(opts)
35
+ } else {
36
+ renderer.render(toRaw(scene), toRaw(camera))
37
+ }
38
38
  }
39
39
 
40
40
  // AFTER RENDER
@@ -53,6 +53,15 @@ export const onBeforeRender = (cb: Lunch.UpdateCallback, index = Infinity) => {
53
53
  }
54
54
  }
55
55
 
56
+ export const offBeforeRender = (cb: Lunch.UpdateCallback | number) => {
57
+ if (isFinite(cb as number)) {
58
+ beforeRender.splice(cb as number, 1)
59
+ } else {
60
+ const idx = beforeRender.findIndex((v) => v == cb)
61
+ beforeRender.splice(idx, 1)
62
+ }
63
+ }
64
+
56
65
  export const onAfterRender = (cb: Lunch.UpdateCallback, index = Infinity) => {
57
66
  if (index === Infinity) {
58
67
  afterRender.push(cb)
@@ -61,6 +70,15 @@ export const onAfterRender = (cb: Lunch.UpdateCallback, index = Infinity) => {
61
70
  }
62
71
  }
63
72
 
73
+ export const offAfterRender = (cb: Lunch.UpdateCallback | number) => {
74
+ if (isFinite(cb as number)) {
75
+ afterRender.splice(cb as number, 1)
76
+ } else {
77
+ const idx = afterRender.findIndex((v) => v == cb)
78
+ afterRender.splice(idx, 1)
79
+ }
80
+ }
81
+
64
82
  export const cancelUpdate = () => {
65
83
  if (frameID) cancelAnimationFrame(frameID)
66
84
  }
package/src/index.ts CHANGED
@@ -12,13 +12,17 @@ import {
12
12
  inputActive,
13
13
  mousePos,
14
14
  rootUuid,
15
- update,
16
15
  } from './core'
17
16
  import { components } from './components'
18
17
  import { Lunch } from './types'
19
18
 
20
19
  export { lunchboxRootNode as lunchboxTree } from './core'
21
- export { onBeforeRender, onAfterRender, update } from './core'
20
+ export {
21
+ offAfterRender,
22
+ offBeforeRender,
23
+ onBeforeRender,
24
+ onAfterRender,
25
+ } from './core'
22
26
  export * from './types'
23
27
 
24
28
  // Utilities
@@ -31,16 +35,41 @@ export const globals = {
31
35
  mousePos,
32
36
  }
33
37
 
34
- export const camera = computed(() => ensuredCamera.value.instance)
38
+ export const camera = computed(() => ensuredCamera.value?.instance ?? null)
35
39
  export const renderer = computed(() => ensureRenderer.value?.instance ?? null)
36
40
  export const scene = computed(() => ensuredScene.value.instance)
37
41
 
42
+ // CUSTOM RENDER SUPPORT
43
+ // ====================
44
+ let app: Lunch.App | null = null
45
+ let queuedCustomRenderFunction:
46
+ | ((opts: Lunch.UpdateCallbackProperties) => void)
47
+ | null = null
48
+
49
+ /** Set a custom render function, overriding the Lunchbox app's default render function.
50
+ * Changing this requires the user to manually render their scene.
51
+ */
52
+ export const setCustomRender = (
53
+ render: (opts: Lunch.UpdateCallbackProperties) => void
54
+ ) => {
55
+ if (app) app.setCustomRender(render)
56
+ else queuedCustomRenderFunction = render
57
+ }
58
+
59
+ /** Clear the active app's custom render function. */
60
+ export const clearCustomRender = () => {
61
+ if (app) app.clearCustomRender()
62
+ else queuedCustomRenderFunction = null
63
+ }
64
+
65
+ // CREATE APP
66
+ // ====================
38
67
  export const createApp = (root: Component) => {
39
- const app = createRenderer(nodeOps).createApp(root) as Lunch.App
68
+ app = createRenderer(nodeOps).createApp(root) as Lunch.App
40
69
 
41
70
  // register all components
42
71
  Object.keys(components).forEach((key) => {
43
- app.component(key, (components as any)[key])
72
+ app!.component(key, (components as any)[key])
44
73
  })
45
74
 
46
75
  // update mount function to match Lunchbox.Node
@@ -57,15 +86,33 @@ export const createApp = (root: Component) => {
57
86
  type: 'root',
58
87
  uuid: rootUuid,
59
88
  })
60
- app.rootNode = rootNode
89
+ app!.rootNode = rootNode
61
90
  const mounted = mount(rootNode, ...args)
62
91
  return mounted
63
92
  }
64
93
 
65
94
  // embed .extend function
66
95
  app.extend = (targets: Record<string, any>) => {
67
- extend({ app, ...targets })
68
- return app
96
+ extend({ app: app!, ...targets })
97
+ return app!
98
+ }
99
+
100
+ // prep for custom render support
101
+ app.setCustomRender = (
102
+ newRender: (opts: Lunch.UpdateCallbackProperties) => void
103
+ ) => {
104
+ app!.customRender = newRender
105
+ }
106
+
107
+ // add queued custom render if we have one
108
+ if (queuedCustomRenderFunction) {
109
+ app.setCustomRender(queuedCustomRenderFunction)
110
+ queuedCustomRenderFunction = null
111
+ }
112
+
113
+ // add custom render removal
114
+ app.clearCustomRender = () => {
115
+ app!.customRender = null
69
116
  }
70
117
 
71
118
  // done
package/src/types.ts CHANGED
@@ -7,8 +7,13 @@ type RendererStandardNode<T = THREE.Object3D> =
7
7
  export declare namespace Lunch {
8
8
  /** Lunchbox app. */
9
9
  type App = VueApp<any> & {
10
+ clearCustomRender: () => void
11
+ customRender: ((opts: UpdateCallbackProperties) => void) | null
10
12
  extend: (v: Record<string, any>) => App
11
13
  rootNode: RootNode
14
+ setCustomRender: (
15
+ update: (opts: UpdateCallbackProperties) => void
16
+ ) => void
12
17
  update: UpdateCallback
13
18
  }
14
19
 
@@ -133,8 +138,13 @@ export declare namespace Lunch {
133
138
 
134
139
  interface WrapperProps {
135
140
  background?: string
141
+ cameraArgs?: any[]
142
+ cameraLook?: [number, number, number]
143
+ cameraLookAt?: [number, number, number]
136
144
  cameraPosition?: [number, number, number]
137
145
  dpr?: number
146
+ ortho?: boolean
147
+ orthographic?: boolean
138
148
  rendererProperties?: Partial<THREE.WebGLRenderer>
139
149
  shadow?: ShadowSugar
140
150
  transparent?: boolean