react-three-game 0.0.57 → 0.0.59
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/.github/copilot-instructions.md +1 -1
- package/README.md +59 -35
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/tools/assetviewer/page.js +1 -1
- package/dist/tools/dragdrop/DragDropLoader.d.ts +19 -6
- package/dist/tools/dragdrop/DragDropLoader.js +77 -40
- package/dist/tools/dragdrop/index.d.ts +4 -0
- package/dist/tools/dragdrop/index.js +2 -0
- package/dist/tools/dragdrop/modelLoader.d.ts +5 -6
- package/dist/tools/dragdrop/modelLoader.js +62 -49
- package/dist/tools/dragdrop/page.js +3 -3
- package/dist/tools/prefabeditor/EditorTree.js +24 -48
- package/dist/tools/prefabeditor/EditorTreeMenus.d.ts +33 -0
- package/dist/tools/prefabeditor/EditorTreeMenus.js +136 -0
- package/dist/tools/prefabeditor/PrefabEditor.js +1 -1
- package/dist/tools/prefabeditor/PrefabRoot.js +5 -3
- package/dist/tools/prefabeditor/components/CameraComponent.js +32 -12
- package/dist/tools/prefabeditor/components/DirectionalLightComponent.js +49 -23
- package/dist/tools/prefabeditor/components/MaterialComponent.d.ts +8 -0
- package/dist/tools/prefabeditor/components/MaterialComponent.js +11 -5
- package/dist/tools/prefabeditor/components/SpotLightComponent.js +34 -13
- package/package.json +2 -2
- package/react-three-game-skill/react-three-game/SKILL.md +63 -5
- package/react-three-game-skill/react-three-game/rules/ADVANCED_PHYSICS.md +7 -5
- package/src/index.ts +1 -1
- package/src/tools/assetviewer/page.tsx +1 -1
- package/src/tools/dragdrop/DragDropLoader.tsx +118 -55
- package/src/tools/dragdrop/index.ts +4 -0
- package/src/tools/dragdrop/modelLoader.ts +95 -50
- package/src/tools/dragdrop/page.tsx +7 -4
- package/src/tools/prefabeditor/EditorTree.tsx +56 -125
- package/src/tools/prefabeditor/EditorTreeMenus.tsx +307 -0
- package/src/tools/prefabeditor/PrefabEditor.tsx +1 -1
- package/src/tools/prefabeditor/PrefabRoot.tsx +6 -3
- package/src/tools/prefabeditor/components/CameraComponent.tsx +51 -14
- package/src/tools/prefabeditor/components/DirectionalLightComponent.tsx +59 -28
- package/src/tools/prefabeditor/components/MaterialComponent.tsx +18 -9
- package/src/tools/prefabeditor/components/SpotLightComponent.tsx +49 -18
|
@@ -1,41 +1,69 @@
|
|
|
1
1
|
import { Component } from "./ComponentRegistry";
|
|
2
|
-
import { useRef, useEffect } from "react";
|
|
2
|
+
import { useRef, useEffect, useMemo, useState } from "react";
|
|
3
3
|
import { BooleanField, ColorField, FieldGroup, NumberField } from "./Input";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { SpotLight, SpotLightHelper } from "three";
|
|
5
|
+
import { useFrame } from "@react-three/fiber";
|
|
6
|
+
|
|
7
|
+
const spotLightDefaults = {
|
|
8
|
+
color: '#ffffff',
|
|
9
|
+
intensity: 1,
|
|
10
|
+
angle: Math.PI / 6,
|
|
11
|
+
penumbra: 0.5,
|
|
12
|
+
distance: 100,
|
|
13
|
+
castShadow: true,
|
|
14
|
+
};
|
|
6
15
|
|
|
7
16
|
function SpotLightComponentEditor({ component, onUpdate }: { component: any; onUpdate: (newComp: any) => void }) {
|
|
17
|
+
const values = { ...spotLightDefaults, ...component.properties };
|
|
18
|
+
|
|
8
19
|
return (
|
|
9
20
|
<FieldGroup>
|
|
10
|
-
<ColorField name="color" label="Color" values={
|
|
11
|
-
<NumberField name="intensity" label="Intensity" values={
|
|
12
|
-
<NumberField name="angle" label="Angle" values={
|
|
13
|
-
<NumberField name="penumbra" label="Penumbra" values={
|
|
14
|
-
<NumberField name="distance" label="Distance" values={
|
|
15
|
-
<BooleanField name="castShadow" label="Cast Shadow" values={
|
|
21
|
+
<ColorField name="color" label="Color" values={values} onChange={onUpdate} />
|
|
22
|
+
<NumberField name="intensity" label="Intensity" values={values} onChange={onUpdate} min={0} step={0.1} fallback={1} />
|
|
23
|
+
<NumberField name="angle" label="Angle" values={values} onChange={onUpdate} min={0} max={Math.PI} step={0.05} fallback={Math.PI / 6} />
|
|
24
|
+
<NumberField name="penumbra" label="Penumbra" values={values} onChange={onUpdate} min={0} max={1} step={0.05} fallback={0.5} />
|
|
25
|
+
<NumberField name="distance" label="Distance" values={values} onChange={onUpdate} min={0} step={1} fallback={100} />
|
|
26
|
+
<BooleanField name="castShadow" label="Cast Shadow" values={values} onChange={onUpdate} fallback={true} />
|
|
16
27
|
</FieldGroup>
|
|
17
28
|
);
|
|
18
29
|
}
|
|
19
30
|
|
|
20
31
|
function SpotLightView({ properties, editMode, isSelected }: { properties: any; editMode?: boolean; isSelected?: boolean }) {
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
32
|
+
const merged = { ...spotLightDefaults, ...properties };
|
|
33
|
+
const color = merged.color;
|
|
34
|
+
const intensity = merged.intensity;
|
|
35
|
+
const angle = merged.angle;
|
|
36
|
+
const penumbra = merged.penumbra;
|
|
37
|
+
const distance = merged.distance;
|
|
38
|
+
const castShadow = merged.castShadow;
|
|
27
39
|
|
|
28
|
-
const spotLightRef = useRef<
|
|
40
|
+
const spotLightRef = useRef<SpotLight>(null);
|
|
29
41
|
const targetRef = useRef<any>(null);
|
|
42
|
+
const [spotLight, setSpotLight] = useState<SpotLight | null>(null);
|
|
43
|
+
const spotLightHelper = useMemo(
|
|
44
|
+
() => spotLight ? new SpotLightHelper(spotLight, color) : null,
|
|
45
|
+
[spotLight, color]
|
|
46
|
+
);
|
|
30
47
|
|
|
31
|
-
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
return () => {
|
|
50
|
+
spotLightHelper?.dispose();
|
|
51
|
+
};
|
|
52
|
+
}, [spotLightHelper]);
|
|
32
53
|
|
|
33
54
|
useEffect(() => {
|
|
34
55
|
if (spotLightRef.current && targetRef.current) {
|
|
35
56
|
spotLightRef.current.target = targetRef.current;
|
|
57
|
+
setSpotLight(spotLightRef.current);
|
|
36
58
|
}
|
|
37
59
|
}, []);
|
|
38
60
|
|
|
61
|
+
useFrame(() => {
|
|
62
|
+
if (spotLightHelper && editMode && isSelected) {
|
|
63
|
+
spotLightHelper.update();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
39
67
|
return (
|
|
40
68
|
<>
|
|
41
69
|
<spotLight
|
|
@@ -51,6 +79,9 @@ function SpotLightView({ properties, editMode, isSelected }: { properties: any;
|
|
|
51
79
|
shadow-bias={-0.0001}
|
|
52
80
|
shadow-normalBias={0.02}
|
|
53
81
|
/>
|
|
82
|
+
{editMode && isSelected && spotLightHelper && (
|
|
83
|
+
<primitive object={spotLightHelper} />
|
|
84
|
+
)}
|
|
54
85
|
<object3D ref={targetRef} position={[0, -5, 0]} />
|
|
55
86
|
{editMode && (
|
|
56
87
|
<>
|
|
@@ -72,7 +103,7 @@ const SpotLightComponent: Component = {
|
|
|
72
103
|
name: 'SpotLight',
|
|
73
104
|
Editor: SpotLightComponentEditor,
|
|
74
105
|
View: SpotLightView,
|
|
75
|
-
defaultProperties:
|
|
106
|
+
defaultProperties: spotLightDefaults
|
|
76
107
|
};
|
|
77
108
|
|
|
78
109
|
export default SpotLightComponent;
|