Skip to content

Commit

Permalink
refactor: createXXXEntity functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki Shimada committed Sep 15, 2024
1 parent 93add5d commit cd1d409
Show file tree
Hide file tree
Showing 37 changed files with 128 additions and 78 deletions.
6 changes: 0 additions & 6 deletions src/foundation/components/Camera/CameraComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,3 @@ export class CameraComponent extends Component {
return base as unknown as ComponentToComponentMethods<SomeComponentClass> & EntityBaseClass;
}
}

export function createCameraEntity(): ICameraEntity {
const entity = createGroupEntity();
const entityAddedComponent = EntityRepository.addComponentToEntity(CameraComponent, entity);
return entityAddedComponent;
}
13 changes: 13 additions & 0 deletions src/foundation/components/Camera/createCameraEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { EntityRepository } from '../../core/EntityRepository';
import { ICameraEntity } from '../../helpers/EntityHelper';
import { createGroupEntity } from '../SceneGraph/createGroupEntity';
import { WellKnownComponentTIDs } from '../WellKnownComponentTIDs';

export function createCameraEntity(): ICameraEntity {
const entity = createGroupEntity();
const entityAddedComponent = EntityRepository.tryToAddComponentToEntityByTID(
WellKnownComponentTIDs.CameraComponentTID,
entity
) as ICameraEntity;
return entityAddedComponent;
}
1 change: 1 addition & 0 deletions src/foundation/components/Camera/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './CameraComponent';
export * from './ICameraEntity';
export * from './createCameraEntity';
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import { IEntity } from '../../core/Entity';
import { ComponentToComponentMethods } from '../ComponentTypes';
import { ProcessStage } from '../../definitions';
import { createCameraEntity } from '../Camera/CameraComponent';
import { ICameraControllerEntity } from '../../helpers/EntityHelper';

/**
Expand Down Expand Up @@ -104,12 +103,3 @@ export class CameraControllerComponent extends Component {
return base as unknown as ComponentToComponentMethods<SomeComponentClass> & EntityBase;
}
}

export function createCameraControllerEntity(): ICameraControllerEntity {
const entity = createCameraEntity();
const entityAddedComponent = EntityRepository.addComponentToEntity(
CameraControllerComponent,
entity
);
return entityAddedComponent;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { EntityRepository } from '../../core/EntityRepository';
import { ICameraControllerEntity } from '../../helpers/EntityHelper';
import { createCameraEntity } from '../Camera/createCameraEntity';
import { WellKnownComponentTIDs } from '../WellKnownComponentTIDs';

export function createCameraControllerEntity(): ICameraControllerEntity {
const entity = createCameraEntity();
const entityAddedComponent = EntityRepository.tryToAddComponentToEntityByTID(
WellKnownComponentTIDs.CameraControllerComponentTID,
entity
) as ICameraControllerEntity;
return entityAddedComponent;
}
1 change: 1 addition & 0 deletions src/foundation/components/CameraController/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './CameraControllerComponent';
export * from './ICameraControllerEntity';
export * from './createCameraControllerEntity';
6 changes: 0 additions & 6 deletions src/foundation/components/Light/LightComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,3 @@ export class LightComponent extends Component {
return base as unknown as ComponentToComponentMethods<SomeComponentClass> & EntityBase;
}
}

export function createLightEntity(): ILightEntity {
const entity = createGroupEntity();
const entityAddedComponent = EntityRepository.addComponentToEntity(LightComponent, entity);
return entityAddedComponent;
}
13 changes: 13 additions & 0 deletions src/foundation/components/Light/createLightEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { EntityRepository } from '../../core/EntityRepository';
import { ILightEntity } from '../../helpers/EntityHelper';
import { createGroupEntity } from '../SceneGraph/createGroupEntity';
import { WellKnownComponentTIDs } from '../WellKnownComponentTIDs';

export function createLightEntity(): ILightEntity {
const entity = createGroupEntity();
const entityAddedComponent = EntityRepository.tryToAddComponentToEntityByTID(
WellKnownComponentTIDs.LightComponentTID,
entity
) as ILightEntity;
return entityAddedComponent;
}
1 change: 1 addition & 0 deletions src/foundation/components/Light/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './ILightEntity';
export * from './LightComponent';
export * from './createLightEntity';
10 changes: 0 additions & 10 deletions src/foundation/components/MeshRenderer/MeshRendererComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,3 @@ export class MeshRendererComponent extends Component {
return base as unknown as ComponentToComponentMethods<SomeComponentClass> & EntityBase;
}
}

export function createMeshEntity(): IMeshEntity {
const entity = createGroupEntity();
const entityAddedComponent = EntityRepository.addComponentToEntity(MeshComponent, entity);
const entityAddedComponent2 = EntityRepository.addComponentToEntity(
MeshRendererComponent,
entityAddedComponent
);
return entityAddedComponent2;
}
17 changes: 17 additions & 0 deletions src/foundation/components/MeshRenderer/createMeshEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { EntityRepository } from '../../core/EntityRepository';
import { IMeshEntity } from '../../helpers/EntityHelper';
import { createGroupEntity } from '../SceneGraph/createGroupEntity';
import { WellKnownComponentTIDs } from '../WellKnownComponentTIDs';

export function createMeshEntity(): IMeshEntity {
const entity = createGroupEntity();
const entityAddedComponent = EntityRepository.tryToAddComponentToEntityByTID(
WellKnownComponentTIDs.MeshComponentTID,
entity
);
const entityAddedComponent2 = EntityRepository.tryToAddComponentToEntityByTID(
WellKnownComponentTIDs.MeshRendererComponentTID,
entityAddedComponent
) as IMeshEntity;
return entityAddedComponent2;
}
1 change: 1 addition & 0 deletions src/foundation/components/MeshRenderer/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './IMeshRendererEntity';
export * from './MeshRendererComponent';
export * from './createMeshEntity';
6 changes: 0 additions & 6 deletions src/foundation/components/Physics/PhysicsComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,3 @@ export class PhysicsComponent extends Component {
return base as unknown as ComponentToComponentMethods<SomeComponentClass> & EntityBase;
}
}

export function createPhysicsEntity(): IPhysicsEntity {
const entity = createGroupEntity();
const entityAddedComponent = EntityRepository.addComponentToEntity(PhysicsComponent, entity);
return entityAddedComponent;
}
13 changes: 13 additions & 0 deletions src/foundation/components/Physics/createPhysicsEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { EntityRepository } from '../../core/EntityRepository';
import { IPhysicsEntity } from '../../helpers/EntityHelper';
import { createGroupEntity } from '../SceneGraph/createGroupEntity';
import { WellKnownComponentTIDs } from '../WellKnownComponentTIDs';

export function createPhysicsEntity(): IPhysicsEntity {
const entity = createGroupEntity();
const entityAddedComponent = EntityRepository.tryToAddComponentToEntityByTID(
WellKnownComponentTIDs.PhysicsComponentTID,
entity
) as IPhysicsEntity;
return entityAddedComponent;
}
1 change: 1 addition & 0 deletions src/foundation/components/Physics/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './IPhysicsEntity';
export * from './PhysicsComponent';
export * from './createPhysicsEntity';
3 changes: 1 addition & 2 deletions src/foundation/components/SceneGraph/SceneGraphComponent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ComponentRepository } from '../../core/ComponentRepository';
import { Component } from '../../core/Component';
import { Matrix44 } from '../../math/Matrix44';
import { applyMixins, EntityRepository } from '../../core/EntityRepository';
Expand Down Expand Up @@ -27,7 +26,7 @@ import { ScaleGizmo } from '../../gizmos/ScaleGizmo';
import { IMatrix44 } from '../../math/IMatrix';
import { IQuaternion, IVector3, MutableScalar, Quaternion } from '../../math';
import { OimoPhysicsStrategy } from '../../physics/Oimo/OimoPhysicsStrategy';
import { createTransformEntity, TransformComponent } from '../Transform/TransformComponent';
import { TransformComponent } from '../Transform/TransformComponent';
import { flattenHierarchy } from './SceneGraphOps';

export class SceneGraphComponent extends Component {
Expand Down
7 changes: 1 addition & 6 deletions src/foundation/components/SceneGraph/createGroupEntity.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { EntityRepository } from '../../core/EntityRepository';
import { ISceneGraphEntity } from '../../helpers/EntityHelper';
import { createTransformEntity } from '../Transform/TransformComponent';
import { createTransformEntity } from '../Transform/createTransformEntity';
import { WellKnownComponentTIDs } from '../WellKnownComponentTIDs';
import { SceneGraphComponent } from './SceneGraphComponent';

export function createGroupEntity(): ISceneGraphEntity {
const entity = createTransformEntity();
const entityAddedComponent = EntityRepository.tryToAddComponentToEntityByTID(
WellKnownComponentTIDs.SceneGraphComponentTID,
entity
) as ISceneGraphEntity;
// const entityAddedComponent = EntityRepository.addComponentToEntity(
// SceneGraphComponent,
// entity
// ) as ISceneGraphEntity;
return entityAddedComponent;
}
6 changes: 0 additions & 6 deletions src/foundation/components/Skeletal/SkeletalComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,3 @@ export class SkeletalComponent extends Component {
return m;
}
}

export function createSkeletalEntity(): ISkeletalEntity {
const entity = createGroupEntity();
const entityAddedComponent = EntityRepository.addComponentToEntity(SkeletalComponent, entity);
return entityAddedComponent;
}
13 changes: 13 additions & 0 deletions src/foundation/components/Skeletal/createSkeletalEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { EntityRepository } from '../../core/EntityRepository';
import { ISkeletalEntity } from '../../helpers/EntityHelper';
import { createGroupEntity } from '../SceneGraph/createGroupEntity';
import { WellKnownComponentTIDs } from '../WellKnownComponentTIDs';

export function createSkeletalEntity(): ISkeletalEntity {
const entity = createGroupEntity();
const entityAddedComponent = EntityRepository.tryToAddComponentToEntityByTID(
WellKnownComponentTIDs.SkeletalComponentTID,
entity
) as ISkeletalEntity;
return entityAddedComponent;
}
1 change: 1 addition & 0 deletions src/foundation/components/Skeletal/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './AnimationRetarget';
export * from './ISkeletalEntity';
export * from './SkeletalComponent';
export * from './createSkeletalEntity';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MemoryManager } from '../../core/MemoryManager';
import { Vector3 } from '../../math/Vector3';
import { createTransformEntity } from './TransformComponent';
import { createTransformEntity } from './createTransformEntity';
import '../registerComponents';

function generateEntity() {
Expand Down
6 changes: 0 additions & 6 deletions src/foundation/components/Transform/TransformComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,3 @@ export class TransformComponent extends Component {
return base as unknown as ComponentToComponentMethods<SomeComponentClass> & EntityBase;
}
}

export function createTransformEntity(): ITransformEntity {
const entity = EntityRepository.createEntity();
const entity1 = EntityRepository.addComponentToEntity(TransformComponent, entity);
return entity1;
}
12 changes: 12 additions & 0 deletions src/foundation/components/Transform/createTransformEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { EntityRepository } from '../../core/EntityRepository';
import { ITransformEntity } from '../../helpers/EntityHelper';
import { WellKnownComponentTIDs } from '../WellKnownComponentTIDs';

export function createTransformEntity(): ITransformEntity {
const entity = EntityRepository.createEntity();
const entity1 = EntityRepository.tryToAddComponentToEntityByTID(
WellKnownComponentTIDs.TransformComponentTID,
entity
) as ITransformEntity;
return entity1;
}
1 change: 1 addition & 0 deletions src/foundation/components/Transform/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './ITransformEntity';
export * from './TransformComponent';
export * from './createTransformEntity';
2 changes: 1 addition & 1 deletion src/foundation/enhanced_js_objects/Array.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MeshComponent } from '../components/Mesh/MeshComponent';
import { createMeshEntity } from '../components/MeshRenderer/MeshRendererComponent';
import { IEntity } from '../core/Entity';
import { MemoryManager } from '../core/MemoryManager';
import { ArrayAsRn, enhanceArray } from './Array';
import { createMeshEntity } from '../components/MeshRenderer/createMeshEntity';
import '../components/registerComponents';

declare global {
Expand Down
2 changes: 1 addition & 1 deletion src/foundation/gizmos/AABBGizmo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Vector3 } from '../math/Vector3';
import { Mesh } from '../geometry/Mesh';
import { ISceneGraphEntity } from '../helpers/EntityHelper';
import { Is } from '../misc/Is';
import { createMeshEntity } from '../components/MeshRenderer/MeshRendererComponent';
import { createMeshEntity } from '../components/MeshRenderer/createMeshEntity';

/**
* AABB Gizmo class
Expand Down
2 changes: 1 addition & 1 deletion src/foundation/gizmos/LightGizmo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createMeshEntity } from '../components/MeshRenderer/MeshRendererComponent';
import { createMeshEntity } from '../components/MeshRenderer/createMeshEntity';
import { PrimitiveMode } from '../definitions/PrimitiveMode';
import { VertexAttribute } from '../definitions/VertexAttribute';
import { Mesh } from '../geometry/Mesh';
Expand Down
3 changes: 1 addition & 2 deletions src/foundation/gizmos/LocatorGizmo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createMeshEntity } from '../components/MeshRenderer/MeshRendererComponent';
import { Entity } from '../core/Entity';
import { createMeshEntity } from '../components/MeshRenderer/createMeshEntity';
import { PrimitiveMode } from '../definitions/PrimitiveMode';
import { VertexAttribute } from '../definitions/VertexAttribute';
import { Mesh } from '../geometry/Mesh';
Expand Down
2 changes: 1 addition & 1 deletion src/foundation/gizmos/ScaleGizmo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CameraComponent } from '../components/Camera/CameraComponent';
import { createMeshEntity } from '../components/MeshRenderer/MeshRendererComponent';
import { createMeshEntity } from '../components/MeshRenderer/createMeshEntity';
import { createGroupEntity } from '../components/SceneGraph/createGroupEntity';
import { ComponentRepository } from '../core/ComponentRepository';
import { Config } from '../core/Config';
Expand Down
2 changes: 1 addition & 1 deletion src/foundation/gizmos/TranslationGizmo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import {
} from '../system/InputManager';
import { Gizmo } from './Gizmo';
import { IQuaternion } from '../math';
import { createMeshEntity } from '../components/MeshRenderer/MeshRendererComponent';
import { createGroupEntity } from '../components/SceneGraph/createGroupEntity';
import { createMeshEntity } from '../components/MeshRenderer/createMeshEntity';

declare let window: any;

Expand Down
12 changes: 8 additions & 4 deletions src/foundation/helpers/EntityHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { LightComponent } from '../components/Light/LightComponent';
import { IConstraintEntityMethods } from '../components/Constraint/IConstraintEntity';
import { IAnimationStateEntityMethods } from '../components/AnimationState';
import { createGroupEntity } from '../components/SceneGraph/createGroupEntity';
import { WellKnownComponentTIDs } from '../components';

export type ITransformEntity = IEntity & ITransformEntityMethods;
export type ISceneGraphEntity = ITransformEntity & ISceneGraphEntityMethods;
Expand All @@ -32,11 +33,14 @@ export interface IAnimationStateEntity extends ISceneGraphEntity, IAnimationStat

export function createLightWithCameraEntity(): ILightEntity & ICameraEntityMethods {
const entity = createGroupEntity();
const entityAddedComponent = EntityRepository.addComponentToEntity(LightComponent, entity);
const entityAddedComponent2 = EntityRepository.addComponentToEntity(
CameraComponent,
const entityAddedComponent = EntityRepository.tryToAddComponentToEntityByTID(
WellKnownComponentTIDs.LightComponentTID,
entity
) as ILightEntity;
const entityAddedComponent2 = EntityRepository.tryToAddComponentToEntityByTID(
WellKnownComponentTIDs.CameraComponentTID,
entityAddedComponent
);
) as ILightEntity & ICameraEntityMethods;

entityAddedComponent2.getCamera().isSyncToLight = true;

Expand Down
2 changes: 1 addition & 1 deletion src/foundation/helpers/MeshHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { PhysicsComponent } from '../components/Physics/PhysicsComponent';
import { EntityRepository } from '../core/EntityRepository';
import { OimoPhysicsStrategy } from '../physics/Oimo/OimoPhysicsStrategy';
import { PhysicsShape } from '../definitions/PhysicsShapeType';
import { createMeshEntity } from '../components/MeshRenderer/MeshRendererComponent';
import { createMeshEntity } from '../components/MeshRenderer/createMeshEntity';

const createPlane = (
desc: PlaneDescriptor & {
Expand Down
7 changes: 4 additions & 3 deletions src/foundation/importer/ModelConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,18 @@ import {
IMeshEntity,
} from '../helpers/EntityHelper';
import { BlendShapeComponent } from '../components/BlendShape/BlendShapeComponent';
import { createLightEntity, LightComponent } from '../components/Light/LightComponent';
import { LightComponent } from '../components/Light/LightComponent';
import { IBlendShapeEntityMethods } from '../components/BlendShape/IBlendShapeEntity';
import { BufferView } from '../memory/BufferView';
import { RhodoniteImportExtension } from './RhodoniteImportExtension';
import { Vrm0xMaterialProperty } from '../../types/VRM0x';
import { MutableMatrix44 } from '../math/MutableMatrix44';
import { Sampler } from '../textures/Sampler';
import { AnimationStateComponent } from '../components/AnimationState/AnimationStateComponent';
import { createCameraEntity } from '../components/Camera/CameraComponent';
import { createMeshEntity } from '../components/MeshRenderer/MeshRendererComponent';
import { createGroupEntity } from '../components/SceneGraph/createGroupEntity';
import { createMeshEntity } from '../components/MeshRenderer/createMeshEntity';
import { createLightEntity } from '../components/Light/createLightEntity';
import { createCameraEntity } from '../components/Camera/createCameraEntity';

declare let DracoDecoderModule: any;

Expand Down
2 changes: 1 addition & 1 deletion src/foundation/renderer/RenderPass.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMeshEntity } from '../components/MeshRenderer/MeshRendererComponent';
import { MemoryManager } from '../core/MemoryManager';
import { RenderPass } from './RenderPass';
import { createMeshEntity } from '../components/MeshRenderer/createMeshEntity';
import '../components/registerComponents';

function generateEntity() {
Expand Down
3 changes: 2 additions & 1 deletion src/foundation/system/System.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { initDefaultTextures } from '../materials/core/DummyTextures';
import { WebGpuResourceRepository } from '../../webgpu/WebGpuResourceRepository';
import { WebGpuDeviceWrapper } from '../../webgpu/WebGpuDeviceWrapper';
import { WebGpuStrategyBasic } from '../../webgpu/WebGpuStrategyBasic';
import { CameraComponent, createCameraEntity } from '../components/Camera/CameraComponent';
import { CameraComponent } from '../components/Camera/CameraComponent';
import { AnimationComponent } from '../components/Animation/AnimationComponent';
import { CameraControllerComponent } from '../components/CameraController/CameraControllerComponent';
import { MeshRendererComponent } from '../components/MeshRenderer/MeshRendererComponent';
Expand All @@ -38,6 +38,7 @@ import { Primitive } from '../geometry/Primitive';
import { VERSION } from '../../version';
import { ShaderSemantics } from '../definitions/ShaderSemantics';
import { Scalar } from '../math/Scalar';
import { createCameraEntity } from '../components/Camera/createCameraEntity';
declare const spector: any;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/xr/WebARSystem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { createCameraEntity } from '../foundation/components/Camera/CameraComponent';
import { createCameraEntity } from '../foundation/components/Camera/createCameraEntity';
import { ICameraEntity } from '../foundation/helpers/EntityHelper';
import { MutableMatrix44 } from '../foundation/math/MutableMatrix44';
import { MutableQuaternion } from '../foundation/math/MutableQuaternion';
Expand Down
Loading

0 comments on commit cd1d409

Please sign in to comment.