Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4acc96b

Browse files
committedFeb 23, 2025
chore(core): rework json generation
wip json generation wip wip wip wip wip
1 parent 18abf86 commit 4acc96b

File tree

8 files changed

+1002
-421
lines changed

8 files changed

+1002
-421
lines changed
 

‎libs/core/src/lib/three-types.ts

Lines changed: 102 additions & 421 deletions
Large diffs are not rendered by default.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
export const COMMON_ATTRIBUTES = [
2+
{
3+
name: 'attach',
4+
description: 'Property to attach to parent. Can be dotted path',
5+
},
6+
{
7+
name: '[attach]',
8+
description: 'An array of paths to attach to parent. Can also be an NgtAttachFunction',
9+
},
10+
{
11+
name: '[dispose]',
12+
description: 'Cleanup function',
13+
},
14+
{
15+
name: '[parameters]',
16+
description: 'Additional parameters for the instance',
17+
},
18+
{
19+
name: '[userData]',
20+
description: 'User data to pass to the instance',
21+
},
22+
];
23+
24+
export const COMMON_EVENTS = [
25+
{
26+
name: '(change)',
27+
properties: { type: 'string', target: 'any' },
28+
},
29+
{
30+
name: '(disposed)',
31+
properties: { type: 'string', target: 'any' },
32+
},
33+
{
34+
name: '(attached)',
35+
type: 'NgtAfterAttach',
36+
description: 'Fires after the element is attached to its parent',
37+
properties: [
38+
{
39+
name: 'parent',
40+
description: 'The parent instance this element was attached to',
41+
},
42+
{
43+
name: 'node',
44+
description: 'The element instance that was attached',
45+
},
46+
],
47+
},
48+
{
49+
name: '(updated)',
50+
type: 'any',
51+
description: 'Fires when the element is updated with the updated instance',
52+
},
53+
];
54+
55+
export const OBJECT3D_EVENTS = [
56+
{
57+
name: 'added',
58+
properties: { type: 'string', target: 'THREE.Object3D' },
59+
},
60+
{
61+
name: 'removed',
62+
properties: { type: 'string', target: 'THREE.Object3D' },
63+
},
64+
{
65+
name: 'childadded',
66+
properties: { type: 'string', target: 'THREE.Object3D', child: 'THREE.Object3D' },
67+
},
68+
{
69+
name: 'childremoved',
70+
properties: { type: 'string', target: 'THREE.Object3D', child: 'THREE.Object3D' },
71+
},
72+
];

‎tools/scripts/json/event-types.mjs

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
export const EVENT_TYPE_MAP = {
2+
click: {
3+
type: 'MouseEvent',
4+
properties: {
5+
eventObject: 'THREE.Object3D',
6+
intersections: 'THREE.Intersection[]',
7+
unprojectedPoint: 'THREE.Vector3',
8+
pointer: 'THREE.Vector2',
9+
delta: 'number',
10+
ray: 'THREE.Ray',
11+
camera: 'THREE.Camera',
12+
stopPropagation: '() => void',
13+
nativeEvent: 'MouseEvent',
14+
},
15+
},
16+
contextmenu: {
17+
type: 'MouseEvent',
18+
properties: {
19+
eventObject: 'THREE.Object3D',
20+
intersections: 'THREE.Intersection[]',
21+
unprojectedPoint: 'THREE.Vector3',
22+
pointer: 'THREE.Vector2',
23+
delta: 'number',
24+
ray: 'THREE.Ray',
25+
camera: 'THREE.Camera',
26+
stopPropagation: '() => void',
27+
nativeEvent: 'MouseEvent',
28+
},
29+
},
30+
dblclick: {
31+
type: 'MouseEvent',
32+
properties: {
33+
eventObject: 'THREE.Object3D',
34+
intersections: 'THREE.Intersection[]',
35+
unprojectedPoint: 'THREE.Vector3',
36+
pointer: 'THREE.Vector2',
37+
delta: 'number',
38+
ray: 'THREE.Ray',
39+
camera: 'THREE.Camera',
40+
stopPropagation: '() => void',
41+
nativeEvent: 'MouseEvent',
42+
},
43+
},
44+
pointerup: {
45+
type: 'PointerEvent',
46+
properties: {
47+
eventObject: 'THREE.Object3D',
48+
intersections: 'THREE.Intersection[]',
49+
unprojectedPoint: 'THREE.Vector3',
50+
pointer: 'THREE.Vector2',
51+
delta: 'number',
52+
ray: 'THREE.Ray',
53+
camera: 'THREE.Camera',
54+
stopPropagation: '() => void',
55+
nativeEvent: 'PointerEvent',
56+
},
57+
},
58+
pointerdown: {
59+
type: 'PointerEvent',
60+
properties: {
61+
eventObject: 'THREE.Object3D',
62+
intersections: 'THREE.Intersection[]',
63+
unprojectedPoint: 'THREE.Vector3',
64+
pointer: 'THREE.Vector2',
65+
delta: 'number',
66+
ray: 'THREE.Ray',
67+
camera: 'THREE.Camera',
68+
stopPropagation: '() => void',
69+
nativeEvent: 'PointerEvent',
70+
},
71+
},
72+
pointerover: {
73+
type: 'PointerEvent',
74+
properties: {
75+
eventObject: 'THREE.Object3D',
76+
intersections: 'THREE.Intersection[]',
77+
unprojectedPoint: 'THREE.Vector3',
78+
pointer: 'THREE.Vector2',
79+
delta: 'number',
80+
ray: 'THREE.Ray',
81+
camera: 'THREE.Camera',
82+
stopPropagation: '() => void',
83+
nativeEvent: 'PointerEvent',
84+
},
85+
},
86+
pointerout: {
87+
type: 'PointerEvent',
88+
properties: {
89+
eventObject: 'THREE.Object3D',
90+
intersections: 'THREE.Intersection[]',
91+
unprojectedPoint: 'THREE.Vector3',
92+
pointer: 'THREE.Vector2',
93+
delta: 'number',
94+
ray: 'THREE.Ray',
95+
camera: 'THREE.Camera',
96+
stopPropagation: '() => void',
97+
nativeEvent: 'PointerEvent',
98+
},
99+
},
100+
pointerenter: {
101+
type: 'PointerEvent',
102+
properties: {
103+
eventObject: 'THREE.Object3D',
104+
intersections: 'THREE.Intersection[]',
105+
unprojectedPoint: 'THREE.Vector3',
106+
pointer: 'THREE.Vector2',
107+
delta: 'number',
108+
ray: 'THREE.Ray',
109+
camera: 'THREE.Camera',
110+
stopPropagation: '() => void',
111+
nativeEvent: 'PointerEvent',
112+
},
113+
},
114+
pointerleave: {
115+
type: 'PointerEvent',
116+
properties: {
117+
eventObject: 'THREE.Object3D',
118+
intersections: 'THREE.Intersection[]',
119+
unprojectedPoint: 'THREE.Vector3',
120+
pointer: 'THREE.Vector2',
121+
delta: 'number',
122+
ray: 'THREE.Ray',
123+
camera: 'THREE.Camera',
124+
stopPropagation: '() => void',
125+
nativeEvent: 'PointerEvent',
126+
},
127+
},
128+
pointermove: {
129+
type: 'PointerEvent',
130+
properties: {
131+
eventObject: 'THREE.Object3D',
132+
intersections: 'THREE.Intersection[]',
133+
unprojectedPoint: 'THREE.Vector3',
134+
pointer: 'THREE.Vector2',
135+
delta: 'number',
136+
ray: 'THREE.Ray',
137+
camera: 'THREE.Camera',
138+
stopPropagation: '() => void',
139+
nativeEvent: 'PointerEvent',
140+
},
141+
},
142+
pointercancel: {
143+
type: 'PointerEvent',
144+
properties: {
145+
eventObject: 'THREE.Object3D',
146+
intersections: 'THREE.Intersection[]',
147+
unprojectedPoint: 'THREE.Vector3',
148+
pointer: 'THREE.Vector2',
149+
delta: 'number',
150+
ray: 'THREE.Ray',
151+
camera: 'THREE.Camera',
152+
stopPropagation: '() => void',
153+
nativeEvent: 'PointerEvent',
154+
},
155+
},
156+
wheel: {
157+
type: 'WheelEvent',
158+
properties: {
159+
eventObject: 'THREE.Object3D',
160+
intersections: 'THREE.Intersection[]',
161+
unprojectedPoint: 'THREE.Vector3',
162+
pointer: 'THREE.Vector2',
163+
delta: 'number',
164+
ray: 'THREE.Ray',
165+
camera: 'THREE.Camera',
166+
stopPropagation: '() => void',
167+
nativeEvent: 'WheelEvent',
168+
},
169+
},
170+
};

‎tools/scripts/json/generate.mjs

Lines changed: 432 additions & 0 deletions
Large diffs are not rendered by default.

‎tools/scripts/json/index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './generate.mjs';

‎tools/scripts/json/math-types.mjs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export const MATH_TYPE_MAP = {
2+
Vector2: {
3+
type: 'NgtVector2',
4+
accepts: ['THREE.Vector2', '[number, number]', 'number'],
5+
},
6+
Vector3: {
7+
type: 'NgtVector3',
8+
accepts: ['THREE.Vector3', '[number, number, number]', 'number'],
9+
},
10+
Color: {
11+
type: 'NgtColor',
12+
accepts: ['THREE.Color', 'string', 'number', '[number, number, number]'],
13+
},
14+
Euler: {
15+
type: 'NgtEuler',
16+
accepts: ['THREE.Euler', '[number, number, number]', '[number, number, number, string]'],
17+
},
18+
Quaternion: {
19+
type: 'NgtQuaternion',
20+
accepts: ['THREE.Quaternion', '[number, number, number, number]'],
21+
},
22+
Matrix3: {
23+
type: 'NgtMatrix3',
24+
accepts: ['THREE.Matrix3', '[number, number, number, number, number, number, number, number, number]'],
25+
},
26+
Matrix4: {
27+
type: 'NgtMatrix4',
28+
accepts: [
29+
'THREE.Matrix4',
30+
'[number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number]',
31+
],
32+
},
33+
Layers: { type: 'NgtLayers', accepts: ['THREE.Layers', 'number'] },
34+
};
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
export const NGT_THREE_ELEMENTS = {
2+
'ngt-object3D': 'Object3D',
3+
'ngt-lOD': 'LOD',
4+
'ngt-mesh': 'Mesh',
5+
'ngt-instanced-mesh': 'InstancedMesh',
6+
'ngt-material': 'Material',
7+
'ngt-mesh-basic-material': 'MeshBasicMaterial',
8+
'ngt-mesh-physical-material': 'MeshPhysicalMaterial',
9+
'ngt-mesh-standard-material': 'MeshStandardMaterial',
10+
'ngt-mesh-toon-material': 'MeshToonMaterial',
11+
'ngt-mesh-normal-material': 'MeshNormalMaterial',
12+
'ngt-mesh-depth-material': 'MeshDepthMaterial',
13+
'ngt-mesh-distance-material': 'MeshDistanceMaterial',
14+
'ngt-mesh-matcap-material': 'MeshMatcapMaterial',
15+
'ngt-mesh-phong-material': 'MeshPhongMaterial',
16+
'ngt-line-basic-material': 'LineBasicMaterial',
17+
'ngt-line-dashed-material': 'LineDashedMaterial',
18+
'ngt-mesh-lambert-material': 'MeshLambertMaterial',
19+
'ngt-points-material': 'PointsMaterial',
20+
'ngt-raw-shader-material': 'RawShaderMaterial',
21+
'ngt-shader-material': 'ShaderMaterial',
22+
'ngt-shadow-material': 'ShadowMaterial',
23+
'ngt-sprite-material': 'SpriteMaterial',
24+
'ngt-instanced-buffer-geometry': 'InstancedBufferGeometry',
25+
'ngt-buffer-geometry': 'BufferGeometry',
26+
'ngt-wireframe-geometry': 'WireframeGeometry',
27+
'ngt-tetrahedron-geometry': 'TetrahedronGeometry',
28+
'ngt-octahedron-geometry': 'OctahedronGeometry',
29+
'ngt-icosahedron-geometry': 'IcosahedronGeometry',
30+
'ngt-polyhedron-geometry': 'PolyhedronGeometry',
31+
'ngt-dodecahedron-geometry': 'DodecahedronGeometry',
32+
'ngt-tube-geometry': 'TubeGeometry',
33+
'ngt-torus-knot-geometry': 'TorusKnotGeometry',
34+
'ngt-torus-geometry': 'TorusGeometry',
35+
'ngt-sphere-geometry': 'SphereGeometry',
36+
'ngt-ring-geometry': 'RingGeometry',
37+
'ngt-plane-geometry': 'PlaneGeometry',
38+
'ngt-lathe-geometry': 'LatheGeometry',
39+
'ngt-line-segments': 'LineSegments',
40+
'ngt-line-loop': 'LineLoop',
41+
'ngt-points': 'Points',
42+
'ngt-group': 'Group',
43+
'ngt-camera': 'Camera',
44+
'ngt-perspective-camera': 'PerspectiveCamera',
45+
'ngt-orthographic-camera': 'OrthographicCamera',
46+
'ngt-cube-camera': 'CubeCamera',
47+
'ngt-array-camera': 'ArrayCamera',
48+
'ngt-spot-light': 'SpotLight',
49+
'ngt-point-light': 'PointLight',
50+
'ngt-rect-area-light': 'RectAreaLight',
51+
'ngt-hemisphere-light': 'HemisphereLight',
52+
'ngt-directional-light': 'DirectionalLight',
53+
'ngt-ambient-light': 'AmbientLight',
54+
'ngt-light-probe': 'LightProbe',
55+
'ngt-spot-light-helper': 'SpotLightHelper',
56+
'ngt-skeleton-helper': 'SkeletonHelper',
57+
'ngt-point-light-helper': 'PointLightHelper',
58+
'ngt-hemisphere-light-helper': 'HemisphereLightHelper',
59+
'ngt-grid-helper': 'GridHelper',
60+
'ngt-polar-grid-helper': 'PolarGridHelper',
61+
'ngt-directional-light-helper': 'DirectionalLightHelper',
62+
'ngt-camera-helper': 'CameraHelper',
63+
'ngt-box-helper': 'BoxHelper',
64+
'ngt-box3-helper': 'Box3Helper',
65+
'ngt-plane-helper': 'PlaneHelper',
66+
'ngt-arrow-helper': 'ArrowHelper',
67+
'ngt-axes-helper': 'AxesHelper',
68+
'ngt-audio': 'Audio',
69+
'ngt-positional-audio': 'PositionalAudio',
70+
'ngt-audio-listener': 'AudioListener',
71+
'ngt-texture': 'Texture',
72+
'ngt-compressed-texture': 'CompressedTexture',
73+
'ngt-video-texture': 'VideoTexture',
74+
'ngt-data-texture': 'DataTexture',
75+
'ngt-data3D-texture': 'Data3DTexture',
76+
'ngt-cube-texture': 'CubeTexture',
77+
'ngt-canvas-texture': 'CanvasTexture',
78+
'ngt-depth-texture': 'DepthTexture',
79+
'ngt-raycaster': 'Raycaster',
80+
'ngt-vector2': 'Vector2',
81+
'ngt-vector3': 'Vector3',
82+
'ngt-vector4': 'Vector4',
83+
'ngt-euler': 'Euler',
84+
'ngt-matrix3': 'Matrix3',
85+
'ngt-matrix4': 'Matrix4',
86+
'ngt-quaternion': 'Quaternion',
87+
'ngt-buffer-attribute': 'BufferAttribute',
88+
'ngt-float16-buffer-attribute': 'Float16BufferAttribute',
89+
'ngt-float32-buffer-attribute': 'Float32BufferAttribute',
90+
'ngt-int8-buffer-attribute': 'Int8BufferAttribute',
91+
'ngt-int16-buffer-attribute': 'Int16BufferAttribute',
92+
'ngt-int32-buffer-attribute': 'Int32BufferAttribute',
93+
'ngt-uint8-buffer-attribute': 'Uint8BufferAttribute',
94+
'ngt-uint16-buffer-attribute': 'Uint16BufferAttribute',
95+
'ngt-uint32-buffer-attribute': 'Uint32BufferAttribute',
96+
'ngt-instanced-buffer-attribute': 'InstancedBufferAttribute',
97+
'ngt-color': 'Color',
98+
'ngt-fog': 'Fog',
99+
'ngt-fog-exp2': 'FogExp2',
100+
'ngt-shape': 'Shape',
101+
'ngt-primitive': null,
102+
'ngt-value': null,
103+
};
104+
105+
export const ELEMENT_METADATA = {
106+
'ngt-primitive': {
107+
description: 'Container for pre-made THREE objects',
108+
onlyCommonProperties: true,
109+
},
110+
'ngt-value': {
111+
description: 'Attaches arbitrary values to parent',
112+
onlyCommonProperties: true,
113+
properties: [
114+
{
115+
name: 'rawValue',
116+
type: 'any',
117+
description: 'Raw value to be attached'
118+
}
119+
]
120+
},
121+
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
export const KNOWN_PROPERTIES = {
2+
SpotLightHelper: {
3+
properties: ['light', 'matrix', 'matrixAutoUpdate', 'color'],
4+
isObject3D: true,
5+
},
6+
SkeletonHelper: {
7+
properties: ['root', 'bones', 'matrix', 'matrixAutoUpdate'],
8+
isObject3D: true,
9+
},
10+
PointLightHelper: {
11+
properties: ['light', 'matrix', 'matrixAutoUpdate', 'color'],
12+
isObject3D: true,
13+
},
14+
HemisphereLightHelper: {
15+
properties: ['light', 'matrix', 'matrixAutoUpdate', 'color', 'size'],
16+
isObject3D: true,
17+
},
18+
DirectionalLightHelper: {
19+
properties: ['light', 'matrix', 'matrixAutoUpdate', 'color', 'size'],
20+
isObject3D: true,
21+
},
22+
CameraHelper: {
23+
properties: ['camera', 'matrix', 'matrixAutoUpdate', 'pointMap'],
24+
isObject3D: true,
25+
},
26+
Audio: {
27+
properties: [
28+
'listener',
29+
'context',
30+
'gain',
31+
'autoplay',
32+
'buffer',
33+
'detune',
34+
'loop',
35+
'loopStart',
36+
'loopEnd',
37+
'offset',
38+
'duration',
39+
'playbackRate',
40+
'isPlaying',
41+
'source',
42+
'sourceType',
43+
'filters',
44+
],
45+
isObject3D: true,
46+
},
47+
PositionalAudio: {
48+
properties: [
49+
'panner',
50+
'orientation',
51+
'position',
52+
'refDistance',
53+
'rolloffFactor',
54+
'maxDistance',
55+
'distanceModel',
56+
'panningModel',
57+
'coneInnerAngle',
58+
'coneOuterAngle',
59+
'coneOuterGain',
60+
],
61+
isObject3D: true,
62+
},
63+
AudioListener: {
64+
properties: ['context', 'gain', 'filter', 'timeDelta', 'rotation', 'position'],
65+
isObject3D: true,
66+
},
67+
VideoTexture: {
68+
properties: ['video', 'needsUpdate'],
69+
},
70+
};

0 commit comments

Comments
 (0)
Please sign in to comment.