Skip to content

Commit

Permalink
fix: 792 directionallighthelpers breaks devtools (#793)
Browse files Browse the repository at this point in the history
* fix: better handling of color types for lights on devtools

* fix: highlighted mesh counts on devtools stats #533
  • Loading branch information
alvarosabu committed Jul 26, 2024
1 parent 1081bf2 commit 426acee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
22 changes: 14 additions & 8 deletions src/devtools/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {
setupDevtoolsPlugin,
} from '@vue/devtools-api'
import { reactive } from 'vue'
import type { Mesh } from 'three'
import { Color, type Mesh } from 'three'
import { createHighlightMesh, editSceneObject } from '../utils'
import * as is from '../utils/is'
import { bytesToKB, calculateMemoryUsage } from '../utils/perf'
import type { TresContext } from '../composables'
import type { TresObject } from './../types'
Expand Down Expand Up @@ -51,14 +52,16 @@ const createNode = (object: TresObject): SceneGraphObject => {
}

if (object.type.includes('Light')) {
if (is.light(object)) {
node.tags.push({
label: `${object.intensity}`,
textColor: 0x9499A6,
backgroundColor: 0xF8F9FA,
tooltip: 'Intensity',
})
}
node.tags.push({
label: `${object.intensity}`,
textColor: 0x9499A6,
backgroundColor: 0xF8F9FA,
tooltip: 'Intensity',
})
node.tags.push({
label: `#${object.color.getHexString()}`,
label: `#${new Color(object.color).getHexString()}`,
textColor: 0x9499A6,
backgroundColor: 0xF8F9FA,
tooltip: 'Color',
Expand Down Expand Up @@ -173,6 +176,9 @@ export function registerTresDevtools(app: DevtoolsApp, tres: TresContext) {
payload.state = {
object: Object.entries(instance)
.map(([key, value]) => {
if (key === 'children') {
return { key, value: value.filter(child => child.type !== 'HightlightMesh') }
}
return { key, value, editable: true }
})
.filter(({ key }) => {
Expand Down
6 changes: 5 additions & 1 deletion src/utils/is.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TresObject, TresPrimitive } from 'src/types'
import type { BufferGeometry, Camera, Fog, Material, Object3D, Scene } from 'three'
import type { BufferGeometry, Camera, Fog, Light, Material, Object3D, Scene } from 'three'

export function und(u: unknown) {
return typeof u === 'undefined'
Expand Down Expand Up @@ -45,6 +45,10 @@ export function material(u: unknown): u is Material {
return obj(u) && 'isMaterial' in u && !!(u.isMaterial)
}

export function light(u: unknown): u is Light {
return obj(u) && 'isLight' in u && !!(u.isLight)
}

export function fog(u: unknown): u is Fog {
return obj(u) && 'isFog' in u && !!(u.isFog)
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function calculateMemoryUsage(object: TresObject | Scene) {
let totalMemory = 0

object.traverse((node: TresObject) => {
if (node.isMesh && node.geometry) {
if (node.isMesh && node.geometry && node.type !== 'HightlightMesh') {
const geometry = node.geometry
const verticesMemory = geometry.attributes.position.count * 3 * Float32Array.BYTES_PER_ELEMENT
const facesMemory = geometry.index ? geometry.index.count * Uint32Array.BYTES_PER_ELEMENT : 0
Expand Down

0 comments on commit 426acee

Please sign in to comment.