A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
refactor: unify LocalTransform and WorldTransform into single Transform
esengine22e34dba7b24
diff --git a/editor/src/__tests__/store/EditorStore.test.ts b/editor/src/__tests__/store/EditorStore.test.tsindex d09aa7409..38eee3a12 100644--- a/editor/src/__tests__/store/EditorStore.test.ts+++ b/editor/src/__tests__/store/EditorStore.test.ts@@ -417,17 +417,17 @@ describe('EditorStore', () => {it('updateProperties changes multiple properties at once', () => {const entity = store.createEntity('Entity1');- store.addComponent(entity, 'LocalTransform', {+ store.addComponent(entity, 'Transform', {position: { x: 0, y: 0, z: 0 },scale: { x: 1, y: 1, z: 1 },});- store.updateProperties(entity, 'LocalTransform', [+ store.updateProperties(entity, 'Transform', [{ property: 'position', oldValue: { x: 0, y: 0, z: 0 }, newValue: { x: 10, y: 20, z: 0 } },{ property: 'scale', oldValue: { x: 1, y: 1, z: 1 }, newValue: { x: 2, y: 2, z: 2 } },]);- const comp = store.getComponent(entity, 'LocalTransform');+ const comp = store.getComponent(entity, 'Transform');expect(comp!.data.position).toEqual({ x: 10, y: 20, z: 0 });expect(comp!.data.scale).toEqual({ x: 2, y: 2, z: 2 });});diff --git a/editor/src/gizmos/GizmoRegistry.ts b/editor/src/gizmos/GizmoRegistry.tsindex 509f0d148..786533938 100644--- a/editor/src/gizmos/GizmoRegistry.ts+++ b/editor/src/gizmos/GizmoRegistry.ts@@ -1,13 +1,13 @@import type { EditorStore } from '../store/EditorStore';import type { EntityData } from '../types/SceneTypes';-import type { Transform } from '../math/Transform';+import type { TransformValue } from '../math/Transform';export interface GizmoContext {store: EditorStore;ctx: CanvasRenderingContext2D;zoom: number;screenToWorld(clientX: number, clientY: number): { worldX: number; worldY: number };- getWorldTransform(entityId: number): Transform;+ getWorldTransform(entityId: number): TransformValue;getEntityBounds(entityData: EntityData): { width: number; height: number; offsetX?: number; offsetY?: number };requestRender(): void;}diff --git a/editor/src/gizmos/builtinGizmos.ts b/editor/src/gizmos/builtinGizmos.tsindex 8f3b5397e..5787a538e 100644--- a/editor/src/gizmos/builtinGizmos.ts+++ b/editor/src/gizmos/builtinGizmos.ts@@ -170,7 +170,7 @@ export function createMoveGizmo(): GizmoDescriptor {onDragStart(worldX, worldY, hitData, gctx) {dragAxis = hitData as DragAxis;const entityData = gctx.store.getSelectedEntityData();- const transform = entityData?.components.find(c => c.type === 'LocalTransform');+ const transform = entityData?.components.find(c => c.type === 'Transform');if (transform) {const value = transform.data.position as { x: number; y: number; z: number };dragState = {@@ -202,7 +202,7 @@ export function createMoveGizmo(): GizmoDescriptor {newY = Math.round(newY / gridSize) * gridSize;}- gctx.store.updatePropertyDirect(entity, 'LocalTransform', 'position', {+ gctx.store.updatePropertyDirect(entity, 'Transform', 'position', {x: newX, y: newY, z: dragState.startValue.z,});gctx.requestRender();@@ -213,12 +213,12 @@ export function createMoveGizmo(): GizmoDescriptor {if (entity === null || !dragState) { dragState = null; return; }const entityData = gctx.store.getSelectedEntityData();- const transform = entityData?.components.find(c => c.type === 'LocalTransform');+ const transform = entityData?.components.find(c => c.type === 'Transform');if (transform) {const currentValue = transform.data.position;if (currentValue && !valuesEqual(dragState.originalValue, currentValue)) {gctx.store.updateProperty(- entity, 'LocalTransform', 'position',+ entity, 'Transform', 'position',{ ...dragState.originalValue }, deepClone(currentValue),);}@@ -290,7 +290,7 @@ export function createRotateGizmo(): GizmoDescriptor {const radius = size * 0.8;const entityData = gctx.store.getSelectedEntityData();- const transform = entityData?.components.find(c => c.type === 'LocalTransform');+ const transform = entityData?.components.find(c => c.type === 'Transform');const quat = transform?.data.rotation as { x: number; y: number; z: number; w: number } ?? { x: 0, y: 0, z: 0, w: 1 };const euler = quatToEuler(quat);const angleRad = -euler.z * Math.PI / 180;@@ -325,7 +325,7 @@ export function createRotateGizmo(): GizmoDescriptor {onDragStart(worldX, worldY, _hitData, gctx) {const entityData = gctx.store.getSelectedEntityData();- const transform = entityData?.components.find(c => c.type === 'LocalTransform');+ const transform = entityData?.components.find(c => c.type === 'Transform');if (transform) {const quat = transform.data.rotation as { x: number; y: number; z: number; w: number };dragState = {@@ -357,7 +357,7 @@ export function createRotateGizmo(): GizmoDescriptor {const newRotZ = dragState.startEuler.z + deltaAngle;const quat = eulerToQuat({ x: 0, y: 0, z: newRotZ });- gctx.store.updatePropertyDirect(entity, 'LocalTransform', 'rotation', quat);+ gctx.store.updatePropertyDirect(entity, 'Transform', 'rotation', quat);gctx.requestRender();},@@ -366,12 +366,12 @@ export function createRotateGizmo(): GizmoDescriptor {if (entity === null || !dragState) { dragState = null; return; }const entityData = gctx.store.getSelectedEntityData();- const transform = entityData?.components.find(c => c.type === 'LocalTransform');+ const transform = entityData?.components.find(c => c.type === 'Transform');if (transform) {const currentValue = transform.data.rotation;if (currentValue && !valuesEqual(dragState.originalQuat, currentValue)) {gctx.store.updateProperty(- entity, 'LocalTransform', 'rotation',+ entity, 'Transform', 'rotation',{ ...dragState.originalQuat }, deepClone(currentValue),);}@@ -477,7 +477,7 @@ export function createScaleGizmo(): GizmoDescriptor {onDragStart(worldX, worldY, hitData, gctx) {dragAxis = hitData as DragAxis;const entityData = gctx.store.getSelectedEntityData();- const transform = entityData?.components.find(c => c.type === 'LocalTransform');+ const transform = entityData?.components.find(c => c.type === 'Transform');if (transform) {const value = transform.data.scale as { x: number; y: number; z: number };dragState = {@@ -503,7 +503,7 @@ export function createScaleGizmo(): GizmoDescriptor {if (dragAxis === 'x' || dragAxis === 'xy') newX += dx * scaleFactor;if (dragAxis === 'y' || dragAxis === 'xy') newY += dy * scaleFactor;- gctx.store.updatePropertyDirect(entity, 'LocalTransform', 'scale', {+ gctx.store.updatePropertyDirect(entity, 'Transform', 'scale', {x: Math.max(0.01, newX), y: Math.max(0.01, newY), z: dragState.startValue.z,});gctx.requestRender();@@ -514,12 +514,12 @@ export function createScaleGizmo(): GizmoDescriptor {if (entity === null || !dragState) { dragState = null; return; }const entityData = gctx.store.getSelectedEntityData();- const transform = entityData?.components.find(c => c.type === 'LocalTransform');+ const transform = entityData?.components.find(c => c.type === 'Transform');if (transform) {const currentValue = transform.data.scale;if (currentValue && !valuesEqual(dragState.originalValue, currentValue)) {gctx.store.updateProperty(- entity, 'LocalTransform', 'scale',+ entity, 'Transform', 'scale',{ ...dragState.originalValue }, deepClone(currentValue),);}@@ -674,7 +674,7 @@ export function createRectGizmo(): GizmoDescriptor {const entityData = gctx.store.getSelectedEntityData();if (!entityData) return;- const transform = entityData.components.find(c => c.type === 'LocalTransform');+ const transform = entityData.components.find(c => c.type === 'Transform');const pos = transform?.data.position as { x: number; y: number; z: number } ?? { x: 0, y: 0, z: 0 };const sizeType = getSizeComponentType(entityData);@@ -731,10 +731,10 @@ export function createRectGizmo(): GizmoDescriptor {gctx.store.updatePropertyDirect(entity, sizeType, 'size', { x: newWidth, y: newHeight });}- const transform = entityData.components.find(c => c.type === 'LocalTransform');+ const transform = entityData.components.find(c => c.type === 'Transform');if (transform) {const pos = transform.data.position as { x: number; y: number; z: number };- gctx.store.updatePropertyDirect(entity, 'LocalTransform', 'position', {+ gctx.store.updatePropertyDirect(entity, 'Transform', 'position', {x: newPosX, y: newPosY, z: pos?.z ?? 0,});}@@ -761,12 +761,12 @@ export function createRectGizmo(): GizmoDescriptor {}}- const transform = entityData.components.find(c => c.type === 'LocalTransform');+ const transform = entityData.components.find(c => c.type === 'Transform');if (transform) {const currentPos = transform.data.position as { x: number; y: number; z: number };if (currentPos && !valuesEqual(dragState.originalPos, currentPos)) {gctx.store.updateProperty(- entity, 'LocalTransform', 'position',+ entity, 'Transform', 'position',{ ...dragState.originalPos }, { ...currentPos },);}diff --git a/editor/src/index.ts b/editor/src/index.tsindex 217d5c587..061929e93 100644--- a/editor/src/index.ts+++ b/editor/src/index.ts@@ -156,7 +156,7 @@ export {export {type ComponentSchema,- LocalTransformSchema,+ TransformSchema,SpriteSchema,CameraSchema,TextSchema,@@ -253,7 +253,7 @@ export { AssetPathResolver, getGlobalPathResolver, getAssetDatabase } from './as// Math// =============================================================================-export { quatToEuler, eulerToQuat, type Transform } from './math/Transform';+export { quatToEuler, eulerToQuat, type TransformValue } from './math/Transform';// =============================================================================// Content Browserdiff --git a/editor/src/io/SceneSerializer.ts b/editor/src/io/SceneSerializer.tsindex c86bb4b38..cfbd5e8f0 100644--- a/editor/src/io/SceneSerializer.ts+++ b/editor/src/io/SceneSerializer.ts@@ -64,10 +64,10 @@ export class SceneSerializer {entity.components = [];}- if (!entity.components.some(c => c.type === 'LocalTransform')) {+ if (!entity.components.some(c => c.type === 'Transform')) {entity.components.unshift({- type: 'LocalTransform',- data: getDefaultComponentData('LocalTransform'),+ type: 'Transform',+ data: getDefaultComponentData('Transform'),});}diff --git a/editor/src/launcher/ProjectService.ts b/editor/src/launcher/ProjectService.tsindex 497b51caa..6218b2d71 100644--- a/editor/src/launcher/ProjectService.ts+++ b/editor/src/launcher/ProjectService.ts@@ -358,7 +358,7 @@ function createDefaultScene(children: [],components: [{- type: 'LocalTransform',+ type: 'Transform',data: {position: { x: 0, y: 0, z: 10 },rotation: { x: 0, y: 0, z: 0, w: 1 },@@ -391,7 +391,7 @@ function createDefaultScene(children: [],components: [{- type: 'LocalTransform',+ type: 'Transform',data: {position: { x: 0, y: 0, z: 0 },rotation: { x: 0, y: 0, z: 0, w: 1 },diff --git a/editor/src/math/Transform.ts b/editor/src/math/Transform.tsindex ae2992879..1fad424b1 100644--- a/editor/src/math/Transform.ts+++ b/editor/src/math/Transform.ts@@ -22,7 +22,7 @@ export interface Quat {w: number;}-export interface Transform {+export interface TransformValue {position: Vec3;rotation: Quat;scale: Vec3;@@ -32,7 +32,7 @@ export interface Transform {// Constants// =============================================================================-export const IDENTITY_TRANSFORM: Readonly<Transform> = Object.freeze({+export const IDENTITY_TRANSFORM_VALUE: Readonly<TransformValue> = Object.freeze({position: Object.freeze({ x: 0, y: 0, z: 0 }),rotation: Object.freeze({ x: 0, y: 0, z: 0, w: 1 }),scale: Object.freeze({ x: 1, y: 1, z: 1 }),@@ -132,7 +132,7 @@ export function eulerToQuat(euler: Vec3): Quat {/*** @brief Compose parent and child transforms: worldChild = worldParent * localChild*/-export function composeTransforms(parent: Transform, child: Transform): Transform {+export function composeTransforms(parent: TransformValue, child: TransformValue): TransformValue {const rotatedPos = rotateVector(child.position, parent.rotation);return {@@ -153,7 +153,7 @@ export function composeTransforms(parent: Transform, child: Transform): Transfor/*** @brief Create a copy of an identity transform*/-export function createIdentityTransform(): Transform {+export function createIdentityTransform(): TransformValue {return {position: { x: 0, y: 0, z: 0 },rotation: { x: 0, y: 0, z: 0, w: 1 },@@ -164,7 +164,7 @@ export function createIdentityTransform(): Transform {/*** @brief Clone a transform*/-export function cloneTransform(t: Transform): Transform {+export function cloneTransform(t: TransformValue): TransformValue {return {position: { ...t.position },rotation: { ...t.rotation },@@ -182,16 +182,16 @@ export interface EntityDataLike {children: number[];}-export function getLocalTransformFromEntity(entity: EntityDataLike): Transform {- const comp = entity.components.find(c => c.type === 'LocalTransform');+export function getTransformFromEntity(entity: EntityDataLike): TransformValue {+ const comp = entity.components.find(c => c.type === 'Transform');if (!comp) {return createIdentityTransform();}return {- position: (comp.data.position as Vec3) ?? IDENTITY_TRANSFORM.position,- rotation: (comp.data.rotation as Quat) ?? IDENTITY_TRANSFORM.rotation,- scale: (comp.data.scale as Vec3) ?? IDENTITY_TRANSFORM.scale,+ position: (comp.data.position as Vec3) ?? IDENTITY_TRANSFORM_VALUE.position,+ rotation: (comp.data.rotation as Quat) ?? IDENTITY_TRANSFORM_VALUE.rotation,+ scale: (comp.data.scale as Vec3) ?? IDENTITY_TRANSFORM_VALUE.scale,};}@@ -285,7 +285,7 @@ export function findCanvasWorldRect(allEntities: EntityDataLike[]): LayoutRect |}const camera = e.components.find(c => c.type === 'Camera');if (camera) {- const lt = e.components.find(c => c.type === 'LocalTransform');+ const lt = e.components.find(c => c.type === 'Transform');if (lt?.data?.position) {const pos = lt.data.position as { x: number; y: number };cameraPos = { x: pos.x, y: pos.y };@@ -309,8 +309,8 @@ function computeScreenSpaceTransform(entity: EntityDataLike,getParentEntity: (id: number) => EntityDataLike | undefined,canvasRect: LayoutRect,-): Transform {- const localTransform = getLocalTransformFromEntity(entity);+): TransformValue {+ const localTransform = getTransformFromEntity(entity);const path: EntityDataLike[] = [];let cur: EntityDataLike | undefined = entity;@@ -332,7 +332,7 @@ function computeScreenSpaceTransform(const node = path[i];const uiRect = getUIRectFromEntity(node);if (!uiRect) {- const lt = getLocalTransformFromEntity(node);+ const lt = getTransformFromEntity(node);resultX = lt.position.x;resultY = lt.position.y;continue;@@ -341,7 +341,7 @@ function computeScreenSpaceTransform(const layout = computeUIRectLayout(uiRect.anchorMin, uiRect.anchorMax,uiRect.offsetMin, uiRect.offsetMax,- uiRect.size, parentRect,+ uiRect.size, parentRect, uiRect.pivot,);const isRoot = i === 0;@@ -399,7 +399,7 @@ export function computeAdjustedLocalTransform(getParentEntity: (id: number) => EntityDataLike | undefined,allEntities?: EntityDataLike[],cachedCanvasRect?: LayoutRect | null,-): Transform {+): TransformValue {if (isInScreenSpaceHierarchy(entity, getParentEntity)) {const canvasRect = cachedCanvasRect?? (allEntities ? findCanvasWorldRect(allEntities) : null);@@ -408,7 +408,7 @@ export function computeAdjustedLocalTransform(}}- const localTransform = getLocalTransformFromEntity(entity);+ const localTransform = getTransformFromEntity(entity);const uiRect = getUIRectFromEntity(entity);const size = getEntitySize(entity);@@ -437,7 +437,7 @@ export function computeAdjustedLocalTransform(// Matrix Conversion// =============================================================================-export function transformToMatrix4x4(t: Transform): Float32Array {+export function transformToMatrix4x4(t: TransformValue): Float32Array {const { x: qx, y: qy, z: qz, w: qw } = t.rotation;const { x: sx, y: sy, z: sz } = t.scale;const { x: tx, y: ty, z: tz } = t.position;diff --git a/editor/src/panels/hierarchy/HierarchyContextMenu.ts b/editor/src/panels/hierarchy/HierarchyContextMenu.tsindex 2134aeb2a..0f5a381b4 100644--- a/editor/src/panels/hierarchy/HierarchyContextMenu.ts+++ b/editor/src/panels/hierarchy/HierarchyContextMenu.ts@@ -23,7 +23,7 @@ export function showEntityContextMenu(state: HierarchyState, x: number, y: numbeconst createChildren: ContextMenuItem[] = [{ label: 'Empty Entity', icon: icons.plus(14), onClick: () => {const newEntity = state.store.createEntity(undefined, entity);- state.store.addComponent(newEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(newEntity, 'Transform', getInitialComponentData('Transform'));} },{ label: 'Sprite', icon: icons.image(14), onClick: () => createEntityWithComponent(state, 'Sprite', entity) },{ label: 'Text', icon: icons.type(14), onClick: () => createEntityWithComponent(state, 'Text', entity) },@@ -184,7 +184,7 @@ export function showEntityContextMenu(state: HierarchyState, x: number, y: numbefunction createEntityWithComponent(state: HierarchyState, componentType: string, parent: Entity | null): void {const newEntity = state.store.createEntity(componentType, parent);- state.store.addComponent(newEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(newEntity, 'Transform', getInitialComponentData('Transform'));if (componentType === 'Text') {state.store.addComponent(newEntity, 'UIRect', getInitialComponentData('UIRect'));@@ -195,14 +195,14 @@ function createEntityWithComponent(state: HierarchyState, componentType: string,function createPhysicsEntity(state: HierarchyState, colliderType: string, parent: Entity | null): void {const newEntity = state.store.createEntity(colliderType, parent);- state.store.addComponent(newEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(newEntity, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(newEntity, 'RigidBody', getInitialComponentData('RigidBody'));state.store.addComponent(newEntity, colliderType, getInitialComponentData(colliderType));}function createButtonEntity(state: HierarchyState, parent: Entity | null): void {const newEntity = state.store.createEntity('Button', parent);- state.store.addComponent(newEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(newEntity, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(newEntity, 'Sprite', getInitialComponentData('Sprite'));state.store.addComponent(newEntity, 'UIRect', getInitialComponentData('UIRect'));state.store.addComponent(newEntity, 'Interactable', getInitialComponentData('Interactable'));@@ -211,7 +211,7 @@ function createButtonEntity(state: HierarchyState, parent: Entity | null): voidfunction createTextInputEntity(state: HierarchyState, parent: Entity | null): void {const newEntity = state.store.createEntity('TextInput', parent);- state.store.addComponent(newEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(newEntity, 'Transform', getInitialComponentData('Transform'));const tiDefaults = getInitialComponentData('TextInput');state.store.addComponent(newEntity, 'Sprite', {...getInitialComponentData('Sprite'),@@ -228,7 +228,7 @@ function createTextInputEntity(state: HierarchyState, parent: Entity | null): vofunction createPanelEntity(state: HierarchyState, parent: Entity | null): void {const newEntity = state.store.createEntity('Panel', parent);- state.store.addComponent(newEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(newEntity, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(newEntity, 'Sprite', getInitialComponentData('Sprite'));state.store.addComponent(newEntity, 'UIRect', getInitialComponentData('UIRect'));state.store.addComponent(newEntity, 'UIMask', getInitialComponentData('UIMask'));@@ -236,7 +236,7 @@ function createPanelEntity(state: HierarchyState, parent: Entity | null): void {function createScreenSpaceRootEntity(state: HierarchyState, parent: Entity | null): void {const newEntity = state.store.createEntity('ScreenSpace Root', parent);- state.store.addComponent(newEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(newEntity, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(newEntity, 'UIRect', {...getInitialComponentData('UIRect'),anchorMin: { x: 0, y: 0 },@@ -247,7 +247,7 @@ function createScreenSpaceRootEntity(state: HierarchyState, parent: Entity | nulfunction createImageEntity(state: HierarchyState, parent: Entity | null): void {const newEntity = state.store.createEntity('Image', parent);- state.store.addComponent(newEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(newEntity, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(newEntity, 'Sprite', getInitialComponentData('Sprite'));state.store.addComponent(newEntity, 'UIRect', getInitialComponentData('UIRect'));state.store.addComponent(newEntity, 'Image', getInitialComponentData('Image'));@@ -255,7 +255,7 @@ function createImageEntity(state: HierarchyState, parent: Entity | null): void {function createToggleEntity(state: HierarchyState, parent: Entity | null): void {const toggleEntity = state.store.createEntity('Toggle', parent);- state.store.addComponent(toggleEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(toggleEntity, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(toggleEntity, 'Sprite', {...getInitialComponentData('Sprite'),size: { x: 24, y: 24 },@@ -267,7 +267,7 @@ function createToggleEntity(state: HierarchyState, parent: Entity | null): voidstate.store.addComponent(toggleEntity, 'Interactable', getInitialComponentData('Interactable'));const checkmark = state.store.createEntity('Checkmark', toggleEntity);- state.store.addComponent(checkmark, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(checkmark, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(checkmark, 'Sprite', {...getInitialComponentData('Sprite'),size: { x: 16, y: 16 },@@ -286,7 +286,7 @@ function createToggleEntity(state: HierarchyState, parent: Entity | null): voidfunction createProgressBarEntity(state: HierarchyState, parent: Entity | null): void {const barEntity = state.store.createEntity('ProgressBar', parent);- state.store.addComponent(barEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(barEntity, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(barEntity, 'Sprite', {...getInitialComponentData('Sprite'),size: { x: 200, y: 20 },@@ -298,7 +298,7 @@ function createProgressBarEntity(state: HierarchyState, parent: Entity | null):});const fill = state.store.createEntity('Fill', barEntity);- state.store.addComponent(fill, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(fill, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(fill, 'Sprite', {...getInitialComponentData('Sprite'),size: { x: 200, y: 20 },@@ -321,7 +321,7 @@ function createProgressBarEntity(state: HierarchyState, parent: Entity | null):function createScrollViewEntity(state: HierarchyState, parent: Entity | null): void {const scrollEntity = state.store.createEntity('ScrollView', parent);- state.store.addComponent(scrollEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(scrollEntity, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(scrollEntity, 'Sprite', {...getInitialComponentData('Sprite'),size: { x: 300, y: 200 },@@ -334,7 +334,7 @@ function createScrollViewEntity(state: HierarchyState, parent: Entity | null): vstate.store.addComponent(scrollEntity, 'Interactable', getInitialComponentData('Interactable'));const content = state.store.createEntity('Content', scrollEntity);- state.store.addComponent(content, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(content, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(content, 'UIRect', {...getInitialComponentData('UIRect'),anchorMin: { x: 0, y: 0 },@@ -352,7 +352,7 @@ function createScrollViewEntity(state: HierarchyState, parent: Entity | null): vfunction createSliderEntity(state: HierarchyState, parent: Entity | null): void {const sliderEntity = state.store.createEntity('Slider', parent);- state.store.addComponent(sliderEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(sliderEntity, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(sliderEntity, 'Sprite', {...getInitialComponentData('Sprite'),size: { x: 200, y: 8 },@@ -365,7 +365,7 @@ function createSliderEntity(state: HierarchyState, parent: Entity | null): voidstate.store.addComponent(sliderEntity, 'Interactable', getInitialComponentData('Interactable'));const fill = state.store.createEntity('Fill', sliderEntity);- state.store.addComponent(fill, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(fill, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(fill, 'Sprite', {...getInitialComponentData('Sprite'),size: { x: 200, y: 8 },@@ -380,7 +380,7 @@ function createSliderEntity(state: HierarchyState, parent: Entity | null): void});const handle = state.store.createEntity('Handle', sliderEntity);- state.store.addComponent(handle, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(handle, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(handle, 'Sprite', {...getInitialComponentData('Sprite'),size: { x: 20, y: 20 },@@ -401,7 +401,7 @@ function createSliderEntity(state: HierarchyState, parent: Entity | null): voidfunction createDropdownEntity(state: HierarchyState, parent: Entity | null): void {const ddEntity = state.store.createEntity('Dropdown', parent);- state.store.addComponent(ddEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(ddEntity, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(ddEntity, 'Sprite', {...getInitialComponentData('Sprite'),size: { x: 160, y: 32 },@@ -413,7 +413,7 @@ function createDropdownEntity(state: HierarchyState, parent: Entity | null): voistate.store.addComponent(ddEntity, 'Interactable', getInitialComponentData('Interactable'));const label = state.store.createEntity('Label', ddEntity);- state.store.addComponent(label, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(label, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(label, 'UIRect', {...getInitialComponentData('UIRect'),anchorMin: { x: 0, y: 0 },@@ -427,8 +427,8 @@ function createDropdownEntity(state: HierarchyState, parent: Entity | null): voi});const list = state.store.createEntity('List', ddEntity);- state.store.addComponent(list, 'LocalTransform', {- ...getInitialComponentData('LocalTransform'),+ state.store.addComponent(list, 'Transform', {+ ...getInitialComponentData('Transform'),scale: { x: 0, y: 0, z: 0 },});state.store.addComponent(list, 'Sprite', {@@ -550,7 +550,7 @@ export async function createEntityFromAsset(const newEntity = state.store.createEntity(baseName, parent);- state.store.addComponent(newEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(newEntity, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(newEntity, 'SpineAnimation', {...getInitialComponentData('SpineAnimation'),@@ -560,7 +560,7 @@ export async function createEntityFromAsset(} else if (asset.type === 'image') {const newEntity = state.store.createEntity(baseName, parent);- state.store.addComponent(newEntity, 'LocalTransform', getInitialComponentData('LocalTransform'));+ state.store.addComponent(newEntity, 'Transform', getInitialComponentData('Transform'));state.store.addComponent(newEntity, 'Sprite', {...getInitialComponentData('Sprite'),diff --git a/editor/src/panels/inspector/InspectorHelpers.ts b/editor/src/panels/inspector/InspectorHelpers.tsindex 87b51e599..11a83ad7e 100644--- a/editor/src/panels/inspector/InspectorHelpers.ts+++ b/editor/src/panels/inspector/InspectorHelpers.ts@@ -123,8 +123,7 @@ export function getAssetServer(): EditorAssetServer | null {}const COMPONENT_ICON_MAP = new Map<string, (size: number) => string>([- ['LocalTransform', icons.move],- ['WorldTransform', icons.move],+ ['Transform', icons.move],['Sprite', icons.image],['NinePatch', icons.image],['Camera', icons.camera],diff --git a/editor/src/panels/scene-view/EntityDropHandler.ts b/editor/src/panels/scene-view/EntityDropHandler.tsindex 72d7f78a1..f29994b1e 100644--- a/editor/src/panels/scene-view/EntityDropHandler.ts+++ b/editor/src/panels/scene-view/EntityDropHandler.ts@@ -48,9 +48,9 @@ export class EntityDropHandler {const baseName = asset.name.replace(/\.[^.]+$/, '');const newEntity = this.store_.createEntity(baseName);- const transformData = getInitialComponentData('LocalTransform');+ const transformData = getInitialComponentData('Transform');transformData.position = { x: worldX, y: worldY, z: 0 };- this.store_.addComponent(newEntity, 'LocalTransform', transformData);+ this.store_.addComponent(newEntity, 'Transform', transformData);const relativePath = getGlobalPathResolver().toRelativePath(asset.path);this.store_.addComponent(newEntity, 'Sprite', {diff --git a/editor/src/panels/scene-view/MarqueeSelection.ts b/editor/src/panels/scene-view/MarqueeSelection.tsindex d7f9402a3..2fd11dc65 100644--- a/editor/src/panels/scene-view/MarqueeSelection.ts+++ b/editor/src/panels/scene-view/MarqueeSelection.ts@@ -48,7 +48,7 @@ export class MarqueeSelection {for (const entity of scene.entities) {if (!store.isEntityVisible(entity.id)) continue;- const transform = entity.components.find(c => c.type === 'LocalTransform');+ const transform = entity.components.find(c => c.type === 'Transform');if (!transform) continue;const worldTransform = store.getWorldTransform(entity.id);diff --git a/editor/src/panels/scene-view/SceneViewInput.ts b/editor/src/panels/scene-view/SceneViewInput.tsindex 300dc9355..da7e11785 100644--- a/editor/src/panels/scene-view/SceneViewInput.ts+++ b/editor/src/panels/scene-view/SceneViewInput.ts@@ -337,7 +337,7 @@ export class SceneViewInput {const entity = scene.entities[i];if (!store.isEntityVisible(entity.id)) continue;- const transform = entity.components.find(c => c.type === 'LocalTransform');+ const transform = entity.components.find(c => c.type === 'Transform');if (!transform) continue;const worldTransform = store.getWorldTransform(entity.id);diff --git a/editor/src/schemas/ComponentSchemas.ts b/editor/src/schemas/ComponentSchemas.tsindex f44eafa03..a2c4f1403 100644--- a/editor/src/schemas/ComponentSchemas.ts+++ b/editor/src/schemas/ComponentSchemas.ts@@ -53,8 +53,8 @@ function inferPropertyType(value: unknown): string {// Built-in Schemas// =============================================================================-export const LocalTransformSchema: ComponentSchema = {- name: 'LocalTransform',+export const TransformSchema: ComponentSchema = {+ name: 'Transform',category: 'builtin',removable: false,properties: [@@ -71,7 +71,7 @@ export const SpriteSchema: ComponentSchema = {{ name: 'texture', type: 'texture' },{ name: 'material', type: 'material-file' },{ name: 'color', type: 'color' },- { name: 'size', type: 'vec2' },+ { name: 'size', type: 'vec2', hiddenWhen: { hasComponent: 'UIRect' } },{ name: 'uvOffset', type: 'vec2' },{ name: 'uvScale', type: 'vec2' },{ name: 'layer', type: 'number', min: -1000, max: 1000 },@@ -217,8 +217,8 @@ export const UIMaskSchema: ComponentSchema = {name: 'mode',type: 'enum',options: [- { label: 'Scissor', value: 'scissor' },- { label: 'Stencil', value: 'stencil' },+ { label: 'Scissor', value: 0 },+ { label: 'Stencil', value: 1 },],},],@@ -514,6 +514,66 @@ export const DropdownSchema: ComponentSchema = {],};+export const FlexContainerSchema: ComponentSchema = {+ name: 'FlexContainer',+ category: 'ui',+ properties: [+ {+ name: 'direction',+ type: 'enum',+ options: [+ { label: 'Row', value: 0 },+ { label: 'Column', value: 1 },+ { label: 'RowReverse', value: 2 },+ { label: 'ColumnReverse', value: 3 },+ ],+ },+ {+ name: 'wrap',+ type: 'enum',+ options: [+ { label: 'NoWrap', value: 0 },+ { label: 'Wrap', value: 1 },+ ],+ },+ {+ name: 'justifyContent',+ type: 'enum',+ options: [+ { label: 'Start', value: 0 },+ { label: 'Center', value: 1 },+ { label: 'End', value: 2 },+ { label: 'SpaceBetween', value: 3 },+ { label: 'SpaceAround', value: 4 },+ { label: 'SpaceEvenly', value: 5 },+ ],+ },+ {+ name: 'alignItems',+ type: 'enum',+ options: [+ { label: 'Start', value: 0 },+ { label: 'Center', value: 1 },+ { label: 'End', value: 2 },+ { label: 'Stretch', value: 3 },+ ],+ },+ { name: 'gap', type: 'vec2' },+ { name: 'padding', type: 'vec4' },+ ],+};++export const FlexItemSchema: ComponentSchema = {+ name: 'FlexItem',+ category: 'ui',+ properties: [+ { name: 'flexGrow', type: 'number', min: 0, step: 0.1 },+ { name: 'flexShrink', type: 'number', min: 0, step: 0.1 },+ { name: 'flexBasis', type: 'number', step: 1 },+ { name: 'order', type: 'number', step: 1 },+ ],+};+export const LayoutGroupSchema: ComponentSchema = {name: 'LayoutGroup',category: 'ui',@@ -646,7 +706,7 @@ export interface BuiltinSchemaOptions {export function registerBuiltinSchemas(options?: BuiltinSchemaOptions): void {const enableSpine = options?.enableSpine ?? true;- registerComponentSchema(LocalTransformSchema);+ registerComponentSchema(TransformSchema);registerComponentSchema(SpriteSchema);registerComponentSchema(CameraSchema);registerComponentSchema(TextSchema);@@ -668,6 +728,8 @@ export function registerBuiltinSchemas(options?: BuiltinSchemaOptions): void {registerComponentSchema(SafeAreaSchema);registerComponentSchema(ListViewSchema);registerComponentSchema(DropdownSchema);+ registerComponentSchema(FlexContainerSchema);+ registerComponentSchema(FlexItemSchema);registerComponentSchema(LayoutGroupSchema);registerComponentSchema(RigidBodySchema);registerComponentSchema(BoxColliderSchema);diff --git a/editor/src/schemas/index.ts b/editor/src/schemas/index.tsindex b7f4ad958..32bd68901 100644--- a/editor/src/schemas/index.ts+++ b/editor/src/schemas/index.ts@@ -5,7 +5,7 @@export {type ComponentSchema,- LocalTransformSchema,+ TransformSchema,SpriteSchema,CameraSchema,TextSchema,diff --git a/editor/src/store/SceneOperations.ts b/editor/src/store/SceneOperations.tsindex 169cff294..bd8bad9d2 100644--- a/editor/src/store/SceneOperations.ts+++ b/editor/src/store/SceneOperations.ts@@ -251,7 +251,7 @@ export class SceneOperations {component.data[propertyName] = newValue;this.host_.state_.isDirty = true;- if (componentType === 'LocalTransform') {+ if (componentType === 'Transform') {this.host_.worldTransforms_.updateEntity(entityData);this.host_.worldTransforms_.markDirty(entity as number);}diff --git a/editor/src/transform/WorldTransformCache.ts b/editor/src/transform/WorldTransformCache.tsindex 68effcff6..3826d2f38 100644--- a/editor/src/transform/WorldTransformCache.ts+++ b/editor/src/transform/WorldTransformCache.ts@@ -5,7 +5,7 @@import type { SceneData, EntityData } from '../types/SceneTypes';import {- Transform,+ type TransformValue,composeTransforms,createIdentityTransform,computeAdjustedLocalTransform,@@ -16,13 +16,15 @@ import {// =============================================================================export class WorldTransformCache {- private cache_ = new Map<number, Transform>();+ private cache_ = new Map<number, TransformValue>();private dirty_ = new Set<number>();private entityMap_ = new Map<number, EntityData>();+ private cppWorldTransformProvider_: ((entityId: number) => TransformValue | null) | null = null;++ setCppWorldTransformProvider(provider: ((entityId: number) => TransformValue | null) | null): void {+ this.cppWorldTransformProvider_ = provider;+ }- /**- * @brief Set scene data and rebuild entity index- */setScene(scene: SceneData): void {this.entityMap_.clear();this.cache_.clear();@@ -61,7 +63,12 @@ export class WorldTransformCache {/*** @brief Get world transform for an entity (uses cache)*/- getWorldTransform(entityId: number): Transform {+ getWorldTransform(entityId: number): TransformValue {+ if (this.cppWorldTransformProvider_) {+ const cppTransform = this.cppWorldTransformProvider_(entityId);+ if (cppTransform) return cppTransform;+ }+if (!this.dirty_.has(entityId) && this.cache_.has(entityId)) {return this.cache_.get(entityId)!;}@@ -120,7 +127,7 @@ export class WorldTransformCache {}}- private computeWorldTransform(entityId: number): Transform {+ private computeWorldTransform(entityId: number): TransformValue {const entity = this.entityMap_.get(entityId);if (!entity) {return createIdentityTransform();diff --git a/editor/src/types/SceneTypes.ts b/editor/src/types/SceneTypes.tsindex b938d452e..1175c7024 100644--- a/editor/src/types/SceneTypes.ts+++ b/editor/src/types/SceneTypes.ts@@ -74,7 +74,7 @@ export function createEmptyScene(children: [],components: [{- type: 'LocalTransform',+ type: 'Transform',data: {position: { x: 0, y: 0, z: 10 },rotation: { x: 0, y: 0, z: 0, w: 1 },@@ -108,7 +108,7 @@ export function createEmptyScene(children: [],components: [{- type: 'LocalTransform',+ type: 'Transform',data: {position: { x: 0, y: 0, z: 0 },rotation: { x: 0, y: 0, z: 0, w: 1 },diff --git a/sdk/esengine.d.ts b/sdk/esengine.d.tsindex e6866a0be..1cf2b558f 100644--- a/sdk/esengine.d.ts+++ b/sdk/esengine.d.ts@@ -71,16 +71,13 @@ export interface Sprite {flipY: boolean;}-export interface LocalTransform {- position: Vec3;- rotation: Quat;- scale: Vec3;-}--export interface WorldTransform {+export interface Transform {position: Vec3;rotation: Quat;scale: Vec3;+ worldPosition: Vec3;+ worldRotation: Quat;+ worldScale: Vec3;}export interface Velocity {@@ -115,14 +112,10 @@ export interface Registry {getSprite(entity: Entity): Sprite;addSprite(entity: Entity, component: Sprite): void;removeSprite(entity: Entity): void;- hasLocalTransform(entity: Entity): boolean;- getLocalTransform(entity: Entity): LocalTransform;- addLocalTransform(entity: Entity, component: LocalTransform): void;- removeLocalTransform(entity: Entity): void;- hasWorldTransform(entity: Entity): boolean;- getWorldTransform(entity: Entity): WorldTransform;- addWorldTransform(entity: Entity, component: WorldTransform): void;- removeWorldTransform(entity: Entity): void;+ hasTransform(entity: Entity): boolean;+ getTransform(entity: Entity): Transform;+ addTransform(entity: Entity, component: Transform): void;+ removeTransform(entity: Entity): void;hasVelocity(entity: Entity): boolean;getVelocity(entity: Entity): Velocity;addVelocity(entity: Entity, component: Velocity): void;@@ -146,8 +139,7 @@ export interface ESEngineModule {Parent: new () => Parent;Children: new () => Children;Sprite: new () => Sprite;- LocalTransform: new () => LocalTransform;- WorldTransform: new () => WorldTransform;+ Transform: new () => Transform;Velocity: new () => Velocity;// Renderer functionsdiff --git a/sdk/src/component.ts b/sdk/src/component.tsindex 98a690af9..556791f85 100644--- a/sdk/src/component.ts+++ b/sdk/src/component.ts@@ -37,18 +37,30 @@ function deepClone<T>(value: T): T {let componentCounter = 0;+function hasNestedObjects(obj: object): boolean {+ for (const key in obj) {+ const val = (obj as Record<string, unknown>)[key];+ if (val !== null && typeof val === 'object') return true;+ }+ return false;+}+function createComponentDef<T extends object>(name: string,defaults: T): ComponentDef<T> {const id = ++componentCounter;+ const needsDeepClone = hasNestedObjects(defaults);return {_id: Symbol(`Component_${id}_${name}`),_name: name,_default: defaults,_builtin: false as const,create(data?: Partial<T>): T {- return data ? { ...deepClone(defaults), ...data } : deepClone(defaults);+ if (needsDeepClone) {+ return data ? { ...deepClone(defaults), ...data } : deepClone(defaults);+ }+ return data ? { ...defaults, ...data } : { ...defaults };}};}@@ -194,17 +206,17 @@ export type ScaleMode = (typeof ScaleMode)[keyof typeof ScaleMode];// Builtin Component Types// =============================================================================-export interface LocalTransformData {+export interface TransformData {position: Vec3;rotation: Quat;scale: Vec3;+ worldPosition: Vec3;+ worldRotation: Quat;+ worldScale: Vec3;}-export interface WorldTransformData {- position: Vec3;- rotation: Quat;- scale: Vec3;-}+export type LocalTransformData = TransformData;+export type WorldTransformData = TransformData;export interface SpriteData {texture: number;@@ -228,6 +240,7 @@ export interface CameraData {aspectRatio: number;isActive: boolean;priority: number;+ /** Editor-only: not synced to C++ Camera component, used for gizmo rendering */showFrustum: boolean;viewportX: number;viewportY: number;@@ -298,17 +311,16 @@ export interface SceneOwnerData {// Builtin Component Instances// =============================================================================-export const LocalTransform = defineBuiltin<LocalTransformData>('LocalTransform', {+export const Transform = defineBuiltin<TransformData>('Transform', {position: { x: 0, y: 0, z: 0 },rotation: { w: 1, x: 0, y: 0, z: 0 },- scale: { x: 1, y: 1, z: 1 }-});--export const WorldTransform = defineBuiltin<WorldTransformData>('WorldTransform', {- position: { x: 0, y: 0, z: 0 },- rotation: { w: 1, x: 0, y: 0, z: 0 },- scale: { x: 1, y: 1, z: 1 }+ scale: { x: 1, y: 1, z: 1 },+ worldPosition: { x: 0, y: 0, z: 0 },+ worldRotation: { w: 1, x: 0, y: 0, z: 0 },+ worldScale: { x: 1, y: 1, z: 1 },});+export const LocalTransform = Transform;+export const WorldTransform = Transform;export const Sprite = defineBuiltin<SpriteData>('Sprite', {texture: INVALID_TEXTURE,@@ -389,15 +401,7 @@ export const SpineAnimation = defineBuiltin<SpineAnimationData>('SpineAnimation'enabled: true});-export const Name: ComponentDef<NameData> = {- _id: Symbol('Component_Name'),- _name: 'Name',- _default: { value: '' },- _builtin: false as const,- create(data?: Partial<NameData>): NameData {- return { value: '', ...data };- }-};+export const Name = defineComponent<NameData>('Name', { value: '' });export const SceneOwner = defineComponent<SceneOwnerData>('SceneOwner', {scene: '',@@ -427,4 +431,3 @@ export function getComponentDefaults(typeName: string): Record<string, unknown>return null;}-registerComponent('Name', Name);diff --git a/sdk/src/core.ts b/sdk/src/core.tsindex 41f550a05..33253326a 100644--- a/sdk/src/core.ts+++ b/sdk/src/core.ts@@ -67,6 +67,7 @@ export {type BuiltinComponentDef,type AnyComponentDef,type ComponentData,+ Transform,LocalTransform,WorldTransform,Sprite,@@ -82,6 +83,7 @@ export {ProjectionType,ClearFlags,ScaleMode,+ type TransformData,type LocalTransformData,type WorldTransformData,type SpriteData,@@ -213,6 +215,7 @@ export {UIMask,createMaskProcessor,TextRenderer,+ textPlugin,intersectRects,invertMatrix4,screenToWorld,@@ -343,11 +346,15 @@ export {loadSceneData,loadSceneWithAssets,loadComponent,+ remapEntityFields,updateCameraAspectRatio,findEntityByName,registerComponentAssetFields,getComponentAssetFields,+ getComponentAssetFieldDescriptors,+ getComponentSpineFieldDescriptor,registerComponentEntityFields,+ type AssetFieldType,type SceneData,type SceneEntityData,type SceneComponentData,diff --git a/sdk/src/physics/PhysicsPlugin.ts b/sdk/src/physics/PhysicsPlugin.tsindex cb7fafae9..86e52e27d 100644--- a/sdk/src/physics/PhysicsPlugin.ts+++ b/sdk/src/physics/PhysicsPlugin.ts@@ -5,8 +5,8 @@import type { Plugin, App } from '../app';import type { Entity, Vec2 } from '../types';-import type { LocalTransformData, WorldTransformData, ParentData, CanvasData } from '../component';-import { LocalTransform, WorldTransform, Parent, Canvas } from '../component';+import type { TransformData, ParentData, CanvasData } from '../component';+import { Transform, Parent, Canvas } from '../component';import { defineResource, Res, Time, type TimeData } from '../resource';import { Schedule, defineSystem } from '../system';import {@@ -128,27 +128,35 @@ export class PhysicsPlugin implements Plugin {const world = app.world;+ world.onDespawn((entity: Entity) => {+ if (trackedEntities.has(entity)) {+ module._physics_destroyBody(entity);+ trackedEntities.delete(entity);+ cachedProps.delete(entity);+ }+ });+app.addSystemToSchedule(Schedule.PostUpdate,defineSystem([Res(Time)],(time: TimeData) => {- const entities = world.getEntitiesWithComponents([RigidBody, LocalTransform, WorldTransform]);+ const entities = world.getEntitiesWithComponents([RigidBody, Transform]);const currentEntities = new Set<Entity>();for (const entity of entities) {currentEntities.add(entity);const rb = world.get(entity, RigidBody) as RigidBodyData;- const wt = world.get(entity, WorldTransform) as WorldTransformData;+ const wt = world.get(entity, Transform) as TransformData;if (!trackedEntities.has(entity)) {if (!rb.enabled) continue;- const angle = quatToAngleZ(wt.rotation);+ const angle = quatToAngleZ(wt.worldRotation);module._physics_createBody(entity, rb.bodyType,- wt.position.x * invPpu, wt.position.y * invPpu, angle,+ wt.worldPosition.x * invPpu, wt.worldPosition.y * invPpu, angle,rb.gravityScale, rb.linearDamping, rb.angularDamping,rb.fixedRotation ? 1 : 0, rb.bullet ? 1 : 0);@@ -187,10 +195,10 @@ export class PhysicsPlugin implements Plugin {}if (rb.bodyType === BodyType.Kinematic) {- const angle = quatToAngleZ(wt.rotation);+ const angle = quatToAngleZ(wt.worldRotation);module._physics_setBodyTransform(entity,- wt.position.x * invPpu, wt.position.y * invPpu,+ wt.worldPosition.x * invPpu, wt.worldPosition.y * invPpu,angle);}@@ -219,7 +227,9 @@ export class PhysicsPlugin implements Plugin {});- initPromise.catch(() => {});+ initPromise.catch((e) => {+ console.error('[ESEngine] Physics initialization failed:', e);+ });app.physicsInitPromise = initPromise;}}@@ -277,7 +287,7 @@ function syncDynamicTransforms(app: App, module: PhysicsWasmModule, ppu: number)if (!app.world.valid(entityId)) continue;- const transform = app.world.get(entityId, LocalTransform) as LocalTransformData;+ const transform = app.world.get(entityId, Transform) as TransformData;if (!transform) continue;let localX = worldX;@@ -286,15 +296,15 @@ function syncDynamicTransforms(app: App, module: PhysicsWasmModule, ppu: number)if (app.world.has(entityId, Parent)) {const parentData = app.world.get(entityId, Parent) as ParentData;- if (parentData && app.world.valid(parentData.entity) && app.world.has(parentData.entity, WorldTransform)) {- const pwt = app.world.get(parentData.entity, WorldTransform) as WorldTransformData;- const parentAngle = quatToAngleZ(pwt.rotation);- const dx = worldX - pwt.position.x;- const dy = worldY - pwt.position.y;+ if (parentData && app.world.valid(parentData.entity) && app.world.has(parentData.entity, Transform)) {+ const pwt = app.world.get(parentData.entity, Transform) as TransformData;+ const parentAngle = quatToAngleZ(pwt.worldRotation);+ const dx = worldX - pwt.worldPosition.x;+ const dy = worldY - pwt.worldPosition.y;const cos = Math.cos(-parentAngle);const sin = Math.sin(-parentAngle);- const sx = pwt.scale.x !== 0 ? pwt.scale.x : 1;- const sy = pwt.scale.y !== 0 ? pwt.scale.y : 1;+ const sx = pwt.worldScale.x !== 0 ? pwt.worldScale.x : 1;+ const sy = pwt.worldScale.y !== 0 ? pwt.worldScale.y : 1;localX = (dx * cos - dy * sin) / sx;localY = (dx * sin + dy * cos) / sy;localAngle = worldAngle - parentAngle;@@ -309,7 +319,7 @@ function syncDynamicTransforms(app: App, module: PhysicsWasmModule, ppu: number)transform.rotation.y = q.y;transform.rotation.z = q.z;- app.world.insert(entityId, LocalTransform, transform);+ app.world.insert(entityId, Transform, transform);}}diff --git a/sdk/src/preview/PreviewPlugin.ts b/sdk/src/preview/PreviewPlugin.tsindex b8594f1be..1b58016dd 100644--- a/sdk/src/preview/PreviewPlugin.ts+++ b/sdk/src/preview/PreviewPlugin.ts@@ -6,7 +6,7 @@import type { App, Plugin } from '../app';import type { SceneData } from '../scene';import { loadRuntimeScene } from '../runtimeLoader';-import { LocalTransform, Camera, Canvas, ProjectionType, ClearFlags, type LocalTransformData, type CameraData, type CanvasData } from '../component';+import { Transform, Camera, Canvas, ProjectionType, ClearFlags, type TransformData, type CameraData, type CanvasData } from '../component';import { DEFAULT_DESIGN_WIDTH, DEFAULT_DESIGN_HEIGHT, DEFAULT_PIXELS_PER_UNIT } from '../defaults';import { platformFetch } from '../platform';import { SceneManager } from '../sceneManager';@@ -119,12 +119,15 @@ export class PreviewPlugin implements Plugin {const sceneCtx = manager.getScene(PREVIEW_SCENE);const cameraEntity = sceneCtx ? sceneCtx.spawn() : world.spawn();- const transformData: LocalTransformData = {+ const transformData: TransformData = {position: { x: 0, y: 0, z: 10 },rotation: { x: 0, y: 0, z: 0, w: 1 },scale: { x: 1, y: 1, z: 1 },+ worldPosition: { x: 0, y: 0, z: 10 },+ worldRotation: { x: 0, y: 0, z: 0, w: 1 },+ worldScale: { x: 1, y: 1, z: 1 },};- world.insert(cameraEntity, LocalTransform, transformData);+ world.insert(cameraEntity, Transform, transformData);const cameraData: CameraData = {isActive: true,diff --git a/sdk/src/runtimeLoader.ts b/sdk/src/runtimeLoader.tsindex 0fc914f30..8bdda3ed0 100644--- a/sdk/src/runtimeLoader.ts+++ b/sdk/src/runtimeLoader.ts@@ -3,7 +3,7 @@* @brief Runtime scene loader for builder targets (WeChat, Playable, etc.)*/-import { SpineAnimation, WorldTransform, SceneOwner, type SpineAnimationData, type WorldTransformData } from './component';+import { SpineAnimation, Transform, SceneOwner, type SpineAnimationData, type TransformData } from './component';import { Material } from './material';import { loadSceneData, getComponentAssetFieldDescriptors, getComponentSpineFieldDescriptor, type AssetFieldType, type SceneData } from './scene';import type { ESEngineModule } from './wasm';@@ -236,15 +236,15 @@ function createSpineInstances(}function buildTransformMatrix(- wt: WorldTransformData,+ wt: TransformData,skeletonScale: number,flipX: boolean,flipY: boolean,): Float32Array {- const sx = wt.scale.x * skeletonScale * (flipX ? -1 : 1);- const sy = wt.scale.y * skeletonScale * (flipY ? -1 : 1);- const sz = wt.scale.z;- const qx = wt.rotation.x, qy = wt.rotation.y, qz = wt.rotation.z, qw = wt.rotation.w;+ const sx = wt.worldScale.x * skeletonScale * (flipX ? -1 : 1);+ const sy = wt.worldScale.y * skeletonScale * (flipY ? -1 : 1);+ const sz = wt.worldScale.z;+ const qx = wt.worldRotation.x, qy = wt.worldRotation.y, qz = wt.worldRotation.z, qw = wt.worldRotation.w;const x2 = qx + qx, y2 = qy + qy, z2 = qz + qz;const xx = qx * x2, xy = qx * y2, xz = qx * z2;const yy = qy * y2, yz = qy * z2, zz = qz * z2;@@ -253,7 +253,7 @@ function buildTransformMatrix((1 - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,(xy - wz) * sy, (1 - (xx + zz)) * sy, (yz + wx) * sy, 0,(xz + wy) * sz, (yz - wx) * sz, (1 - (xx + yy)) * sz, 0,- wt.position.x, wt.position.y, wt.position.z, 1,+ wt.worldPosition.x, wt.worldPosition.y, wt.worldPosition.z, 1,]);}@@ -287,8 +287,8 @@ function setupSpineRenderer(}let transformPtr = 0;- if (world.has(entityId, WorldTransform)) {- const wt = world.get(entityId, WorldTransform) as WorldTransformData;+ if (world.has(entityId, Transform)) {+ const wt = world.get(entityId, Transform) as TransformData;const skeletonScale = spineData?.skeletonScale ?? 1;const flipX = spineData?.flipX ?? false;const flipY = spineData?.flipY ?? false;diff --git a/sdk/src/spine/SpinePlugin.ts b/sdk/src/spine/SpinePlugin.tsindex b950fd8a9..ebdd22951 100644--- a/sdk/src/spine/SpinePlugin.ts+++ b/sdk/src/spine/SpinePlugin.ts@@ -9,7 +9,7 @@ import type { ESEngineModule } from '../wasm';import { defineResource } from '../resource';import { Schedule } from '../system';import type { SystemDef } from '../system';-import { SpineAnimation, WorldTransform, type SpineAnimationData, type WorldTransformData } from '../component';+import { SpineAnimation, Transform, type SpineAnimationData, type TransformData } from '../component';import { Assets } from '../asset';import type { Entity } from '../types';import { loadSpineModule, type SpineModuleFactory } from './SpineModuleLoader';@@ -20,15 +20,15 @@ export const SpineResource = defineResource<SpineModuleController | null>(null,const _transformBuf = new Float32Array(16);function buildTransformMatrix(- wt: WorldTransformData,+ wt: TransformData,skeletonScale: number,flipX: boolean,flipY: boolean,): Float32Array {- const sx = wt.scale.x * skeletonScale * (flipX ? -1 : 1);- const sy = wt.scale.y * skeletonScale * (flipY ? -1 : 1);- const sz = wt.scale.z;- const qx = wt.rotation.x, qy = wt.rotation.y, qz = wt.rotation.z, qw = wt.rotation.w;+ const sx = wt.worldScale.x * skeletonScale * (flipX ? -1 : 1);+ const sy = wt.worldScale.y * skeletonScale * (flipY ? -1 : 1);+ const sz = wt.worldScale.z;+ const qx = wt.worldRotation.x, qy = wt.worldRotation.y, qz = wt.worldRotation.z, qw = wt.worldRotation.w;const x2 = qx + qx, y2 = qy + qy, z2 = qz + qz;const xx = qx * x2, xy = qx * y2, xz = qx * z2;const yy = qy * y2, yz = qy * z2, zz = qz * z2;@@ -45,9 +45,9 @@ function buildTransformMatrix(_transformBuf[9] = (yz - wx) * sz;_transformBuf[10] = (1 - (xx + yy)) * sz;_transformBuf[11] = 0;- _transformBuf[12] = wt.position.x;- _transformBuf[13] = wt.position.y;- _transformBuf[14] = wt.position.z;+ _transformBuf[12] = wt.worldPosition.x;+ _transformBuf[13] = wt.worldPosition.y;+ _transformBuf[14] = wt.worldPosition.z;_transformBuf[15] = 1;return _transformBuf;}@@ -178,8 +178,8 @@ export class SpinePlugin implements Plugin {}let transform: Float32Array | undefined;- if (world.has(entity as Entity, WorldTransform)) {- const wt = world.get(entity as Entity, WorldTransform) as WorldTransformData;+ if (world.has(entity as Entity, Transform)) {+ const wt = world.get(entity as Entity, Transform) as TransformData;const skeletonScale = spineData?.skeletonScale ?? 1;const flipX = spineData?.flipX ?? false;const flipY = spineData?.flipY ?? false;diff --git a/src/esengine/ecs/TransformSystem.hpp b/src/esengine/ecs/TransformSystem.hppindex bc1faf6f7..d069f1431 100644--- a/src/esengine/ecs/TransformSystem.hpp+++ b/src/esengine/ecs/TransformSystem.hpp@@ -1,8 +1,8 @@/*** @file TransformSystem.hpp* @brief System for computing hierarchical world transforms- * @details Manages the computation of WorldTransform matrices from- * LocalTransform components, respecting parent-child hierarchy.+ * @details Computes world-space position/rotation/scale from local transform+ * fields, respecting parent-child hierarchy.** @author ESEngine Team* @date 2026@@ -12,51 +12,22 @@*/#pragma once-// =============================================================================-// Includes-// =============================================================================--// Project includes#include "System.hpp"#include "Registry.hpp"#include "components/Transform.hpp"#include "components/Hierarchy.hpp"#include "../math/Math.hpp"-// Standard library#include <algorithm>namespace esengine::ecs {-// =============================================================================-// TransformSystem-// =============================================================================--/**- * @brief System that computes world-space transforms from local transforms- *- * @details This system processes entities with LocalTransform and computes- * their WorldTransform matrices. It handles hierarchical transforms- * by processing parents before children.- *- * Features:- * - Respects Parent/Children hierarchy- * - Uses dirty flags for optimization- * - Caches world-space position/rotation/scale for convenience- *- * @code- * SystemGroup systems;- * systems.createSystem<TransformSystem>();- *- * // In game loop:- * systems.update(registry, deltaTime);- * // WorldTransform is now up-to-date for all entities- * @endcode- */class TransformSystem : public System {public:+ static constexpr u32 MAX_HIERARCHY_DEPTH = 256;+TransformSystem() {- setPriority(-100); // Run early, before other systems need transforms+ setPriority(-100);}void init(Registry& registry) override {@@ -69,41 +40,60 @@ public:}private:+ std::vector<Entity> dirty_to_clear_;+void updateDirtyTransforms(Registry& registry) {- registry.each<LocalTransform>([®istry, this](Entity entity, LocalTransform& local) {- registry.getOrEmplace<WorldTransform>(entity);+ dirty_to_clear_.clear();+ registry.each<Transform>([®istry, this](Entity entity, Transform& transform) {if (!registry.has<Parent>(entity)) {bool isStatic = registry.has<TransformStatic>(entity);bool isDirty = registry.has<TransformDirty>(entity);if (isStatic && !isDirty) {+ auto* children = registry.tryGet<Children>(entity);+ if (children) {+ for (Entity child : children->entities) {+ if (registry.valid(child)) {+ auto* childTransform = registry.tryGet<Transform>(child);+ if (childTransform) {+ updateEntityTransform(registry, child, *childTransform, transform.cachedMatrix_, false, 1);+ }+ }+ }+ }return;}- updateRootTransform(registry, entity, local);+ updateRootTransform(registry, entity, transform);}});++ for (Entity e : dirty_to_clear_) {+ if (registry.has<TransformDirty>(e)) {+ registry.remove<TransformDirty>(e);+ }+ }}- void updateRootTransform(Registry& registry, Entity entity, const LocalTransform& local) {- auto& world = registry.get<WorldTransform>(entity);- world.position = local.position;- world.rotation = local.rotation;- world.scale = local.scale;+ void updateRootTransform(Registry& registry, Entity entity, Transform& transform) {+ transform.worldPosition = transform.position;+ transform.worldRotation = transform.rotation;+ transform.worldScale = transform.scale;+ transform.cachedMatrix_ = math::compose(transform.worldPosition, transform.worldRotation, transform.worldScale);+ transform.decomposed_ = true;if (registry.has<TransformDirty>(entity)) {- registry.remove<TransformDirty>(entity);+ dirty_to_clear_.push_back(entity);}auto* children = registry.tryGet<Children>(entity);if (children) {- glm::mat4 worldMatrix = math::compose(world.position, world.rotation, world.scale);for (Entity child : children->entities) {if (registry.valid(child)) {- auto* childLocal = registry.tryGet<LocalTransform>(child);- if (childLocal) {- updateEntityTransform(registry, child, *childLocal, worldMatrix, true);+ auto* childTransform = registry.tryGet<Transform>(child);+ if (childTransform) {+ updateEntityTransform(registry, child, *childTransform, transform.cachedMatrix_, true, 1);}}}@@ -111,21 +101,23 @@ private:}void updateEntityTransform(Registry& registry, Entity entity,- const LocalTransform& local,+ Transform& transform,const glm::mat4& parentWorldMatrix,- bool parentDirty) {+ bool parentDirty, u32 depth) {+ if (depth >= MAX_HIERARCHY_DEPTH) {+ return;+ }+bool isDirty = parentDirty || registry.has<TransformDirty>(entity);if (registry.has<TransformStatic>(entity) && !isDirty) {auto* children = registry.tryGet<Children>(entity);if (children) {- const auto& world = registry.get<WorldTransform>(entity);- glm::mat4 worldMatrix = math::compose(world.position, world.rotation, world.scale);for (Entity child : children->entities) {if (registry.valid(child)) {- auto* childLocal = registry.tryGet<LocalTransform>(child);- if (childLocal) {- updateEntityTransform(registry, child, *childLocal, worldMatrix, false);+ auto* childTransform = registry.tryGet<Transform>(child);+ if (childTransform) {+ updateEntityTransform(registry, child, *childTransform, transform.cachedMatrix_, false, depth + 1);}}}@@ -133,23 +125,23 @@ private:return;}- glm::mat4 localMatrix = math::compose(local.position, local.rotation, local.scale);+ glm::mat4 localMatrix = math::compose(transform.position, transform.rotation, transform.scale);glm::mat4 worldMatrix = parentWorldMatrix * localMatrix;- auto& world = registry.get<WorldTransform>(entity);- math::decompose(worldMatrix, world.position, world.rotation, world.scale);+ transform.cachedMatrix_ = worldMatrix;+ transform.decomposed_ = false;if (isDirty && !parentDirty) {- registry.remove<TransformDirty>(entity);+ dirty_to_clear_.push_back(entity);}auto* children = registry.tryGet<Children>(entity);if (children) {for (Entity child : children->entities) {if (registry.valid(child)) {- auto* childLocal = registry.tryGet<LocalTransform>(child);- if (childLocal) {- updateEntityTransform(registry, child, *childLocal, worldMatrix, isDirty);+ auto* childTransform = registry.tryGet<Transform>(child);+ if (childTransform) {+ updateEntityTransform(registry, child, *childTransform, worldMatrix, isDirty, depth + 1);}}}@@ -157,25 +149,17 @@ private:}};-// =============================================================================-// Hierarchy Utilities-// =============================================================================+inline bool isDescendantOf(Registry& registry, Entity entity, Entity ancestor) {+ while (registry.has<Parent>(entity)) {+ Entity parent = registry.get<Parent>(entity).entity;+ if (parent == ancestor) return true;+ if (!registry.valid(parent)) break;+ entity = parent;+ }+ return false;+}-/**- * @brief Sets the parent of an entity, updating both Parent and Children components- *- * @param registry The ECS registry- * @param child The child entity- * @param newParent The new parent entity (INVALID_ENTITY to unparent)- *- * @code- * Entity parent = registry.create();- * Entity child = registry.create();- * setParent(registry, child, parent);- * @endcode- */inline void setParent(Registry& registry, Entity child, Entity newParent) {- // Remove from old parent if existsif (registry.has<Parent>(child)) {Entity oldParent = registry.get<Parent>(child).entity;if (registry.valid(oldParent) && registry.has<Children>(oldParent)) {@@ -193,21 +177,22 @@ inline void setParent(Registry& registry, Entity child, Entity newParent) {}}- // Set new parentif (newParent != INVALID_ENTITY && registry.valid(newParent)) {+ if (child == newParent || isDescendantOf(registry, newParent, child)) {+ return;+ }+if (registry.has<Parent>(child)) {registry.get<Parent>(child).entity = newParent;} else {registry.emplace<Parent>(child, newParent);}- // Add to new parent's children listif (!registry.has<Children>(newParent)) {registry.emplace<Children>(newParent);}registry.get<Children>(newParent).entities.push_back(child);- // Update hierarchy depthu32 parentDepth = 0;if (registry.has<HierarchyDepth>(newParent)) {parentDepth = registry.get<HierarchyDepth>(newParent).depth;@@ -219,19 +204,11 @@ inline void setParent(Registry& registry, Entity child, Entity newParent) {}}- // Mark transform as dirtyif (!registry.has<TransformDirty>(child)) {registry.emplace<TransformDirty>(child);}}-/**- * @brief Gets the root ancestor of an entity- *- * @param registry The ECS registry- * @param entity The entity to find root for- * @return The root entity (entity itself if no parent)- */inline Entity getRoot(Registry& registry, Entity entity) {while (registry.has<Parent>(entity)) {Entity parent = registry.get<Parent>(entity).entity;@@ -241,34 +218,9 @@ inline Entity getRoot(Registry& registry, Entity entity) {return entity;}-/**- * @brief Checks if an entity is a descendant of another- *- * @param registry The ECS registry- * @param entity The potential descendant- * @param ancestor The potential ancestor- * @return true if entity is a descendant of ancestor- */-inline bool isDescendantOf(Registry& registry, Entity entity, Entity ancestor) {- while (registry.has<Parent>(entity)) {- Entity parent = registry.get<Parent>(entity).entity;- if (parent == ancestor) return true;- if (!registry.valid(parent)) break;- entity = parent;- }- return false;-}--/**- * @brief Destroys an entity and all its descendants- *- * @param registry The ECS registry- * @param entity The entity to destroy with its children- */inline void destroyWithChildren(Registry& registry, Entity entity) {- // Recursively destroy children firstif (registry.has<Children>(entity)) {- auto children = registry.get<Children>(entity).entities; // Copy to avoid iteration issues+ auto children = registry.get<Children>(entity).entities;for (Entity child : children) {if (registry.valid(child)) {destroyWithChildren(registry, child);@@ -276,7 +228,6 @@ inline void destroyWithChildren(Registry& registry, Entity entity) {}}- // Remove from parent's children listif (registry.has<Parent>(entity)) {Entity parent = registry.get<Parent>(entity).entity;if (registry.valid(parent) && registry.has<Children>(parent)) {@@ -290,7 +241,6 @@ inline void destroyWithChildren(Registry& registry, Entity entity) {}}- // Destroy the entityregistry.destroy(entity);}diff --git a/src/esengine/ecs/components/Camera.hpp b/src/esengine/ecs/components/Camera.hppindex e669bddf0..e9c81e5fb 100644--- a/src/esengine/ecs/components/Camera.hpp+++ b/src/esengine/ecs/components/Camera.hpp@@ -45,7 +45,7 @@ enum class ProjectionType : u8 {** @code* Entity camera = registry.create();- * registry.emplace<LocalTransform>(camera, glm::vec3(0, 0, 10));+ * registry.emplace<Transform>(camera, glm::vec3(0, 0, 10));* auto& cam = registry.emplace<Camera>(camera);* cam.projectionType = ProjectionType::Perspective;* cam.fov = 60.0f;diff --git a/src/esengine/ecs/components/Hierarchy.hpp b/src/esengine/ecs/components/Hierarchy.hppindex e0a2704b8..0d5178e5a 100644--- a/src/esengine/ecs/components/Hierarchy.hpp+++ b/src/esengine/ecs/components/Hierarchy.hpp@@ -63,6 +63,7 @@ struct Parent {ES_COMPONENT()struct Children {/** @brief List of child entity IDs */+ ES_PROPERTY()std::vector<Entity> entities;Children() = default;diff --git a/src/esengine/ecs/components/Transform.hpp b/src/esengine/ecs/components/Transform.hppindex bfdf5352d..92583ab86 100644--- a/src/esengine/ecs/components/Transform.hpp+++ b/src/esengine/ecs/components/Transform.hpp@@ -1,8 +1,8 @@/*** @file Transform.hpp- * @brief Transform components for spatial positioning- * @details Provides LocalTransform for relative positioning and WorldTransform- * for cached world-space matrices. Uses quaternions for rotation.+ * @brief Unified Transform component with local and world-space data+ * @details Single component storing both local (user-controlled) and world-space+ * (system-computed) transforms. Uses quaternions for rotation.** @author ESEngine Team* @date 2026@@ -12,131 +12,73 @@*/#pragma once-// =============================================================================-// Includes-// =============================================================================-#include "../../core/Types.hpp"#include "../../core/Reflection.hpp"#include "../../math/Math.hpp"namespace esengine::ecs {-// =============================================================================-// Local Transform Component-// =============================================================================-/**- * @brief Local transform relative to parent (or world if no parent)+ * @brief Unified transform component*- * @details Stores spatial transformation data using quaternion for rotation- * to avoid gimbal lock. This component represents the transform- * relative to the entity's parent. If no Parent component exists,- * this is equivalent to world space.- *- * @note Rotation is stored as a quaternion. Use math::eulerToQuat() and- * math::quatToEuler() for conversion if needed.+ * @details Contains both local (relative to parent) and world-space transforms.+ * Local fields (position, rotation, scale) are user-controlled.+ * World fields (worldPosition, worldRotation, worldScale) are computed+ * by TransformSystem each frame.** @code* Entity e = registry.create();- * registry.emplace<LocalTransform>(e, glm::vec3(10.0f, 0.0f, 0.0f));+ * registry.emplace<Transform>(e, glm::vec3(10.0f, 0.0f, 0.0f));*- * auto& transform = registry.get<LocalTransform>(e);- * transform.rotation = glm::angleAxis(glm::radians(45.0f), glm::vec3(0, 1, 0));+ * auto& transform = registry.get<Transform>(e);+ * transform.position.x = 5.0f; // set local+ * // After TransformSystem runs:+ * // transform.worldPosition contains final world-space position* @endcode*/ES_COMPONENT()-struct LocalTransform {- /** @brief Position relative to parent */+struct Transform {ES_PROPERTY()glm::vec3 position{0.0f, 0.0f, 0.0f};- /** @brief Rotation as quaternion (no gimbal lock) */ES_PROPERTY()- glm::quat rotation{1.0f, 0.0f, 0.0f, 0.0f}; // Identity quaternion (w, x, y, z)+ glm::quat rotation{1.0f, 0.0f, 0.0f, 0.0f};- /** @brief Scale factors */ES_PROPERTY()glm::vec3 scale{1.0f, 1.0f, 1.0f};- /** @brief Default constructor (identity transform) */- LocalTransform() = default;-- /**- * @brief Constructs transform with position only- * @param pos Initial position- */- explicit LocalTransform(const glm::vec3& pos) : position(pos) {}-- /**- * @brief Constructs transform with position and rotation- * @param pos Initial position- * @param rot Initial rotation (quaternion)- */- LocalTransform(const glm::vec3& pos, const glm::quat& rot)- : position(pos), rotation(rot) {}-- /**- * @brief Constructs transform with full parameters- * @param pos Initial position- * @param rot Initial rotation (quaternion)- * @param scl Initial scale- */- LocalTransform(const glm::vec3& pos, const glm::quat& rot, const glm::vec3& scl)- : position(pos), rotation(rot), scale(scl) {}-};--// =============================================================================-// World Transform Component (Cached)-// =============================================================================--/**- * @brief Cached world-space transform matrix- *- * @details This component is managed by the TransformSystem. It stores- * the final world-space transformation matrix computed from the- * hierarchy of LocalTransform components.- *- * @note Do not modify this component directly - it will be overwritten- * by TransformSystem. Modify LocalTransform instead.- */-ES_COMPONENT()-struct WorldTransform {- /** @brief World-space position */ES_PROPERTY()- glm::vec3 position{0.0f, 0.0f, 0.0f};+ glm::vec3 worldPosition{0.0f, 0.0f, 0.0f};- /** @brief World-space rotation */ES_PROPERTY()- glm::quat rotation{1.0f, 0.0f, 0.0f, 0.0f};+ glm::quat worldRotation{1.0f, 0.0f, 0.0f, 0.0f};- /** @brief World-space scale */ES_PROPERTY()- glm::vec3 scale{1.0f, 1.0f, 1.0f};+ glm::vec3 worldScale{1.0f, 1.0f, 1.0f};- WorldTransform() = default;-};+ glm::mat4 cachedMatrix_{1.0f};+ bool decomposed_ = true;-// =============================================================================-// Transform Dirty Flag-// =============================================================================+ void ensureDecomposed() {+ if (!decomposed_) {+ math::decompose(cachedMatrix_, worldPosition, worldRotation, worldScale);+ decomposed_ = true;+ }+ }++ Transform() = default;++ explicit Transform(const glm::vec3& pos) : position(pos) {}++ Transform(const glm::vec3& pos, const glm::quat& rot)+ : position(pos), rotation(rot) {}++ Transform(const glm::vec3& pos, const glm::quat& rot, const glm::vec3& scl)+ : position(pos), rotation(rot), scale(scl) {}+};-/**- * @brief Tag component indicating transform needs recalculation- *- * @details Added when LocalTransform is modified. TransformSystem will- * recalculate WorldTransform for all entities with this tag- * and then remove the tag.- */struct TransformDirty {};-/**- * @brief Tag component for static transforms that rarely change- *- * @details Entities with this tag are skipped by TransformSystem unless- * they also have TransformDirty. Use for background scenery,- * static UI elements, etc. that don't move every frame.- */struct TransformStatic {};} // namespace esengine::ecsdiff --git a/src/esengine/ecs/components/Velocity.hpp b/src/esengine/ecs/components/Velocity.hppindex e53ac4cda..5c3545a7b 100644--- a/src/esengine/ecs/components/Velocity.hpp+++ b/src/esengine/ecs/components/Velocity.hpp@@ -29,7 +29,7 @@ namespace esengine::ecs {* @brief Velocity component for physics simulation** @details Stores linear and angular velocity for movement and rotation.- * Used by physics systems to update LocalTransform components.+ * Used by physics systems to update Transform components.** @note Angular velocity is in radians per second around each axis.*/diff --git a/templates/src/main.ts b/templates/src/main.tsindex e39466df4..bdaa513d1 100644--- a/templates/src/main.ts+++ b/templates/src/main.ts@@ -11,7 +11,7 @@ import {defineSystem,Schedule,Commands,- LocalTransform,+ Transform,Sprite,Camera,Canvas,@@ -50,7 +50,7 @@ export async function main(Module: ESEngineModule): Promise<void> {isActive: true,priority: 0})- .insert(LocalTransform, {+ .insert(Transform, {position: { x: 0, y: 0, z: 10 },rotation: { w: 1, x: 0, y: 0, z: 0 },scale: { x: 1, y: 1, z: 1 }@@ -69,7 +69,7 @@ export async function main(Module: ESEngineModule): Promise<void> {flipX: false,flipY: false})- .insert(LocalTransform, {+ .insert(Transform, {position: { x: 0, y: 0, z: 0 },rotation: { w: 1, x: 0, y: 0, z: 0 },scale: { x: 1, y: 1, z: 1 }@@ -82,7 +82,7 @@ export async function main(Module: ESEngineModule): Promise<void> {// Add update system - runs every frameapp.addSystemToSchedule(Schedule.Update, defineSystem(- [Res(Time), Query(LocalTransform, Sprite)],+ [Res(Time), Query(Transform, Sprite)],(time, query) => {for (const [entity, transform, sprite] of query) {// Move the sprite in a circlediff --git a/tests/ecs/test_registry.cpp b/tests/ecs/test_registry.cppindex 7e3b15010..ccc8c45ff 100644--- a/tests/ecs/test_registry.cpp+++ b/tests/ecs/test_registry.cpp@@ -322,7 +322,7 @@ TEST(local_transform_default) {esengine::ecs::Registry registry;esengine::Entity entity = registry.create();- auto& local = registry.emplace<esengine::ecs::LocalTransform>(entity);+ auto& local = registry.emplace<esengine::ecs::Transform>(entity);ASSERT_EQ(local.position.x, 0.0f);ASSERT_EQ(local.position.y, 0.0f);@@ -335,7 +335,7 @@ TEST(local_transform_with_position) {esengine::ecs::Registry registry;esengine::Entity entity = registry.create();- auto& local = registry.emplace<esengine::ecs::LocalTransform>(+ auto& local = registry.emplace<esengine::ecs::Transform>(entity, glm::vec3(10.0f, 20.0f, 30.0f));ASSERT_EQ(local.position.x, 10.0f);@@ -348,7 +348,7 @@ TEST(local_transform_with_rotation) {esengine::Entity entity = registry.create();glm::quat rotation = glm::angleAxis(glm::radians(90.0f), glm::vec3(0, 1, 0));- auto& local = registry.emplace<esengine::ecs::LocalTransform>(+ auto& local = registry.emplace<esengine::ecs::Transform>(entity, glm::vec3(0.0f), rotation);ASSERT_TRUE(esengine::math::approxEqual(local.rotation.y, rotation.y, 0.001f));@@ -360,8 +360,8 @@ TEST(hierarchy_parent_child) {esengine::Entity parent = registry.create();esengine::Entity child = registry.create();- registry.emplace<esengine::ecs::LocalTransform>(parent, glm::vec3(10.0f, 0.0f, 0.0f));- registry.emplace<esengine::ecs::LocalTransform>(child, glm::vec3(5.0f, 0.0f, 0.0f));+ registry.emplace<esengine::ecs::Transform>(parent, glm::vec3(10.0f, 0.0f, 0.0f));+ registry.emplace<esengine::ecs::Transform>(child, glm::vec3(5.0f, 0.0f, 0.0f));esengine::ecs::setParent(registry, child, parent);@@ -380,9 +380,9 @@ TEST(hierarchy_depth) {esengine::Entity parent = registry.create();esengine::Entity child = registry.create();- registry.emplace<esengine::ecs::LocalTransform>(grandparent);- registry.emplace<esengine::ecs::LocalTransform>(parent);- registry.emplace<esengine::ecs::LocalTransform>(child);+ registry.emplace<esengine::ecs::Transform>(grandparent);+ registry.emplace<esengine::ecs::Transform>(parent);+ registry.emplace<esengine::ecs::Transform>(child);esengine::ecs::setParent(registry, parent, grandparent);esengine::ecs::setParent(registry, child, parent);@@ -398,9 +398,9 @@ TEST(hierarchy_get_root) {esengine::Entity middle = registry.create();esengine::Entity leaf = registry.create();- registry.emplace<esengine::ecs::LocalTransform>(root);- registry.emplace<esengine::ecs::LocalTransform>(middle);- registry.emplace<esengine::ecs::LocalTransform>(leaf);+ registry.emplace<esengine::ecs::Transform>(root);+ registry.emplace<esengine::ecs::Transform>(middle);+ registry.emplace<esengine::ecs::Transform>(leaf);esengine::ecs::setParent(registry, middle, root);esengine::ecs::setParent(registry, leaf, middle);@@ -418,10 +418,10 @@ TEST(hierarchy_is_descendant) {esengine::Entity grandchild = registry.create();esengine::Entity unrelated = registry.create();- registry.emplace<esengine::ecs::LocalTransform>(root);- registry.emplace<esengine::ecs::LocalTransform>(child);- registry.emplace<esengine::ecs::LocalTransform>(grandchild);- registry.emplace<esengine::ecs::LocalTransform>(unrelated);+ registry.emplace<esengine::ecs::Transform>(root);+ registry.emplace<esengine::ecs::Transform>(child);+ registry.emplace<esengine::ecs::Transform>(grandchild);+ registry.emplace<esengine::ecs::Transform>(unrelated);esengine::ecs::setParent(registry, child, root);esengine::ecs::setParent(registry, grandchild, child);