Sfoglia il codice sorgente

fix: improve scene object handling in Tres Devtools

- Enhanced the logic for extracting UUIDs from scene node IDs to ensure proper handling of scene objects.
- Updated the inspector state editing to reflect the new UUID extraction method, improving reliability when editing scene objects.
- Set the `editable` property to false for certain inspector values to prevent unintended modifications.
alvarosabu 4 mesi fa
parent
commit
33a1023fdd
1 ha cambiato i file con 19 aggiunte e 6 eliminazioni
  1. 19 6
      src/devtools/plugin.ts

+ 19 - 6
src/devtools/plugin.ts

@@ -256,9 +256,14 @@ export function registerTresDevtools(app: any, tres: TresContext) {
       api.on.getInspectorState((payload) => {
         if (payload.inspectorId === INSPECTOR_ID) {
           if (payload.nodeId.includes('scene')) {
-            // Existing scene handling logic
-            const [instance] = tres.scene.value.getObjectsByProperty('uuid', payload.nodeId.split('scene-')[1]) as TresObject[]
+            // Extract UUID from scene-uuid format
+            const match = payload.nodeId.match(/^scene-(.+)$/)
+            const uuid = match ? match[1] : null
+            if (!uuid) { return }
+
+            const [instance] = tres.scene.value.getObjectsByProperty('uuid', uuid) as TresObject[]
             if (!instance) { return }
+
             if (prevInstance && highlightMesh && highlightMesh.parent) {
               prevInstance.remove(highlightMesh)
             }
@@ -324,7 +329,7 @@ export function registerTresDevtools(app: any, tres: TresContext) {
                   .map(([key, value]) => ({
                     key,
                     value: isRef(value) ? value.value : value,
-                    editable: true,
+                    editable: false,
                   })),
               }
               return
@@ -347,7 +352,7 @@ export function registerTresDevtools(app: any, tres: TresContext) {
                       return {
                         key,
                         value: val.value,
-                        editable: true,
+                        editable: false,
                       }
                     }
                     if (typeof val === 'function') {
@@ -367,7 +372,7 @@ export function registerTresDevtools(app: any, tres: TresContext) {
                     return {
                       key,
                       value: val,
-                      editable: true,
+                      editable: false,
                     }
                   }),
               }
@@ -378,7 +383,15 @@ export function registerTresDevtools(app: any, tres: TresContext) {
 
       api.on.editInspectorState((payload) => {
         if (payload.inspectorId === INSPECTOR_ID) {
-          editSceneObject(tres.scene.value, payload.nodeId, payload.path, payload.state.value)
+          if (payload.nodeId.includes('scene')) {
+            // Extract UUID from scene-uuid format
+            const match = payload.nodeId.match(/^scene-(.+)$/)
+            const uuid = match ? match[1] : null
+            if (!uuid) { return }
+
+            // Handle scene object editing
+            editSceneObject(tres.scene.value, uuid, payload.path, payload.state.value)
+          }
         }
       })
     },