@lukekaalim/act-three 7.1.2 → 8.0.1
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/CHANGELOG.md +19 -0
- package/builder.ts +3 -8
- package/elements.ts +149 -53
- package/index.ts +0 -1
- package/package.json +4 -4
- package/props.ts +75 -22
- package/deps.ts +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @lukekaalim/act-three
|
|
2
2
|
|
|
3
|
+
## 8.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4168a3d: Lie about the ReadOnly nature of a Ref passes to an element to avoid obscure type issues
|
|
8
|
+
|
|
9
|
+
## 8.0.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- bf3138f: Added PrimitiveRegistry for dynamically adding more elements to act-three, implemented in backstage
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [bf3138f]
|
|
18
|
+
- @lukekaalim/act-backstage@3.2.0
|
|
19
|
+
- @lukekaalim/act-web@5.2.0
|
|
20
|
+
- @lukekaalim/act@4.3.0
|
|
21
|
+
|
|
3
22
|
## 7.1.2
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/builder.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodeBuilder } from "@lukekaalim/act-backstage";
|
|
2
2
|
import { Object3D } from "three";
|
|
3
|
-
import {
|
|
3
|
+
import { registry } from "./elements";
|
|
4
4
|
import { Component, h, specialNodeTypes } from "@lukekaalim/act";
|
|
5
5
|
|
|
6
6
|
export const ThreeJSRoot: Component = ({ children }) => h(specialNodeTypes.render, { type: 'threejs' }, children);
|
|
@@ -9,15 +9,10 @@ export const createThreeJSBuilder = (rootObject: Object3D | null = null): NodeBu
|
|
|
9
9
|
roots: new Set(['threejs']),
|
|
10
10
|
|
|
11
11
|
create(element) {
|
|
12
|
-
|
|
13
|
-
if (handler)
|
|
14
|
-
return handler.create(element.props);
|
|
15
|
-
return null;
|
|
12
|
+
return registry.create(element);
|
|
16
13
|
},
|
|
17
14
|
update(el, next, prev) {
|
|
18
|
-
|
|
19
|
-
if (handler)
|
|
20
|
-
handler.setProps(el, prev && prev.props, next.props);
|
|
15
|
+
registry.update(el, next, prev);
|
|
21
16
|
},
|
|
22
17
|
linkRoot: rootObject && ((child) => {
|
|
23
18
|
rootObject.add(child);
|
package/elements.ts
CHANGED
|
@@ -1,69 +1,165 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import * as three from "three";
|
|
2
|
+
import { ReadonlyRef, Ref } from "@lukekaalim/act";
|
|
3
|
+
import { createPrimitiveRegistry } from "@lukekaalim/act-backstage";
|
|
4
|
+
import { setProps } from "./props";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
export type PropsFromClass<T extends three.Object3D> = {
|
|
7
|
+
position?: three.Vector3Like,
|
|
8
|
+
rotation?: three.Euler,
|
|
9
|
+
quaternion?: three.QuaternionLike,
|
|
10
|
+
scale?: three.Vector3,
|
|
11
|
+
//pivot?: three.Vector3Like | null,
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
name?: string,
|
|
14
|
+
layers?: three.Layers,
|
|
15
|
+
|
|
16
|
+
visible?: boolean,
|
|
17
|
+
static?: boolean,
|
|
18
|
+
renderOrder?: number,
|
|
19
|
+
receiveShadow?: boolean,
|
|
20
|
+
castShadow?: boolean,
|
|
21
|
+
frustumCulled?: boolean,
|
|
22
|
+
|
|
23
|
+
animations?: three.AnimationClip[],
|
|
24
|
+
|
|
25
|
+
userData?: {},
|
|
26
|
+
|
|
27
|
+
//up?: three.Vector3Like,
|
|
28
|
+
|
|
29
|
+
//onChildAdded?: (child: three.Object3D) => void,
|
|
30
|
+
//onChildRemoved?: (child: three.Object3D) => void,
|
|
31
|
+
//onAdded?: (self: T) => void,
|
|
32
|
+
//onRemoved?: (self: T) => void,
|
|
33
|
+
|
|
34
|
+
ref?: ReadonlyRef<null | T>
|
|
12
35
|
}
|
|
36
|
+
& (T extends three.Mesh | three.Points | three.Line ? DrawableProps : {})
|
|
37
|
+
& (T extends three.Sprite ? SpriteProps : {})
|
|
38
|
+
& (T extends three.Light ? LightProps : {})
|
|
39
|
+
& (T extends three.Camera ? CameraProps<T> : {})
|
|
40
|
+
& (T extends three.Scene ? SceneProps : {})
|
|
13
41
|
|
|
14
|
-
|
|
15
|
-
|
|
42
|
+
type SceneProps = {
|
|
43
|
+
fog?: three.FogExp2 | three.Fog | null,
|
|
44
|
+
overrideMaterial?: three.Material | null,
|
|
45
|
+
|
|
46
|
+
background?: three.Color | three.Texture | null,
|
|
47
|
+
backgroundBlurriness?: number,
|
|
48
|
+
backgroundRotation?: number,
|
|
49
|
+
backgroundIntensity?: three.Euler,
|
|
50
|
+
|
|
51
|
+
environment?: three.Texture | null,
|
|
52
|
+
environmentRotation?: number,
|
|
53
|
+
environmentIntensity?: three.Euler,
|
|
16
54
|
}
|
|
17
55
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
56
|
+
type DrawableProps = {
|
|
57
|
+
geometry?: three.BufferGeometry,
|
|
58
|
+
material?: three.Material | three.Material[]
|
|
59
|
+
}
|
|
60
|
+
type LightProps = {
|
|
61
|
+
color?: three.Color,
|
|
62
|
+
intensity?: number,
|
|
25
63
|
}
|
|
64
|
+
type SpriteProps = {
|
|
65
|
+
center?: three.Vector2Like,
|
|
66
|
+
} & DrawableProps;
|
|
67
|
+
type CameraProps<T extends three.Camera> =
|
|
68
|
+
& T extends three.PerspectiveCamera ? {
|
|
69
|
+
aspect?: number,
|
|
70
|
+
far?: number,
|
|
71
|
+
near?: number,
|
|
72
|
+
focus?: number,
|
|
73
|
+
fov?: number,
|
|
74
|
+
zoom?: number,
|
|
75
|
+
} : {}
|
|
76
|
+
& T extends three.OrthographicCamera ? {
|
|
77
|
+
far?: number,
|
|
78
|
+
near?: number,
|
|
26
79
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},
|
|
38
|
-
})
|
|
80
|
+
top?: number,
|
|
81
|
+
right?: number,
|
|
82
|
+
left?: number,
|
|
83
|
+
bottom?: number,
|
|
84
|
+
|
|
85
|
+
zoom?: number,
|
|
86
|
+
} : {}
|
|
87
|
+
|
|
88
|
+
type BuiltinRegistry = {
|
|
89
|
+
[Property in keyof THREE_CLASS_MAP]: PropsFromClass<InstanceType<THREE_CLASS_MAP[Property]>>
|
|
39
90
|
}
|
|
40
91
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Users can write:
|
|
94
|
+
* ```ts
|
|
95
|
+
* declare module "@lukekaalim/act-three" {
|
|
96
|
+
* interface ExtendedPrimitives {
|
|
97
|
+
* MyPrimitive: { myProps: boolean }
|
|
98
|
+
* }
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
* to add a new type definition for an element,
|
|
102
|
+
* and then supply an implementation via:
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* registry
|
|
106
|
+
* .registerPrimitive(
|
|
107
|
+
* 'MyPrimitive',
|
|
108
|
+
* () => new MyPrimitive(),
|
|
109
|
+
* (primitive, props) => { primitive.myProps = props.myProps; })
|
|
110
|
+
* );
|
|
111
|
+
*
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export interface ExtendedPrimitives {}
|
|
48
115
|
|
|
49
|
-
|
|
50
|
-
directionalLight: DirectionalLight,
|
|
116
|
+
type AllPrimitives = ExtendedPrimitives & BuiltinRegistry;
|
|
51
117
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
118
|
+
export const registry = createPrimitiveRegistry<AllPrimitives, three.Object3D>();
|
|
119
|
+
/**
|
|
120
|
+
* Type checked act-three primitive elements.
|
|
121
|
+
*/
|
|
122
|
+
export const a3 = registry.elements;
|
|
55
123
|
|
|
56
|
-
perspectiveCamera: PerspectiveCamera,
|
|
57
|
-
orthographicCamera: OrthographicCamera,
|
|
58
|
-
} as const;
|
|
59
|
-
type ElementMap = typeof elementMap;
|
|
60
124
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
125
|
+
type THREE_CLASS_MAP = typeof THREE_OBJECT3D_CLASS_MAP;
|
|
126
|
+
const THREE_OBJECT3D_CLASS_MAP = {
|
|
127
|
+
mesh: three.Mesh,
|
|
128
|
+
instancedMesh: three.InstancedMesh,
|
|
129
|
+
skinnedMesh: three.SkinnedMesh,
|
|
130
|
+
|
|
131
|
+
points: three.Points,
|
|
132
|
+
|
|
133
|
+
object: three.Object3D,
|
|
134
|
+
group: three.Group,
|
|
135
|
+
scene: three.Scene,
|
|
136
|
+
|
|
137
|
+
sprite: three.Sprite,
|
|
138
|
+
|
|
139
|
+
pointLight: three.PointLight,
|
|
140
|
+
directionalLight: three.DirectionalLight,
|
|
64
141
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
142
|
+
line: three.Line,
|
|
143
|
+
lineLoop: three.LineLoop,
|
|
144
|
+
lineSegments: three.LineSegments,
|
|
68
145
|
|
|
69
|
-
|
|
146
|
+
perspectiveCamera: three.PerspectiveCamera,
|
|
147
|
+
orthographicCamera: three.OrthographicCamera,
|
|
148
|
+
cubeCamera: three.CubeCamera,
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
registry
|
|
152
|
+
.addGlobalCreateHandler((type, props) => {
|
|
153
|
+
const ObjectClass = (THREE_OBJECT3D_CLASS_MAP as any)[type];
|
|
154
|
+
if (ObjectClass) {
|
|
155
|
+
const object = new (ObjectClass as typeof three.Object3D)();
|
|
156
|
+
setProps(object, props as PropsFromClass<three.Object3D>);
|
|
157
|
+
return object;
|
|
158
|
+
}
|
|
159
|
+
console.warn(`I WONT MAKE ${type}`)
|
|
160
|
+
return null;
|
|
161
|
+
})
|
|
162
|
+
.addGlobalUpdateHandler((type, object, next, prev) => {
|
|
163
|
+
setProps(object, next as PropsFromClass<three.Object3D>);
|
|
164
|
+
})
|
|
165
|
+
.registerUnhandledPrimitives(Object.keys(THREE_OBJECT3D_CLASS_MAP) as any[])
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
"name": "@lukekaalim/act-three",
|
|
3
3
|
"main": "index.ts",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "8.0.1",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@lukekaalim/act": "^4.
|
|
8
|
-
"@lukekaalim/act-backstage": "^3.
|
|
7
|
+
"@lukekaalim/act": "^4.3.0",
|
|
8
|
+
"@lukekaalim/act-backstage": "^3.2.0",
|
|
9
9
|
"@lukekaalim/act-recon": "^4.0.0",
|
|
10
|
-
"@lukekaalim/act-web": "^5.
|
|
10
|
+
"@lukekaalim/act-web": "^5.2.0",
|
|
11
11
|
"@types/three": ">= 0.185.0"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
package/props.ts
CHANGED
|
@@ -1,39 +1,92 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import * as three from 'three';
|
|
2
|
+
import * as act from '@lukekaalim/act';
|
|
3
|
+
import { PropsFromClass } from "./elements";
|
|
3
4
|
|
|
4
|
-
export type Object3DProps<T extends Object3D> = {
|
|
5
|
-
position?: three.Vector3,
|
|
6
|
-
scale?: three.Vector3,
|
|
7
|
-
quaternion?: three.Quaternion,
|
|
8
|
-
rotation?: three.Euler,
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
& (T extends three.Mesh ? { geometry?: three.BufferGeometry, material?: three.Material } : {})
|
|
13
|
-
& (T extends three.Scene ? { background?: three.Color } : {})
|
|
14
|
-
|
|
15
|
-
export const setProps = <T extends Object3D>(object: T, props: Object3DProps<T>) => {
|
|
6
|
+
export const setProps = (object: three.Object3D, props: PropsFromClass<three.Object3D>) => {
|
|
16
7
|
if (props.position)
|
|
17
|
-
object.position.copy(props.position
|
|
8
|
+
object.position.copy(props.position);
|
|
18
9
|
if (props.scale)
|
|
19
|
-
object.scale.copy(props.scale
|
|
10
|
+
object.scale.copy(props.scale);
|
|
20
11
|
if (props.quaternion)
|
|
21
|
-
object.quaternion.copy(props.quaternion
|
|
12
|
+
object.quaternion.copy(props.quaternion);
|
|
22
13
|
if (props.rotation)
|
|
23
|
-
object.rotation.copy(props.rotation
|
|
14
|
+
object.rotation.copy(props.rotation);
|
|
15
|
+
|
|
16
|
+
if (props.name !== undefined)
|
|
17
|
+
object.name = props.name;
|
|
18
|
+
if (props.layers)
|
|
19
|
+
object.layers = props.layers;
|
|
20
|
+
|
|
21
|
+
if (props.visible !== undefined)
|
|
22
|
+
object.visible = props.visible;
|
|
23
|
+
if (props.static !== undefined)
|
|
24
|
+
object.static = props.static;
|
|
25
|
+
if (props.renderOrder !== undefined)
|
|
26
|
+
object.renderOrder = props.renderOrder;
|
|
27
|
+
if (props.receiveShadow !== undefined)
|
|
28
|
+
object.receiveShadow = props.receiveShadow;
|
|
29
|
+
if (props.castShadow !== undefined)
|
|
30
|
+
object.castShadow = props.castShadow;
|
|
31
|
+
if (props.frustumCulled !== undefined)
|
|
32
|
+
object.frustumCulled = props.frustumCulled;
|
|
33
|
+
|
|
34
|
+
if (props.animations)
|
|
35
|
+
object.animations = props.animations;
|
|
36
|
+
if (props.userData)
|
|
37
|
+
object.userData = props.userData;
|
|
38
|
+
|
|
24
39
|
if (props.ref)
|
|
25
|
-
|
|
40
|
+
props.ref.current = object;
|
|
26
41
|
|
|
27
|
-
if (object instanceof three.Mesh) {
|
|
28
|
-
const meshProps = props as
|
|
42
|
+
if (object instanceof three.Mesh || object instanceof three.Points || object instanceof three.Line) {
|
|
43
|
+
const meshProps = props as PropsFromClass<three.Mesh | three.Points | three.Line>;
|
|
29
44
|
object.geometry = meshProps.geometry;
|
|
30
45
|
object.material = meshProps.material;
|
|
31
46
|
}
|
|
47
|
+
|
|
32
48
|
if (object instanceof three.PerspectiveCamera) {
|
|
49
|
+
const perspectiveCameraProps = props as PropsFromClass<three.PerspectiveCamera>;
|
|
50
|
+
if (perspectiveCameraProps.aspect)
|
|
51
|
+
object.aspect = perspectiveCameraProps.aspect;
|
|
52
|
+
if (perspectiveCameraProps.fov)
|
|
53
|
+
object.fov = perspectiveCameraProps.fov;
|
|
54
|
+
|
|
55
|
+
if (perspectiveCameraProps.far)
|
|
56
|
+
object.far = perspectiveCameraProps.far;
|
|
57
|
+
if (perspectiveCameraProps.near)
|
|
58
|
+
object.near = perspectiveCameraProps.near;
|
|
59
|
+
|
|
60
|
+
if (perspectiveCameraProps.zoom)
|
|
61
|
+
object.zoom = perspectiveCameraProps.zoom;
|
|
62
|
+
|
|
33
63
|
object.updateProjectionMatrix();
|
|
34
64
|
}
|
|
35
65
|
if (object instanceof three.Scene) {
|
|
36
|
-
const sceneProps = props as
|
|
37
|
-
|
|
66
|
+
const sceneProps = props as PropsFromClass<three.Scene>;
|
|
67
|
+
if (sceneProps.background !== undefined)
|
|
68
|
+
object.background = sceneProps.background;
|
|
69
|
+
if (sceneProps.environment !== undefined)
|
|
70
|
+
object.environment = sceneProps.environment;
|
|
71
|
+
|
|
72
|
+
if (sceneProps.fog !== undefined)
|
|
73
|
+
object.fog = sceneProps.fog;
|
|
74
|
+
if (sceneProps.overrideMaterial !== undefined)
|
|
75
|
+
object.overrideMaterial = sceneProps.overrideMaterial;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (object instanceof three.Light) {
|
|
79
|
+
const lightProps = props as PropsFromClass<three.Light>;
|
|
80
|
+
if (lightProps.color)
|
|
81
|
+
object.color.copy(lightProps.color)
|
|
82
|
+
if (lightProps.intensity !== undefined)
|
|
83
|
+
object.intensity = lightProps.intensity;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (object instanceof three.Sprite) {
|
|
87
|
+
const spriteProps = props as PropsFromClass<three.Sprite>;
|
|
88
|
+
if (spriteProps.center)
|
|
89
|
+
object.center.copy(spriteProps.center)
|
|
38
90
|
}
|
|
39
91
|
};
|
|
92
|
+
|
package/deps.ts
DELETED