Skip to content

Commit

Permalink
feat: sdk7 GltfContainerLoadingState component (#5063)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbosio authored May 4, 2023
1 parent 020f55f commit b1d458c
Show file tree
Hide file tree
Showing 58 changed files with 2,245 additions and 119 deletions.
62 changes: 31 additions & 31 deletions scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"typescript": "^4.2.3"
},
"dependencies": {
"@dcl/protocol": "^1.0.0-4597420155.commit-e877adc",
"@dcl/protocol": "^1.0.0-4799189990.commit-8494b7b",
"@protobuf-ts/protoc": "^2.8.2",
"@types/fs-extra": "^11.0.1",
"@types/glob": "^8.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"GUID:a3ceb534947fac14da25035bc5c24788",
"GUID:97d8897529779cb49bebd400c7f402a6",
"GUID:02760f41040d3ef4c8652916aad15b45",
"GUID:707e0047a59e89c4d98d0d410163d11d"
"GUID:707e0047a59e89c4d98d0d410163d11d",
"GUID:dd3e381612f14b77a5cb26b26b2fdbbb"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public static float GetBottomRadius(this PBMeshCollider.Types.CylinderMesh self)
return self.HasRadiusBottom ? self.RadiusBottom : 0.5f;
}

public static int GetColliderLayer(this PBMeshCollider self)
public static uint GetColliderLayer(this PBMeshCollider self)
{
return self.HasCollisionMask ? self.CollisionMask : ((int)ColliderLayer.ClPhysics | (int)ColliderLayer.ClPointer);
return self.HasCollisionMask ? self.CollisionMask : ((uint)ColliderLayer.ClPhysics | (uint)ColliderLayer.ClPointer);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using DCL.ECS7;
using DCL.ECSComponents.UIDropdown;
using DCL.ECSComponents.UIInput;
using DCL.ECSComponents.UIText;
using DCL.ECSRuntime;
using DCLPlugins.ECSComponents;
using System;

namespace DCL.ECSComponents
{
Expand All @@ -30,6 +30,7 @@ public class ECS7ComponentsComposer : IDisposable
private readonly VisibilityComponentRegister visibilityComponentRegister;
private readonly PointerEventsRegister pointerEvents;
private readonly VideoPlayerRegister videoPlayerRegister;
private readonly GltfContainerLoadingStateRegister gltfContainerLoadingStateRegister;

// UI components
private readonly UITransformRegister uiTransformRegister;
Expand Down Expand Up @@ -79,6 +80,7 @@ public ECS7ComponentsComposer(ECSComponentsFactory componentsFactory, IECSCompon
pointerEventResultRegister = new PointerEventResultRegister(ComponentID.POINTER_EVENTS_RESULT, componentsFactory, componentsWriter);
cameraModeRegister = new CameraModeRegister(ComponentID.CAMERA_MODE, componentsFactory, componentsWriter);
pointerLockRegister = new PointerLockRegister(ComponentID.POINTER_LOCK, componentsFactory, componentsWriter);
gltfContainerLoadingStateRegister = new GltfContainerLoadingStateRegister(ComponentID.GLTF_CONTAINER_LOADING_STATE, componentsFactory, componentsWriter);
}

public void Dispose()
Expand Down Expand Up @@ -115,6 +117,7 @@ public void Dispose()
cameraModeRegister.Dispose();
pointerLockRegister.Dispose();
pointerEvents.Dispose();
gltfContainerLoadingStateRegister.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,23 @@ public class GltfContainerHandler : IECSComponentHandler<PBGltfContainer>
private readonly IInternalECSComponent<InternalColliders> pointerColliderComponent;
private readonly IInternalECSComponent<InternalColliders> physicColliderComponent;
private readonly IInternalECSComponent<InternalRenderers> renderersComponent;
private readonly IInternalECSComponent<InternalGltfContainerLoadingState> gltfContainerLoadingStateComponent;

private readonly DataStore_ECS7 dataStoreEcs7;
private DataStore_FeatureFlag featureFlags;
private readonly DataStore_FeatureFlag featureFlags;

public GltfContainerHandler(IInternalECSComponent<InternalColliders> pointerColliderComponent,
IInternalECSComponent<InternalColliders> physicColliderComponent,
IInternalECSComponent<InternalRenderers> renderersComponent,
DataStore_ECS7 dataStoreEcs7, DataStore_FeatureFlag featureFlags)
IInternalECSComponent<InternalGltfContainerLoadingState> gltfContainerLoadingStateComponent,
DataStore_ECS7 dataStoreEcs7,
DataStore_FeatureFlag featureFlags)
{
this.featureFlags = featureFlags;
this.pointerColliderComponent = pointerColliderComponent;
this.physicColliderComponent = physicColliderComponent;
this.renderersComponent = renderersComponent;
this.gltfContainerLoadingStateComponent = gltfContainerLoadingStateComponent;
this.dataStoreEcs7 = dataStoreEcs7;
}

Expand All @@ -62,6 +67,7 @@ public void OnComponentCreated(IParcelScene scene, IDCLEntity entity)
public void OnComponentRemoved(IParcelScene scene, IDCLEntity entity)
{
CleanUp(scene, entity);
gltfContainerLoadingStateComponent.RemoveFor(scene, entity, new InternalGltfContainerLoadingState() { GltfContainerRemoved = true });
Object.Destroy(gameObject);
}

Expand All @@ -74,8 +80,10 @@ public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, PBGlt

CleanUp(scene, entity);

gltfContainerLoadingStateComponent.PutFor(scene, entity, new InternalGltfContainerLoadingState() { LoadingState = LoadingState.Loading });

gltfLoader.OnSuccessEvent += rendereable => OnLoadSuccess(scene, entity, rendereable);
gltfLoader.OnFailEvent += exception => OnLoadFail(scene, exception);
gltfLoader.OnFailEvent += exception => OnLoadFail(scene, entity, exception);

dataStoreEcs7.AddPendingResource(scene.sceneData.sceneNumber, prevLoadedGltf);
gltfLoader.Load(model.Src);
Expand All @@ -95,13 +103,16 @@ private void OnLoadSuccess(IParcelScene scene, IDCLEntity entity, Rendereable re
physicColliderComponent.AddColliders(scene, entity, physicColliders, (int)ColliderLayer.ClPhysics);
renderersComponent.AddRenderers(scene, entity, renderers);

gltfContainerLoadingStateComponent.PutFor(scene, entity, new InternalGltfContainerLoadingState() { LoadingState = LoadingState.Finished });

// TODO: modify Animator component to remove `AddShapeReady` usage
dataStoreEcs7.AddShapeReady(entity.entityId, gameObject);
dataStoreEcs7.RemovePendingResource(scene.sceneData.sceneNumber, prevLoadedGltf);
}

private void OnLoadFail(IParcelScene scene, Exception exception)
private void OnLoadFail(IParcelScene scene, IDCLEntity entity, Exception exception)
{
gltfContainerLoadingStateComponent.PutFor(scene, entity, new InternalGltfContainerLoadingState() { LoadingState = LoadingState.FinishedWithError });
dataStoreEcs7.RemovePendingResource(scene.sceneData.sceneNumber, prevLoadedGltf);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using DCL.ECSRuntime;
using System;

namespace DCL.ECSComponents
{
Expand All @@ -14,13 +14,16 @@ public GltfContainerRegister(int componentId, ECSComponentsFactory factory, IECS
{
var dataStoreEcs7 = DataStore.i.ecs7;
var featureFlags = DataStore.i.featureFlags;

factory.AddOrReplaceComponent(componentId, ProtoSerialization.Deserialize<PBGltfContainer>,
() => new GltfContainerHandler(
internalComponents.onPointerColliderComponent,
internalComponents.physicColliderComponent,
internalComponents.renderersComponent,
internalComponents.GltfContainerLoadingStateComponent,
dataStoreEcs7,
featureFlags));

componentWriter.AddOrReplaceComponentSerializer<PBGltfContainer>(componentId, ProtoSerialization.Serialize);

this.factory = factory;
Expand All @@ -34,4 +37,4 @@ public void Dispose()
componentWriter.RemoveComponentSerializer(componentId);
}
}
}
}
Loading

0 comments on commit b1d458c

Please sign in to comment.