@lukekaalim/act-three 5.12.2 → 5.12.4

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,21 @@
1
+ // @flow strict
2
+ /*::
3
+ import type { SceneProps } from "../components";
4
+ import type { Scene, Texture } from "three";
5
+ */
6
+ import { Color } from "three";
7
+
8
+ /*::
9
+ export type PropSetters<T> = {
10
+ [string]: (object: T, nextProp: any, prevProp: any) => void,
11
+ }
12
+ */
13
+
14
+ export const scenePropSetters/*: PropSetters<Scene>*/ = {
15
+ 'background': (scene/*: Scene*/, prop/*: null | Color | Texture*/) => {
16
+ if (scene.background instanceof Color && prop instanceof Color)
17
+ scene.background.copy(prop)
18
+ else
19
+ scene.background = prop;
20
+ }
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukekaalim/act-three",
3
- "version": "5.12.2",
3
+ "version": "5.12.4",
4
4
  "description": "Render threejs content using act",
5
5
  "main": "entry.js",
6
6
  "types": "entry.d.ts",
package/props.js CHANGED
@@ -11,6 +11,7 @@ import { setHTMLProp } from "@lukekaalim/act-web";
11
11
  import {
12
12
  BufferGeometry,
13
13
  Camera,
14
+ Color,
14
15
  DirectionalLight,
15
16
  Euler,
16
17
  Group,
@@ -21,10 +22,12 @@ import {
21
22
  Object3D,
22
23
  OrthographicCamera,
23
24
  Quaternion,
25
+ Scene,
24
26
  Vector2,
25
27
  Vector3,
26
28
  } from "three";
27
29
  import { setRef } from "@lukekaalim/act-renderer-core";
30
+ import { scenePropSetters } from './components/scene';
28
31
 
29
32
  export const setTransformProp = (target/*: mixed*/, diff/*: PropDiff*/)/*: boolean*/ => {
30
33
  if (target instanceof Vector2 && diff.next instanceof Vector2) {
@@ -78,6 +81,15 @@ export const setMeshProp = (object/*: { [string]: mixed }*/, name/*: string*/, d
78
81
  }
79
82
  return false;
80
83
  }
84
+ export const setInstanceProp = (object/*: { [string]: mixed }*/, name/*: string*/, diff/*: PropDiff*/)/*: boolean*/ => {
85
+ if (object[name] instanceof Color) {
86
+ if (diff.next instanceof Color || typeof diff.next === 'string' || typeof diff.next === 'number') {
87
+ object[name].set(diff.next)
88
+ return true;
89
+ }
90
+ }
91
+ return false;
92
+ }
81
93
 
82
94
  export const setLightShadowProps = (
83
95
  diffs/*: PropDiffRegistry*/,
@@ -119,6 +131,9 @@ export const setObjectProps2 = (
119
131
  setLightShadowProps(propRegistry, target)
120
132
  continue;
121
133
  }
134
+ if (setInstanceProp((object/*: any*/), key, propDiff))
135
+ continue;
136
+
122
137
  if (setMeshProp((object/*: any*/), key, propDiff)) {
123
138
  continue;
124
139
  }
@@ -126,10 +141,20 @@ export const setObjectProps2 = (
126
141
  continue;
127
142
  if (setValueProp((object/*: any*/), key, propDiff))
128
143
  continue;
144
+ if (object instanceof Scene) {
145
+ const setter = scenePropSetters[propDiff.key];
146
+ if (setter) {
147
+ setter(object, propDiff.next, propDiff.prev);
148
+ continue;
149
+ }
150
+ }
151
+
152
+
129
153
 
130
154
  console.warn(`Unhandled prop ${key}`, propDiff.next, object);
131
155
  }
132
156
 
133
157
  if (object instanceof OrthographicCamera)
134
158
  object.updateProjectionMatrix();
159
+
135
160
  }