Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
particle system trail rendering hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
dinomut1 committed May 25, 2024
1 parent a55505a commit c3d4bf3
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions packages/engine/src/scene/components/ParticleSystemComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,23 @@ import {
import matches from 'ts-matches'

import { Engine, UUIDComponent } from '@etherealengine/ecs'
import { defineComponent, getComponent, setComponent, useComponent } from '@etherealengine/ecs/src/ComponentFunctions'
import {
defineComponent,
getComponent,
setComponent,
useComponent,
useOptionalComponent
} from '@etherealengine/ecs/src/ComponentFunctions'
import { createEntity, generateEntityUUID, useEntityContext } from '@etherealengine/ecs/src/EntityFunctions'
import { NO_PROXY, defineState, getMutableState, getState, none, useHookstate } from '@etherealengine/hyperflux'
import {
NO_PROXY,
defineState,
dispatchAction,
getMutableState,
getState,
none,
useHookstate
} from '@etherealengine/hyperflux'
import { NameComponent } from '@etherealengine/spatial/src/common/NameComponent'
import { addObjectToGroup, removeObjectFromGroup } from '@etherealengine/spatial/src/renderer/components/GroupComponent'
import { VisibleComponent } from '@etherealengine/spatial/src/renderer/components/VisibleComponent'
Expand All @@ -60,7 +74,11 @@ import { TransformComponent } from '@etherealengine/spatial/src/transform/compon
import { AssetLoader } from '../../assets/classes/AssetLoader'
import { AssetClass } from '../../assets/enum/AssetClass'
import { useGLTF, useTexture } from '../../assets/functions/resourceLoaderHooks'
import { GLTFComponent } from '../../gltf/GLTFComponent'
import { GLTFSnapshotAction } from '../../gltf/GLTFDocumentState'
import { GLTFSnapshotState, GLTFSourceState } from '../../gltf/GLTFState'
import getFirstMesh from '../util/meshUtils'
import { SourceComponent } from './SourceComponent'

export const ParticleState = defineState({
name: 'ParticleState',
Expand Down Expand Up @@ -810,6 +828,10 @@ export const ParticleSystemComponent = defineComponent({
const componentState = useComponent(entity, ParticleSystemComponent)
const batchRenderer = useHookstate(getMutableState(ParticleState).batchRenderer)
const metadata = useHookstate({ textures: {}, geometries: {}, materials: {} } as ParticleSystemMetadata)
const sceneID = useOptionalComponent(entity, SourceComponent)?.value
const rootEntity = useHookstate(getMutableState(GLTFSourceState))[sceneID ?? ''].value
const rootGLTF = useOptionalComponent(rootEntity, GLTFComponent)
const refreshed = useHookstate(false)

const [geoDependency] = useGLTF(componentState.value.systemParameters.instancingGeometry!, entity, {}, (url) => {
metadata.geometries.nested(url).set(none)
Expand All @@ -827,6 +849,17 @@ export const ParticleSystemComponent = defineComponent({
transparent: componentState.value.systemParameters.transparent ?? true,
blending: componentState.value.systemParameters.blending as Blending
})
//@todo: this is a hack to make trail rendering mode work correctly. We need to find out why an additional snapshot is needed
useEffect(() => {
if (rootGLTF?.value?.progress !== 100) return
if (refreshed.value) return

if (componentState.systemParameters.renderMode.value === RenderMode.Trail) {
const snapshot = GLTFSnapshotState.cloneCurrentSnapshot(sceneID!)
dispatchAction(GLTFSnapshotAction.createSnapshot(snapshot))
}
refreshed.set(true)
}, [rootGLTF?.value?.progress])

useEffect(() => {
//add dud material
Expand Down

0 comments on commit c3d4bf3

Please sign in to comment.