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

renderOrder to RenderOrderComponent objectLayers to ObjectLayerComponent #9472

Merged
merged 21 commits into from Dec 21, 2023

Conversation

MichaelEstes
Copy link
Contributor

@MichaelEstes MichaelEstes commented Dec 19, 2023

Summary

Replaces setting renderOrder and objectLayers with RenderOrderComponent and ObjectLayerComponent

removes

  • Engine.instance.objectLayerList

deprecates

  • setObjectLayers()
  • enableObjectLayer()

References

closes #9327, #9328

QA Steps

Copy link

cla-bot bot commented Dec 19, 2023

Thank you for your pull request and welcome to the Ethereal Engine developer community!

We require contributors to sign our Copyright Assignment Agreement, and we don't seem to have you on file.

In order for us to review and merge your code, please sign the agreement at https://forms.gle/15ENsSAJGKf2ozvB7

The agreement has not been signed by users: @MichaelEstes.

After signing the agreement, you can ask me to recheck this PR by posting @cla-bot check as a comment to the PR :)

@MichaelEstes
Copy link
Contributor Author

@cla-bot check

Copy link

cla-bot bot commented Dec 19, 2023

Checking that all contributors to this PR are verified.

for (const layer of component.objectLayers.value) {
object.layers.enable(layer)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the prior objectLayer implementation we were running a function updateWorldObjectLayers before when seting Object layer. I'm not familiar with the purpose myself but I see it missing from this implementation. There was likely a reason why it's there @HexaField

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of that function was to update lists on Engine.instance.objectLayerList. My preference is that we deprecate all that, and introduce a tag for each layer. In other words:

const ObjectLayerComponents = [defineComponent({name: 'ObjectLayer0'}), ..., defineComponent({name: 'ObjectLayer31'})]

export const ObjectLayerComponent = defineComponent({
   ...,
   setObjectLayers: (entity:Entity, ...layers: number[) => {
     layers.map((i) => setComponent(entity, ObjectLayerComponents[i]);)
   },
   enableObjectLayer: (entity:Entity, layer: number, enable: boolean) {
     layers.map((i) => setComponent(entity, ObjectLayerComponents[i]);)
   }
})


onInit(entity) {
return {
renderOrder: 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wanted you could probably just set the return as the number value and instead of passing {renderOrder: 1} in set component you can just pass 1

Copy link
Member

@HexaField HexaField left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The object layers component should be the same type as threejs, a bitmask, rather than an array of values.

@HexaField
Copy link
Member

export const ObjectLayerComponent = defineComponent({
   ...,
   entitiesBylayer: Record<layer: number, Entity[]>
})

@speigg
Copy link
Member

speigg commented Dec 20, 2023

export const ObjectLayerComponent = defineComponent({
   ...,
   entitiesBylayer: Record<layer: number, Entity[]>
})

Attaching data to components like this is not ideal; this does not get cleaned up automatically between tests. If we want to store data outside of components, we should use defineState()

name: 'ObjectLayerComponent',
schema: { mask: Types.i32 },

onSet(entity, component) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add the mask here as the input args, and add a toJSON() that returns the mask, so that this component is serialized properly.

})
})

export const ObjectLayerComponent = defineComponent({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename this to ObjectLayerMaskComponent for clarity, and to distinguish from the individual layer components?

return 0
},

onSet(entity, component, renderOrder) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a similar refactor as the object layers, w/ the renderOrder property relying on this data as the source of truth

import { GroupComponent } from './GroupComponent'

export const RenderOrderComponent = defineComponent({
name: 'RenderOrderComponent',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a bitecs schema for this as well.

@speigg speigg added this pull request to the merge queue Dec 21, 2023
Merged via the queue into dev with commit c910ef8 Dec 21, 2023
13 checks passed
@speigg speigg deleted the RenderOrderComponent_9328 branch December 21, 2023 21:33
Rezmason pushed a commit that referenced this pull request Dec 26, 2023
…ent (#9472)

* Start of RenderOrderComponent

* Change RenderOrderComponent to set render order on objects in group

* Change file locations

* Start of ObjectLayerComponent and tests

* Update setObjectLayers to LayerObjectComponent

* Update renderOrder to RenderOrderComponent

* add comments for each layer

* RenderOrderComponent changes, ObjectLayerComponent WIP

* Save for later

* Update ObjectRenderComponent, revert back to setObjectLayers, added Layer tests

* Add setter for Layer, change uint to int (Three expects -1 for enable all), add tests

* Change render order to use object property

* ObjectLayerMaskComponent toJson, rename, mask as set param

* Update toJson

* Change RenderOrder from class to function

* Cleanup

* Fix tests and remove Engine.instance.objectLayerList

* Update RenderOrderComponent.test.tsx

---------

Co-authored-by: HexaField <joshfield999@gmail.com>
Co-authored-by: Gheric Speiginer <gheric.speiginer@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

replace object layers with ObjectLayerComponent
4 participants