Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 792 directionallighthelpers breaks devtools #793

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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