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

feat(editor): component window (scenePrefabs refactored) #8278

Merged
merged 19 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export const PositionalAudioComponent = defineComponent({
jsonID: 'audio',

onInit: (entity) => {
setComponent(entity, MediaComponent, { paths: ['__$project$__/default-project/assets/SampleAudio.mp3'] })

return {
// default values as suggested at https://medium.com/@kfarr/understanding-web-audio-api-positional-audio-distance-models-for-webxr-e77998afcdff
distanceModel: 'inverse' as DistanceModelType,
Expand All @@ -70,6 +72,8 @@ export const PositionalAudioComponent = defineComponent({
},

onSet: (entity, component, json) => {
setComponent(entity, MediaComponent)

if (!json) return
if (typeof json.distanceModel === 'number' && component.distanceModel.value !== json.distanceModel)
component.distanceModel.set(json.distanceModel)
Expand All @@ -85,8 +89,6 @@ export const PositionalAudioComponent = defineComponent({
component.coneOuterAngle.set(json.coneOuterAngle)
if (typeof json.coneOuterGain === 'number' && component.coneOuterGain.value !== json.coneOuterGain)
component.coneOuterGain.set(json.coneOuterGain)

setComponent(entity, MediaComponent, { paths: ['__$project$__/default-project/assets/SampleAudio.mp3'] })
},

toJSON: (entity, component) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/engine/src/scene/components/CloudComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export const CloudComponent = defineComponent({
} as CloudComponentType
},
onSet: (entity, component, json) => {
setComponent(entity, ShadowComponent)

if (!json) return
if (typeof json.texture === 'string') component.texture.set(json.texture)
if (typeof json.worldScale === 'object')
Expand All @@ -73,8 +75,6 @@ export const CloudComponent = defineComponent({
component.spriteScaleRange.set(new Vector2(json.spriteScaleRange.x, json.spriteScaleRange.y))
if (typeof json.fogColor === 'number') component.fogColor.set(new Color(json.fogColor))
if (typeof json.fogRange === 'object') component.fogRange.set(new Vector2(json.fogRange.x, json.fogRange.y))

setComponent(entity, ShadowComponent)
},
toJSON(entity, component) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export const GroundPlaneComponent = defineComponent({
},

onSet(entity, component, json) {
setComponent(entity, ShadowComponent)

if (!json) return

if (matches.object.test(json.color) || matches.string.test(json.color) || matches.number.test(json.color))
Expand All @@ -76,8 +78,6 @@ export const GroundPlaneComponent = defineComponent({
*/
if (!getState(EngineState).sceneLoaded && hasComponent(entity, SceneObjectComponent))
setComponent(entity, SceneAssetPendingTagComponent)

setComponent(entity, ShadowComponent)
},

toJSON(entity, component) {
Expand Down
7 changes: 3 additions & 4 deletions packages/engine/src/scene/components/ImageComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const ImageComponent = defineComponent({

onInit: (entity) => {
return {
source: '',
source: '__$project$__/default-project/assets/sample_etc1s.ktx2',
alphaMode: ImageAlphaMode.Opaque as ImageAlphaModeType,
alphaCutoff: 0.5,
projection: ImageProjection.Flat as ImageProjectionType,
Expand All @@ -99,8 +99,9 @@ export const ImageComponent = defineComponent({
},

onSet: (entity, component, json) => {
setComponent(entity, ShadowComponent)

if (!json) return
if (!component.source.value) component.source.set('__$project$__/default-project/assets/sample_etc1s.ktx2')
// backwards compatability
if (typeof json.source === 'string' && json.source !== component.source.value) component.source.set(json.source)
if (typeof json.alphaMode === 'string' && json.alphaMode !== component.alphaMode.value)
Expand All @@ -110,8 +111,6 @@ export const ImageComponent = defineComponent({
if (typeof json.projection === 'string' && json.projection !== component.projection.value)
component.projection.set(json.projection)
if (typeof json.side === 'number' && json.side !== component.side.value) component.side.set(json.side)

setComponent(entity, ShadowComponent)
},

onRemove: (entity, component) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/engine/src/scene/components/InteriorComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ export const InteriorComponent = defineComponent({
} as InteriorComponentType
},
onSet: (entity, component, json) => {
setComponent(entity, ShadowComponent)

if (!json) return
if (typeof json.cubeMap === 'string') component.cubeMap.set(json.cubeMap)
if (typeof json.tiling === 'number') component.tiling.set(json.tiling)
if (typeof json.size === 'object') component.size.set(new Vector2(json.size.x, json.size.y))

setComponent(entity, ShadowComponent)
},
toJSON(entity, component) {
return {
Expand Down
8 changes: 4 additions & 4 deletions packages/engine/src/scene/components/ModelComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export const ModelComponent = defineComponent({
},

onSet: (entity, component, json) => {
setComponent(entity, EnvmapComponent)
setComponent(entity, LoopAnimationComponent)
HexaField marked this conversation as resolved.
Show resolved Hide resolved
setComponent(entity, ShadowComponent)

if (!json) return
if (typeof json.src === 'string' && json.src !== component.src.value) component.src.set(json.src)
if (typeof json.generateBVH === 'boolean' && json.generateBVH !== component.generateBVH.value)
Expand All @@ -91,10 +95,6 @@ export const ModelComponent = defineComponent({
*/
if (!getState(EngineState).sceneLoaded && hasComponent(entity, SceneObjectComponent))
setComponent(entity, SceneAssetPendingTagComponent)

setComponent(entity, EnvmapComponent)
setComponent(entity, LoopAnimationComponent)
setComponent(entity, ShadowComponent)
},

onRemove: (entity, component) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/engine/src/scene/components/OceanComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export const OceanComponent = defineComponent({
}
},
onSet: (entity, component, json) => {
setComponent(entity, ShadowComponent)

if (!json) return
if (typeof json.normalMap === 'string') component.normalMap.set(json.normalMap)
if (typeof json.distortionMap === 'string') component.distortionMap.set(json.distortionMap)
Expand Down Expand Up @@ -96,8 +98,6 @@ export const OceanComponent = defineComponent({
ocean.update(dt)
})
}

setComponent(entity, ShadowComponent)
},
toJSON: (entity, component) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ export const ParticleSystemComponent = defineComponent({
} as ParticleSystemComponentType
},
onSet: (entity, component, json) => {
setComponent(entity, ShadowComponent)

!!json?.systemParameters &&
component.systemParameters.set({
...JSON.parse(JSON.stringify(component.systemParameters.value)),
Expand All @@ -759,8 +761,6 @@ export const ParticleSystemComponent = defineComponent({
!!json?.behaviorParameters && component.behaviorParameters.set(JSON.parse(JSON.stringify(json.behaviorParameters)))
;(!!json?.systemParameters || !!json?.behaviorParameters) &&
component._refresh.set((component._refresh.value + 1) % 1000)

setComponent(entity, ShadowComponent)
},
onRemove: (entity, component) => {
if (component.system.value) {
Expand Down
3 changes: 2 additions & 1 deletion packages/engine/src/scene/components/PortalComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export const PortalComponent = defineComponent({
},

onSet: (entity, component, json) => {
setComponent(entity, ShadowComponent)

if (!json) return
if (matches.string.test(json.linkedPortalId)) component.linkedPortalId.set(json.linkedPortalId)
if (matches.string.test(json.location)) component.location.set(json.location)
Expand All @@ -122,7 +124,6 @@ export const PortalComponent = defineComponent({
new Quaternion().setFromEuler(new Euler().setFromVector3(json.spawnRotation as any))
)
}
setComponent(entity, ShadowComponent)
},

toJSON: (entity, component) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/engine/src/scene/components/SplineComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export const SplineComponent = defineComponent({
},

onSet: (entity, component, json) => {
setComponent(entity, ShadowComponent)

if (!json) return
if (typeof json.splinePositions !== 'undefined')
component.splinePositions.set(json.splinePositions.map((pos) => new Vector3(pos.x, pos.y, pos.z)))

setComponent(entity, ShadowComponent)
},

toJSON(entity, component) {
Expand Down
10 changes: 6 additions & 4 deletions packages/engine/src/scene/components/VideoComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export const VideoComponent = defineComponent({
jsonID: 'video',

onInit: (entity) => {
setComponent(entity, MediaComponent, { paths: ['__$project$__/default-project/assets/SampleAudio.mp3'] })

const videoGroup = new Group()
videoGroup.name = `video-group-${entity}`
const videoMesh = new Mesh(PLANE_GEO, new MeshBasicMaterial())
Expand Down Expand Up @@ -108,15 +110,15 @@ export const VideoComponent = defineComponent({
},

onSet: (entity, component, json) => {
setComponent(entity, MediaComponent)
setComponent(entity, PositionalAudioComponent)
setComponent(entity, ShadowComponent)

if (!json) return
if (typeof json.mediaUUID === 'string') component.mediaUUID.set(json.mediaUUID)
if (typeof json.side === 'number') component.side.set(json.side)
if (json.size) component.size.set(new Vector2(json.size.x, json.size.y))
if (json.fit) component.fit.set(json.fit)

setComponent(entity, MediaComponent, { paths: ['__$project$__/default-project/assets/SampleAudio.mp3'] })
setComponent(entity, PositionalAudioComponent)
setComponent(entity, ShadowComponent)
},

onRemove: (entity, component) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/engine/src/scene/components/VolumetricComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export const VolumetricComponent = defineComponent({
},

onSet: (entity, component, json) => {
if (typeof json?.useLoadingEffect === 'boolean' && json.useLoadingEffect !== component.useLoadingEffect.value)
component.useLoadingEffect.set(json.useLoadingEffect)

setComponent(entity, MediaComponent)
setComponent(entity, PositionalAudioComponent)
setComponent(entity, ShadowComponent)

if (typeof json?.useLoadingEffect === 'boolean' && json.useLoadingEffect !== component.useLoadingEffect.value)
component.useLoadingEffect.set(json.useLoadingEffect)
}
})

Expand Down
4 changes: 2 additions & 2 deletions packages/engine/src/scene/components/WaterComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export const WaterComponent = defineComponent({
},

onSet: (entity, _component, json) => {
if (!json) return

setComponent(entity, ShadowComponent)
HexaField marked this conversation as resolved.
Show resolved Hide resolved

if (!json) return
},

toJSON(entity, component) {
Expand Down