Skip to content

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.

refactor: simplify EditorSceneRenderer by delegating to EditorSceneManager

esenginebfa9b68861c5
diff --git a/editor/src/renderer/EditorSceneRenderer.ts b/editor/src/renderer/EditorSceneRenderer.ts
index 7dcdbe8aa..e973b636e 100644
--- a/editor/src/renderer/EditorSceneRenderer.ts
+++ b/editor/src/renderer/EditorSceneRenderer.ts
@@ -3,17 +3,11 @@
* @brief WebGL scene renderer for editor scene view
*/
-import type { ESEngineModule, CppRegistry, Entity } from 'esengine';
-import type { SceneData, EntityData, ComponentData } from '../types/SceneTypes';
-import { EditorTextureManager } from './EditorTextureManager';
+import type { ESEngineModule } from 'esengine';
+import type { SceneData, ComponentData } from '../types/SceneTypes';
import { EditorCamera } from './EditorCamera';
-import {
- Transform,
- composeTransforms,
- createIdentityTransform,
-} from '../math/Transform';
-import { EditorTextRenderer } from './EditorTextRenderer';
-import { AssetPathResolver, AssetLoader } from '../asset';
+import { EditorSceneManager } from '../scene/EditorSceneManager';
+import { AssetPathResolver } from '../asset';
// =============================================================================
// EditorSceneRenderer
@@ -21,36 +15,16 @@ import { AssetPathResolver, AssetLoader } from '../asset';
export class EditorSceneRenderer {
private module_: ESEngineModule | null = null;
- private registry_: CppRegistry | null = null;
- private textureManager_: EditorTextureManager | null = null;
- private textRenderer_: EditorTextRenderer | null = null;
+ private sceneManager_: EditorSceneManager | null = null;
private camera_: EditorCamera;
- private initialized_ = false;
private pathResolver_: AssetPathResolver;
- private assetLoader_: AssetLoader | null = null;
-
- /** Map scene entity IDs to runtime entities */
- private entityMap_: Map<number, Entity> = new Map();
-
- /** Current scene data for parent lookups */
- private sceneData_: SceneData | null = null;
-
- /** Map entity ID to EntityData for fast lookup */
- private entityDataMap_: Map<number, EntityData> = new Map();
-
- /** Sync lock to prevent concurrent syncScene calls */
- private syncing_ = false;
- private pendingScene_: SceneData | null = null;
+ private initialized_ = false;
constructor() {
this.camera_ = new EditorCamera();
this.pathResolver_ = new AssetPathResolver();
}
- /**
- * @brief Initialize renderer with WASM module and canvas
- * @returns true if initialization succeeded
- */
async init(module: ESEngineModule, canvasSelector: string): Promise<boolean> {
if (this.initialized_) return true;
@@ -62,467 +36,92 @@ export class EditorSceneRenderer {
return false;
}
- this.registry_ = new module.Registry();
- this.textureManager_ = new EditorTextureManager(module, this.pathResolver_);
- this.textRenderer_ = new EditorTextRenderer(module);
- this.assetLoader_ = new AssetLoader(module, this.pathResolver_);
+ this.sceneManager_ = new EditorSceneManager(module, this.pathResolver_);
this.initialized_ = true;
return true;
}
- /**
- * @brief Set project directory for texture loading
- */
setProjectDir(projectDir: string): void {
this.pathResolver_.setProjectDir(projectDir);
+ this.sceneManager_?.setProjectDir(projectDir);
}
- /**
- * @brief Get path resolver for external use
- */
get pathResolver(): AssetPathResolver {
return this.pathResolver_;
}
- /**
- * @brief Sync entire scene to registry
- */
- async syncScene(scene: SceneData): Promise<void> {
- if (!this.registry_ || !this.module_) return;
-
- if (this.syncing_) {
- this.pendingScene_ = scene;
- return;
- }
-
- this.syncing_ = true;
-
- try {
- await this.syncSceneInternal(scene);
-
- if (this.pendingScene_) {
- const latest = this.pendingScene_;
- this.pendingScene_ = null;
- await this.syncSceneInternal(latest);
- }
- } finally {
- this.syncing_ = false;
- }
- }
-
- private async syncSceneInternal(scene: SceneData): Promise<void> {
- if (!this.registry_ || !this.module_) return;
-
- this.clearRegistry();
-
- this.sceneData_ = scene;
- this.entityDataMap_.clear();
- for (const entityData of scene.entities) {
- this.entityDataMap_.set(entityData.id, entityData);
- }
-
- for (const entityData of scene.entities) {
- await this.syncEntity(entityData);
- }
- }
-
- /**
- * @brief Sync a single entity
- */
- async syncEntity(entityData: EntityData): Promise<void> {
- if (!this.registry_ || !this.module_) return;
-
- let entity = this.entityMap_.get(entityData.id);
- if (!entity) {
- entity = this.registry_.create();
- this.entityMap_.set(entityData.id, entity);
- }
-
- // Update entityDataMap_ with latest data
- this.entityDataMap_.set(entityData.id, entityData);
+ // =========================================================================
+ // Scene Sync (Delegated to EditorSceneManager)
+ // =========================================================================
- for (const comp of entityData.components) {
- await this.syncComponent(entity, comp, entityData.id);
- }
+ async syncScene(scene: SceneData): Promise<void> {
+ await this.sceneManager_?.loadScene(scene);
}
- /**
- * @brief Update a specific entity's components
- */
async updateEntity(entityId: number, components: ComponentData[]): Promise<void> {
- if (!this.registry_) return;
-
- const entity = this.entityMap_.get(entityId);
- if (!entity) return;
-
- // Update entityDataMap_ with latest components
- const existingData = this.entityDataMap_.get(entityId);
- if (existingData) {
- existingData.components = components;
- }
-
- for (const comp of components) {
- await this.syncComponent(entity, comp, entityId);
- }
+ await this.sceneManager_?.updateEntity(entityId, components);
}
- /**
- * @brief Remove an entity
- */
removeEntity(entityId: number): void {
- if (!this.registry_) return;
-
- const entity = this.entityMap_.get(entityId);
- if (entity) {
- this.registry_.destroy(entity);
- this.entityMap_.delete(entityId);
- }
+ this.sceneManager_?.removeEntity(entityId);
}
- /**
- * @brief Get editor camera for pan/zoom control
- */
+ // =========================================================================
+ // Editor-specific Features
+ // =========================================================================
+
get camera(): EditorCamera {
return this.camera_;
}
- /**
- * @brief Get texture manager
- */
- get textureManager(): EditorTextureManager | null {
- return this.textureManager_;
+ get textureManager() {
+ return this.sceneManager_?.assetServer.textureManager ?? null;
}
- /**
- * @brief Get spine bounds for an entity
- * @returns bounds object with x, y, width, height, or null if not found
- */
getSpineBounds(sceneEntityId: number): { x: number; y: number; width: number; height: number } | null {
- if (!this.module_ || !this.registry_) return null;
+ if (!this.module_ || !this.sceneManager_) return null;
- const entity = this.entityMap_.get(sceneEntityId);
+ const entity = this.sceneManager_.getEntityMap().get(sceneEntityId);
if (entity === undefined) return null;
- const bounds = this.module_.getSpineBounds(this.registry_, entity);
+ const bounds = this.module_.getSpineBounds(this.sceneManager_.registry, entity);
if (!bounds.valid) return null;
return { x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height };
}
- /**
- * @brief Render a frame
- */
+ // =========================================================================
+ // Rendering
+ // =========================================================================
+
render(width: number, height: number): void {
- if (!this.module_ || !this.registry_ || !this.initialized_) return;
+ if (!this.module_ || !this.sceneManager_ || !this.initialized_) return;
const matrix = this.camera_.getViewProjection(width, height);
const matrixPtr = this.module_._malloc(64);
this.module_.HEAPF32.set(matrix, matrixPtr / 4);
- this.module_.renderFrameWithMatrix(this.registry_, width, height, matrixPtr);
+ this.module_.renderFrameWithMatrix(this.sceneManager_.registry, width, height, matrixPtr);
this.module_._free(matrixPtr);
}
- /**
- * @brief Dispose resources
- */
- dispose(): void {
- if (this.textureManager_) {
- this.textureManager_.releaseAll();
- this.textureManager_ = null;
- }
-
- if (this.textRenderer_) {
- this.textRenderer_.releaseAll();
- this.textRenderer_ = null;
- }
+ // =========================================================================
+ // Cleanup
+ // =========================================================================
- if (this.registry_) {
- this.registry_.delete();
- this.registry_ = null;
+ dispose(): void {
+ if (this.sceneManager_) {
+ this.sceneManager_.dispose();
+ this.sceneManager_ = null;
}
if (this.module_ && this.initialized_) {
this.module_.shutdownRenderer();
}
- this.entityMap_.clear();
this.initialized_ = false;
this.module_ = null;
}
-
- // =========================================================================
- // Private Methods
- // =========================================================================
-
- private clearRegistry(): void {
- if (!this.registry_) return;
-
- for (const [, entity] of this.entityMap_) {
- this.registry_.destroy(entity);
- }
- this.entityMap_.clear();
-
- if (this.textRenderer_) {
- this.textRenderer_.releaseAll();
- }
- }
-
- private async syncComponent(entity: Entity, comp: ComponentData, entityId: number): Promise<void> {
- if (!this.registry_) return;
-
- switch (comp.type) {
- case 'LocalTransform':
- this.syncTransform(entity, comp.data, entityId);
- break;
-
- case 'Sprite': {
- const entityData = this.entityDataMap_.get(entityId);
- const hasText = entityData?.components.some(c => c.type === 'Text');
- if (!hasText) {
- await this.syncSprite(entity, comp.data);
- }
- break;
- }
-
- case 'Camera':
- this.syncCamera(entity, comp.data);
- break;
-
- case 'Text':
- this.syncText(entity, comp.data, entityId);
- break;
-
- case 'SpineAnimation':
- await this.syncSpineAnimation(entity, comp.data);
- break;
- }
- }
-
- private syncTransform(entity: Entity, data: any, entityId: number): void {
- if (!this.registry_) return;
-
- if (this.registry_.hasLocalTransform(entity)) {
- this.registry_.removeLocalTransform(entity);
- }
-
- const worldTransform = this.computeWorldTransform(entityId);
-
- this.registry_.addLocalTransform(entity, {
- position: worldTransform.position,
- rotation: worldTransform.rotation,
- scale: worldTransform.scale,
- });
- }
-
- private computeWorldTransform(entityId: number): Transform {
- const entityData = this.entityDataMap_.get(entityId);
- if (!entityData) {
- return createIdentityTransform();
- }
-
- const localTransform = this.getLocalTransform(entityData);
- const uiRect = this.getUIRect(entityData);
- const entitySize = this.getEntitySize(entityData);
-
- let adjustedPosition = { ...localTransform.position };
-
- if (uiRect) {
- const parentSize = this.getParentSize(entityData);
-
- // anchor offset (relative to parent center)
- adjustedPosition.x += (uiRect.anchor.x - 0.5) * parentSize.x;
- adjustedPosition.y += (uiRect.anchor.y - 0.5) * parentSize.y;
-
- // pivot offset (renderer uses center pivot)
- adjustedPosition.x += (0.5 - uiRect.pivot.x) * entitySize.x;
- adjustedPosition.y += (0.5 - uiRect.pivot.y) * entitySize.y;
- }
-
- const adjustedLocal: Transform = {
- position: adjustedPosition,
- rotation: localTransform.rotation,
- scale: localTransform.scale,
- };
-
- if (entityData.parent === null) {
- return adjustedLocal;
- }
-
- const parentWorld = this.computeWorldTransform(entityData.parent);
- return composeTransforms(parentWorld, adjustedLocal);
- }
-
- private getLocalTransform(entity: EntityData): Transform {
- const comp = entity.components.find(c => c.type === 'LocalTransform');
- if (!comp) {
- return createIdentityTransform();
- }
-
- return {
- position: (comp.data.position as any) ?? { x: 0, y: 0, z: 0 },
- rotation: (comp.data.rotation as any) ?? { x: 0, y: 0, z: 0, w: 1 },
- scale: (comp.data.scale as any) ?? { x: 1, y: 1, z: 1 },
- };
- }
-
- private getUIRect(entity: EntityData): { size: { x: number; y: number }; anchor: { x: number; y: number }; pivot: { x: number; y: number } } | null {
- const comp = entity.components.find(c => c.type === 'UIRect');
- if (!comp) return null;
-
- return {
- size: (comp.data as any).size ?? { x: 100, y: 100 },
- anchor: (comp.data as any).anchor ?? { x: 0.5, y: 0.5 },
- pivot: (comp.data as any).pivot ?? { x: 0.5, y: 0.5 },
- };
- }
-
- private getEntitySize(entity: EntityData): { x: number; y: number } {
- const uiRect = this.getUIRect(entity);
- if (uiRect?.size) {
- return uiRect.size;
- }
-
- const sprite = entity.components.find(c => c.type === 'Sprite');
- if (sprite?.data?.size) {
- return (sprite.data as any).size;
- }
-
- return { x: 100, y: 100 };
- }
-
- private getParentSize(entity: EntityData): { x: number; y: number } {
- if (entity.parent !== null) {
- const parentData = this.entityDataMap_.get(entity.parent);
- if (parentData) {
- return this.getEntitySize(parentData);
- }
- }
-
- return this.getCanvasSize();
- }
-
- private getCanvasSize(): { x: number; y: number } {
- if (this.sceneData_) {
- for (const entity of this.sceneData_.entities) {
- const canvas = entity.components.find(c => c.type === 'Canvas');
- if (canvas?.data) {
- const resolution = (canvas.data as any).designResolution;
- if (resolution) {
- return { x: resolution.x, y: resolution.y };
- }
- }
- }
- }
- return { x: 1920, y: 1080 };
- }
-
- private async syncSprite(entity: Entity, data: any): Promise<void> {
- if (!this.registry_ || !this.textureManager_) return;
-
- let textureHandle = 0;
-
- const texturePath = data.texture;
- if (texturePath) {
- textureHandle = await this.textureManager_.loadTexture(texturePath);
- }
-
- if (this.registry_.hasSprite(entity)) {
- this.registry_.removeSprite(entity);
- }
-
- this.registry_.addSprite(entity, {
- texture: textureHandle,
- color: data.color ?? { x: 1, y: 1, z: 1, w: 1 },
- size: data.size ?? { x: 100, y: 100 },
- uvOffset: data.uvOffset ?? { x: 0, y: 0 },
- uvScale: data.uvScale ?? { x: 1, y: 1 },
- layer: data.layer ?? 0,
- flipX: data.flipX ?? false,
- flipY: data.flipY ?? false,
- });
- }
-
- private syncCamera(entity: Entity, data: any): void {
- if (!this.registry_) return;
-
- if (this.registry_.hasCamera(entity)) {
- this.registry_.removeCamera(entity);
- }
-
- this.registry_.addCamera(entity, {
- projectionType: data.projectionType ?? 1,
- fov: data.fov ?? 60,
- orthoSize: data.orthoSize ?? 400,
- nearPlane: data.nearPlane ?? 0.1,
- farPlane: data.farPlane ?? 1000,
- aspectRatio: data.aspectRatio ?? 1.0,
- isActive: data.isActive ?? true,
- priority: data.priority ?? 0,
- });
- }
-
- private syncText(entity: Entity, data: any, entityId: number): void {
- if (!this.registry_ || !this.textRenderer_) return;
-
- const entityData = this.entityDataMap_.get(entityId);
- const uiRect = entityData ? this.getUIRect(entityData) : null;
-
- const result = this.textRenderer_.renderText(entityId, data, uiRect);
- if (!result) return;
-
- if (this.registry_.hasSprite(entity)) {
- this.registry_.removeSprite(entity);
- }
-
- this.registry_.addSprite(entity, {
- texture: result.textureHandle,
- color: { x: 1, y: 1, z: 1, w: 1 },
- size: { x: result.width, y: result.height },
- uvOffset: { x: 0, y: 0 },
- uvScale: { x: 1, y: 1 },
- layer: 25,
- flipX: false,
- flipY: false,
- });
- }
-
- private async syncSpineAnimation(entity: Entity, data: any): Promise<void> {
- if (!this.registry_ || !this.assetLoader_) return;
-
- const skeletonPath = data.skeletonPath ?? '';
- const atlasPath = data.atlasPath ?? '';
-
- if (!skeletonPath || !atlasPath) {
- console.warn('[EditorSceneRenderer] SpineAnimation missing skeleton or atlas path');
- return;
- }
-
- const result = await this.assetLoader_.loadSpine(skeletonPath, atlasPath);
- if (!result.success) {
- console.warn(`[EditorSceneRenderer] Failed to load Spine: ${result.error}`);
- return;
- }
-
- if (this.registry_.hasSpineAnimation(entity)) {
- this.registry_.removeSpineAnimation(entity);
- }
-
- this.registry_.addSpineAnimation(entity, {
- skeletonPath,
- atlasPath,
- skin: data.skin ?? 'default',
- animation: data.animation ?? '',
- timeScale: data.timeScale ?? 1,
- loop: data.loop ?? true,
- playing: data.playing ?? true,
- flipX: data.flipX ?? false,
- flipY: data.flipY ?? false,
- color: data.color ?? { x: 1, y: 1, z: 1, w: 1 },
- layer: data.layer ?? 0,
- skeletonScale: data.skeletonScale ?? 1,
- });
- }
}
diff --git a/editor/src/renderer/EditorTextRenderer.ts b/editor/src/renderer/EditorTextRenderer.ts
deleted file mode 100644
index 71a90a09a..000000000
--- a/editor/src/renderer/EditorTextRenderer.ts
+++ /dev/null
@@ -1,280 +0,0 @@
-/**
- * @file EditorTextRenderer.ts
- * @brief Renders text to GPU textures for editor scene view
- */
-
-import type { ESEngineModule } from 'esengine';
-
-// =============================================================================
-// Text Render Result
-// =============================================================================
-
-export interface TextRenderResult {
- textureHandle: number;
- width: number;
- height: number;
-}
-
-// =============================================================================
-// EditorTextRenderer
-// =============================================================================
-
-export class EditorTextRenderer {
- private canvas_: OffscreenCanvas | HTMLCanvasElement;
- private ctx_: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
- private module_: ESEngineModule;
- private cache_ = new Map<number, TextRenderResult>();
-
- constructor(module: ESEngineModule) {
- this.module_ = module;
-
- if (typeof OffscreenCanvas !== 'undefined') {
- this.canvas_ = new OffscreenCanvas(512, 512);
- this.ctx_ = this.canvas_.getContext('2d', { willReadFrequently: true })!;
- } else {
- this.canvas_ = document.createElement('canvas');
- this.canvas_.width = 512;
- this.canvas_.height = 512;
- this.ctx_ = this.canvas_.getContext('2d', { willReadFrequently: true })!;
- }
- }
-
- renderText(entityId: number, data: any, uiRect?: { size: { x: number; y: number } } | null): TextRenderResult | null {
- const existing = this.cache_.get(entityId);
- if (existing) {
- const rm = this.module_.getResourceManager();
- rm.releaseTexture(existing.textureHandle);
- }
-
- const result = this.renderTextInternal(data, uiRect);
- if (result) {
- this.cache_.set(entityId, result);
- }
- return result;
- }
-
- releaseAll(): void {
- const rm = this.module_.getResourceManager();
- for (const result of this.cache_.values()) {
- rm.releaseTexture(result.textureHandle);
- }
- this.cache_.clear();
- }
-
- // =========================================================================
- // Private Methods
- // =========================================================================
-
- private renderTextInternal(data: any, uiRect?: { size: { x: number; y: number } } | null): TextRenderResult | null {
- const content = data.content ?? '';
- if (!content) return null;
-
- const fontFamily = data.fontFamily ?? 'Arial';
- const fontSize = data.fontSize ?? 24;
- const color = data.color ?? { x: 1, y: 1, z: 1, w: 1 };
- const align = data.align ?? 0;
- const verticalAlign = data.verticalAlign ?? 0;
- const wordWrap = data.wordWrap ?? true;
- const overflow = data.overflow ?? 0;
- const lineHeight = data.lineHeight ?? 1.2;
-
- const ctx = this.ctx_;
- const canvas = this.canvas_;
-
- ctx.font = `${fontSize}px ${fontFamily}`;
-
- const hasContainer = uiRect && uiRect.size.x > 0 && uiRect.size.y > 0;
- const containerWidth = hasContainer ? uiRect!.size.x : 0;
- const containerHeight = hasContainer ? uiRect!.size.y : 0;
-
- const shouldWrap = wordWrap && hasContainer;
- let lines = this.wrapText(content, shouldWrap ? containerWidth : 0);
- const lineHeightPx = Math.ceil(fontSize * lineHeight);
- const padding = Math.ceil(fontSize * 0.2);
-
- const measuredWidth = Math.ceil(this.measureWidth(lines));
- const measuredHeight = Math.ceil(lines.length * lineHeightPx);
-
- const width = hasContainer ? Math.ceil(containerWidth) : measuredWidth + padding * 2;
- const height = hasContainer ? Math.ceil(containerHeight) : measuredHeight + padding * 2;
-
- // Handle overflow ellipsis
- if (hasContainer && overflow === 2 && measuredHeight > containerHeight) {
- const maxLines = Math.floor(containerHeight / lineHeightPx);
- if (maxLines > 0 && lines.length > maxLines) {
- lines = lines.slice(0, maxLines);
- const lastLine = lines[maxLines - 1];
- lines[maxLines - 1] = this.truncateWithEllipsis(lastLine, containerWidth);
- }
- }
-
- if (canvas.width < width || canvas.height < height) {
- const newWidth = Math.max(canvas.width, this.nextPowerOf2(width));
- const newHeight = Math.max(canvas.height, this.nextPowerOf2(height));
- canvas.width = newWidth;
- canvas.height = newHeight;
- }
-
- const r = Math.round(color.x * 255);
- const g = Math.round(color.y * 255);
- const b = Math.round(color.z * 255);
- const a = color.w;
-
- ctx.clearRect(0, 0, canvas.width, canvas.height);
- ctx.font = `${fontSize}px ${fontFamily}`;
- ctx.textAlign = this.mapAlign(align);
- ctx.textBaseline = 'top';
- ctx.fillStyle = `rgba(${r}, ${g}, ${b}, ${a})`;
-
- // Handle overflow clip
- if (hasContainer && overflow === 1) {
- ctx.save();
- ctx.beginPath();
- ctx.rect(0, 0, width, height);
- ctx.clip();
- }
-
- const textBlockHeight = lines.length * lineHeightPx;
- let startY: number;
- if (hasContainer) {
- switch (verticalAlign) {
- case 0: startY = padding; break;
- case 1: startY = (height - textBlockHeight) / 2; break;
- case 2: startY = height - textBlockHeight - padding; break;
- default: startY = padding;
- }
- } else {
- startY = padding;
- }
-
- let y = startY;
- for (const line of lines) {
- let x: number;
- if (hasContainer) {
- switch (align) {
- case 0: x = padding; break;
- case 1: x = width / 2; break;
- case 2: x = width - padding; break;
- default: x = padding;
- }
- } else {
- switch (align) {
- case 0: x = padding; break;
- case 1: x = width / 2; break;
- case 2: x = width - padding; break;
- default: x = padding;
- }
- }
- ctx.fillText(line, x, y);
- y += lineHeightPx;
- }
-
- if (hasContainer && overflow === 1) {
- ctx.restore();
- }
-
- const imageData = ctx.getImageData(0, 0, width, height);
- const pixels = new Uint8Array(imageData.data.buffer);
- const flipped = this.flipVertically(pixels, width, height);
-
- const rm = this.module_.getResourceManager();
- const ptr = this.module_._malloc(flipped.length);
- this.module_.HEAPU8.set(flipped, ptr);
-
- const textureHandle = rm.createTexture(width, height, ptr, flipped.length, 1);
-
- this.module_._free(ptr);
-
- return { textureHandle, width, height };
- }
-
- private truncateWithEllipsis(text: string, maxWidth: number): string {
- const ellipsis = '...';
- const ellipsisWidth = this.ctx_.measureText(ellipsis).width;
-
- if (this.ctx_.measureText(text).width <= maxWidth) {
- return text;
- }
-
- let truncated = text;
- while (truncated.length > 0 && this.ctx_.measureText(truncated + ellipsis).width > maxWidth) {
- truncated = truncated.slice(0, -1);
- }
-
- return truncated + ellipsis;
- }
-
- private wrapText(text: string, maxWidth: number): string[] {
- if (!text) return [''];
- if (maxWidth <= 0) return text.split('\n');
-
- const paragraphs = text.split('\n');
- const lines: string[] = [];
-
- for (const paragraph of paragraphs) {
- if (!paragraph) {
- lines.push('');
- continue;
- }
-
- let currentLine = '';
-
- for (const char of paragraph) {
- const testLine = currentLine + char;
- const metrics = this.ctx_.measureText(testLine);
-
- if (metrics.width > maxWidth && currentLine) {
- lines.push(currentLine);
- currentLine = char;
- } else {
- currentLine = testLine;
- }
- }
- if (currentLine) {
- lines.push(currentLine);
- }
- }
-
- return lines.length > 0 ? lines : [''];
- }
-
- private measureWidth(lines: string[]): number {
- let maxWidth = 0;
- for (const line of lines) {
- const metrics = this.ctx_.measureText(line);
- const width = metrics.actualBoundingBoxLeft !== undefined
- ? metrics.actualBoundingBoxLeft + metrics.actualBoundingBoxRight
- : metrics.width;
- maxWidth = Math.max(maxWidth, width);
- }
- return maxWidth;
- }
-
- private mapAlign(align: number): CanvasTextAlign {
- switch (align) {
- case 0: return 'left';
- case 1: return 'center';
- case 2: return 'right';
- default: return 'left';
- }
- }
-
- private nextPowerOf2(n: number): number {
- let p = 1;
- while (p < n) p *= 2;
- return p;
- }
-
- private flipVertically(pixels: Uint8Array, width: number, height: number): Uint8Array {
- const rowSize = width * 4;
- const flipped = new Uint8Array(pixels.length);
-
- for (let y = 0; y < height; y++) {
- const srcOffset = y * rowSize;
- const dstOffset = (height - 1 - y) * rowSize;
- flipped.set(pixels.subarray(srcOffset, srcOffset + rowSize), dstOffset);
- }
-
- return flipped;
- }
-}
diff --git a/editor/src/renderer/index.ts b/editor/src/renderer/index.ts
index 733e79554..2387e06cc 100644
--- a/editor/src/renderer/index.ts
+++ b/editor/src/renderer/index.ts
@@ -5,5 +5,4 @@
export { EditorSceneRenderer } from './EditorSceneRenderer';
export { EditorTextureManager } from './EditorTextureManager';
-export { EditorTextRenderer } from './EditorTextRenderer';
export { EditorCamera } from './EditorCamera';