Skip to content

Commit 426acee

Browse files
authored
fix: 792 directionallighthelpers breaks devtools (#793)
* fix: better handling of color types for lights on devtools * fix: highlighted mesh counts on devtools stats #533
1 parent 1081bf2 commit 426acee

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/devtools/plugin.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import {
55
setupDevtoolsPlugin,
66
} from '@vue/devtools-api'
77
import { reactive } from 'vue'
8-
import type { Mesh } from 'three'
8+
import { Color, type Mesh } from 'three'
99
import { createHighlightMesh, editSceneObject } from '../utils'
10+
import * as is from '../utils/is'
1011
import { bytesToKB, calculateMemoryUsage } from '../utils/perf'
1112
import type { TresContext } from '../composables'
1213
import type { TresObject } from './../types'
@@ -51,14 +52,16 @@ const createNode = (object: TresObject): SceneGraphObject => {
5152
}
5253

5354
if (object.type.includes('Light')) {
55+
if (is.light(object)) {
56+
node.tags.push({
57+
label: `${object.intensity}`,
58+
textColor: 0x9499A6,
59+
backgroundColor: 0xF8F9FA,
60+
tooltip: 'Intensity',
61+
})
62+
}
5463
node.tags.push({
55-
label: `${object.intensity}`,
56-
textColor: 0x9499A6,
57-
backgroundColor: 0xF8F9FA,
58-
tooltip: 'Intensity',
59-
})
60-
node.tags.push({
61-
label: `#${object.color.getHexString()}`,
64+
label: `#${new Color(object.color).getHexString()}`,
6265
textColor: 0x9499A6,
6366
backgroundColor: 0xF8F9FA,
6467
tooltip: 'Color',
@@ -173,6 +176,9 @@ export function registerTresDevtools(app: DevtoolsApp, tres: TresContext) {
173176
payload.state = {
174177
object: Object.entries(instance)
175178
.map(([key, value]) => {
179+
if (key === 'children') {
180+
return { key, value: value.filter(child => child.type !== 'HightlightMesh') }
181+
}
176182
return { key, value, editable: true }
177183
})
178184
.filter(({ key }) => {

src/utils/is.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { TresObject, TresPrimitive } from 'src/types'
2-
import type { BufferGeometry, Camera, Fog, Material, Object3D, Scene } from 'three'
2+
import type { BufferGeometry, Camera, Fog, Light, Material, Object3D, Scene } from 'three'
33

44
export function und(u: unknown) {
55
return typeof u === 'undefined'
@@ -45,6 +45,10 @@ export function material(u: unknown): u is Material {
4545
return obj(u) && 'isMaterial' in u && !!(u.isMaterial)
4646
}
4747

48+
export function light(u: unknown): u is Light {
49+
return obj(u) && 'isLight' in u && !!(u.isLight)
50+
}
51+
4852
export function fog(u: unknown): u is Fog {
4953
return obj(u) && 'isFog' in u && !!(u.isFog)
5054
}

src/utils/perf.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function calculateMemoryUsage(object: TresObject | Scene) {
55
let totalMemory = 0
66

77
object.traverse((node: TresObject) => {
8-
if (node.isMesh && node.geometry) {
8+
if (node.isMesh && node.geometry && node.type !== 'HightlightMesh') {
99
const geometry = node.geometry
1010
const verticesMemory = geometry.attributes.position.count * 3 * Float32Array.BYTES_PER_ELEMENT
1111
const facesMemory = geometry.index ? geometry.index.count * Uint32Array.BYTES_PER_ELEMENT : 0

0 commit comments

Comments
 (0)