diff --git a/packages/core/src/2d/assembler/ISpriteAssembler.ts b/packages/core/src/2d/assembler/ISpriteAssembler.ts index 1b6117d35e..4a446f06d5 100644 --- a/packages/core/src/2d/assembler/ISpriteAssembler.ts +++ b/packages/core/src/2d/assembler/ISpriteAssembler.ts @@ -1,4 +1,4 @@ -import { Vector2, Vector3 } from "@galacean/engine-math"; +import { Matrix, Vector2, Vector3 } from "@galacean/engine-math"; import { ISpriteRenderer } from "./ISpriteRenderer"; /** @@ -8,6 +8,7 @@ export interface ISpriteAssembler { resetData(renderer: ISpriteRenderer, vertexCount?: number): void; updatePositions( renderer: ISpriteRenderer, + worldMatrix: Matrix, width: number, height: number, pivot: Vector2, diff --git a/packages/core/src/2d/assembler/ISpriteRenderer.ts b/packages/core/src/2d/assembler/ISpriteRenderer.ts index 158dbe1ab7..e05ca6b537 100644 --- a/packages/core/src/2d/assembler/ISpriteRenderer.ts +++ b/packages/core/src/2d/assembler/ISpriteRenderer.ts @@ -1,7 +1,6 @@ import { Color } from "@galacean/engine-math"; import { PrimitiveChunkManager } from "../../RenderPipeline/PrimitiveChunkManager"; import { SubPrimitiveChunk } from "../../RenderPipeline/SubPrimitiveChunk"; -import { Transform } from "../../Transform"; import { SpriteTileMode } from "../enums/SpriteTileMode"; import { Sprite } from "../sprite"; @@ -10,7 +9,6 @@ export interface ISpriteRenderer { color?: Color; tileMode?: SpriteTileMode; tiledAdaptiveThreshold?: number; - _transform: Transform; _subChunk: SubPrimitiveChunk; _getChunkManager(): PrimitiveChunkManager; } diff --git a/packages/core/src/2d/assembler/SimpleSpriteAssembler.ts b/packages/core/src/2d/assembler/SimpleSpriteAssembler.ts index 2bc2aeb632..03aa991c22 100644 --- a/packages/core/src/2d/assembler/SimpleSpriteAssembler.ts +++ b/packages/core/src/2d/assembler/SimpleSpriteAssembler.ts @@ -9,7 +9,7 @@ import { ISpriteRenderer } from "./ISpriteRenderer"; @StaticInterfaceImplement() export class SimpleSpriteAssembler { private static _rectangleTriangles = [0, 1, 2, 2, 1, 3]; - private static _worldMatrix = new Matrix(); + private static _matrix = new Matrix(); static resetData(renderer: ISpriteRenderer): void { const manager = renderer._getChunkManager(); @@ -22,6 +22,7 @@ export class SimpleSpriteAssembler { static updatePositions( renderer: ISpriteRenderer, + worldMatrix: Matrix, width: number, height: number, pivot: Vector2, @@ -31,10 +32,9 @@ export class SimpleSpriteAssembler { const { sprite } = renderer; const { x: pivotX, y: pivotY } = pivot; // Renderer's worldMatrix - const worldMatrix = SimpleSpriteAssembler._worldMatrix; - const { elements: wE } = worldMatrix; + const { elements: wE } = SimpleSpriteAssembler._matrix; // Parent's worldMatrix - const { elements: pWE } = renderer._transform.worldMatrix; + const { elements: pWE } = worldMatrix; const sx = flipX ? -width : width; const sy = flipY ? -height : height; (wE[0] = pWE[0] * sx), (wE[1] = pWE[1] * sx), (wE[2] = pWE[2] * sx); diff --git a/packages/core/src/2d/assembler/SlicedSpriteAssembler.ts b/packages/core/src/2d/assembler/SlicedSpriteAssembler.ts index 0ffad4a821..39727f2351 100644 --- a/packages/core/src/2d/assembler/SlicedSpriteAssembler.ts +++ b/packages/core/src/2d/assembler/SlicedSpriteAssembler.ts @@ -12,7 +12,7 @@ export class SlicedSpriteAssembler { 0, 1, 4, 1, 5, 4, 1, 2, 5, 2, 6, 5, 2, 3, 6, 3, 7, 6, 4, 5, 8, 5, 9, 8, 5, 6, 9, 6, 10, 9, 6, 7, 10, 7, 11, 10, 8, 9, 12, 9, 13, 12, 9, 10, 13, 10, 14, 13, 10, 11, 14, 11, 15, 14 ]; - private static _worldMatrix = new Matrix(); + private static _matrix = new Matrix(); private static _row = new Array(4); private static _column = new Array(4); @@ -27,6 +27,7 @@ export class SlicedSpriteAssembler { static updatePositions( renderer: ISpriteRenderer, + worldMatrix: Matrix, width: number, height: number, pivot: Vector2, @@ -83,10 +84,9 @@ export class SlicedSpriteAssembler { const localTransX = width * pivotX; const localTransY = height * pivotY; // Renderer's worldMatrix. - const worldMatrix = SlicedSpriteAssembler._worldMatrix; - const { elements: wE } = worldMatrix; + const { elements: wE } = SlicedSpriteAssembler._matrix; // Parent's worldMatrix. - const { elements: pWE } = renderer._transform.worldMatrix; + const { elements: pWE } = worldMatrix; const sx = flipX ? -1 : 1; const sy = flipY ? -1 : 1; (wE[0] = pWE[0] * sx), (wE[1] = pWE[1] * sx), (wE[2] = pWE[2] * sx); diff --git a/packages/core/src/2d/assembler/TiledSpriteAssembler.ts b/packages/core/src/2d/assembler/TiledSpriteAssembler.ts index 0a396aec10..43eaf47c7f 100644 --- a/packages/core/src/2d/assembler/TiledSpriteAssembler.ts +++ b/packages/core/src/2d/assembler/TiledSpriteAssembler.ts @@ -12,7 +12,7 @@ import { SimpleSpriteAssembler } from "./SimpleSpriteAssembler"; */ @StaticInterfaceImplement() export class TiledSpriteAssembler { - private static _worldMatrix = new Matrix(); + private static _matrix = new Matrix(); private static _posRow = new DisorderedArray(); private static _posColumn = new DisorderedArray(); private static _uvRow = new DisorderedArray(); @@ -35,6 +35,7 @@ export class TiledSpriteAssembler { static updatePositions( renderer: ISpriteRenderer, + worldMatrix: Matrix, width: number, height: number, pivot: Vector2, @@ -53,10 +54,9 @@ export class TiledSpriteAssembler { const localTransX = width * pivotX; const localTransY = height * pivotY; // Renderer's worldMatrix - const { _worldMatrix: worldMatrix } = TiledSpriteAssembler; - const { elements: wE } = worldMatrix; + const { elements: wE } = TiledSpriteAssembler._matrix; // Parent's worldMatrix - const { elements: pWE } = renderer._transform.worldMatrix; + const { elements: pWE } = worldMatrix; const sx = flipX ? -1 : 1; const sy = flipY ? -1 : 1; let wE0: number, wE1: number, wE2: number; diff --git a/packages/core/src/2d/sprite/SpriteMask.ts b/packages/core/src/2d/sprite/SpriteMask.ts index f611d74754..eddd97ea15 100644 --- a/packages/core/src/2d/sprite/SpriteMask.ts +++ b/packages/core/src/2d/sprite/SpriteMask.ts @@ -154,7 +154,10 @@ export class SpriteMask extends Renderer implements ISpriteRenderer { this.shaderData.setTexture(SpriteMask._textureProperty, null); } this._sprite = value; - this._calDefaultSize(); + if (this._customWidth === undefined || this._customHeight === undefined) { + this._calDefaultSize(); + this._dirtyUpdateFlag |= RendererUpdateFlags.AllPositionAndBounds; + } } } @@ -274,7 +277,15 @@ export class SpriteMask extends Renderer implements ISpriteRenderer { // Update position if (this._dirtyUpdateFlag & RendererUpdateFlags.AllPositions) { - SimpleSpriteAssembler.updatePositions(this, this.width, this.height, sprite.pivot, this._flipX, this._flipY); + SimpleSpriteAssembler.updatePositions( + this, + this._transformEntity.transform.worldMatrix, + this.width, + this.height, + sprite.pivot, + this._flipX, + this._flipY + ); this._dirtyUpdateFlag &= ~RendererUpdateFlags.AllPositions; } diff --git a/packages/core/src/2d/sprite/SpriteRenderer.ts b/packages/core/src/2d/sprite/SpriteRenderer.ts index 8e539482e2..7ce6d2be20 100644 --- a/packages/core/src/2d/sprite/SpriteRenderer.ts +++ b/packages/core/src/2d/sprite/SpriteRenderer.ts @@ -349,6 +349,7 @@ export class SpriteRenderer extends Renderer implements ISpriteRenderer { if (this._dirtyUpdateFlag & RendererUpdateFlags.AllPositions) { this._assembler.updatePositions( this, + this._transformEntity.transform.worldMatrix, this.width, this.height, sprite.pivot, diff --git a/packages/core/src/ComponentsDependencies.ts b/packages/core/src/ComponentsDependencies.ts index 32f1e7a9ab..bea9f8cfac 100644 --- a/packages/core/src/ComponentsDependencies.ts +++ b/packages/core/src/ComponentsDependencies.ts @@ -11,7 +11,6 @@ export class ComponentsDependencies { private static _invDependenciesMap = new Map(); static _dependenciesMap = new Map(); - static _inheritedMap = new Map(); /** * @internal @@ -40,7 +39,13 @@ export class ComponentsDependencies { * @internal */ static _removeCheck(entity: Entity, type: ComponentConstructor): void { + const components = entity._components; + const n = components.length; while (type !== Component) { + let count = 0; + for (let i = 0; i < n; i++) { + if (components[i] instanceof type && ++count > 1) return; + } const invDependencies = ComponentsDependencies._invDependenciesMap.get(type); if (invDependencies) { for (let i = 0, len = invDependencies.length; i < len; i++) { @@ -53,15 +58,6 @@ export class ComponentsDependencies { } } - /** - * @internal - */ - static _createChildCheck(child: Entity, type: ComponentConstructor): void { - if (ComponentsDependencies._inheritedMap.get(type)) { - child.addComponent(type); - } - } - /** * @internal */ @@ -94,12 +90,6 @@ export class ComponentsDependencies { private constructor() {} } -export function markAsInherited() { - return function (target: T): void { - ComponentsDependencies._inheritedMap.set(target, true); - }; -} - /** * Declare dependent component. * @param component - Dependent component diff --git a/packages/core/src/ComponentsManager.ts b/packages/core/src/ComponentsManager.ts index f49016d3d6..ed8b0900ce 100644 --- a/packages/core/src/ComponentsManager.ts +++ b/packages/core/src/ComponentsManager.ts @@ -1,4 +1,4 @@ -import { IUICanvas, IUIElement } from "@galacean/engine-design"; +import { IUICanvas } from "@galacean/engine-design"; import { Camera } from "./Camera"; import { Component } from "./Component"; import { Renderer } from "./Renderer"; @@ -39,9 +39,6 @@ export class ComponentsManager { // Render private _onUpdateRenderers: DisorderedArray = new DisorderedArray(); - // UIElement - private _onUpdateUIElements: DisorderedArray = new DisorderedArray(); - // Delay dispose active/inActive Pool private _componentsContainerPool: Component[][] = []; @@ -182,17 +179,6 @@ export class ComponentsManager { renderer._onUpdateIndex = -1; } - addOnUpdateUIElement(element: IUIElement): void { - element._onUIUpdateIndex = this._onUpdateRenderers.length; - this._onUpdateUIElements.add(element); - } - - removeOnUpdateUIElement(element: IUIElement): void { - const replaced = this._onUpdateUIElements.deleteByIndex(element._onUIUpdateIndex); - replaced && (replaced._onUIUpdateIndex = element._onUIUpdateIndex); - element._onUIUpdateIndex = -1; - } - addPendingDestroyScript(component: Script): void { this._pendingDestroyScripts.push(component); } @@ -269,12 +255,6 @@ export class ComponentsManager { ); } - callUIOnUpdate(deltaTime: number): void { - this._onUpdateUIElements.forEach((element: IUIElement) => { - element._onUpdate(); - }); - } - handlingInvalidScripts(): void { const { _disposeDestroyScripts: pendingDestroyScripts, _pendingDestroyScripts: disposeDestroyScripts } = this; this._disposeDestroyScripts = disposeDestroyScripts; diff --git a/packages/core/src/Engine.ts b/packages/core/src/Engine.ts index 2bd1b0ea2e..17c5f249c5 100644 --- a/packages/core/src/Engine.ts +++ b/packages/core/src/Engine.ts @@ -480,9 +480,7 @@ export class Engine extends EventDispatcher { for (let i = 0, n = scenes.length; i < n; i++) { const scene = scenes[i]; if (!scene.isActive || scene.destroyed) continue; - const componentsManager = scene._componentsManager; - componentsManager.callUIOnUpdate(deltaTime); - componentsManager.callRendererOnUpdate(deltaTime); + scene._componentsManager.callRendererOnUpdate(deltaTime); scene._updateShaderData(); } diff --git a/packages/core/src/Entity.ts b/packages/core/src/Entity.ts index 338ade02d1..e83d818a81 100644 --- a/packages/core/src/Entity.ts +++ b/packages/core/src/Entity.ts @@ -99,8 +99,9 @@ export class Entity extends EngineObject { /** @internal */ _updateFlagManager: UpdateFlagManager = new UpdateFlagManager(); /** @internal */ - _transform: Transform; + _modifyFlagManager: UpdateFlagManager; + private _transform: Transform; private _templateResource: ReferResource; private _parent: Entity = null; private _activeChangedComponents: Component[]; @@ -228,6 +229,13 @@ export class Entity extends EngineObject { ComponentsDependencies._addCheck(this, type); const component = new type(this, ...args) as InstanceType; this._components.push(component); + + // @todo: temporary solution + if (component instanceof Transform) { + const transform = this._transform; + this._transform = component; + transform?.destroy(); + } component._setActive(true, ActiveChangeFlag.All); return component; } @@ -550,7 +558,7 @@ export class Entity extends EngineObject { * @internal */ _removeComponent(component: Component): void { - ComponentsDependencies._removeCheck(this, component.constructor as any); + ComponentsDependencies._removeCheck(this, component.constructor as ComponentConstructor); const components = this._components; components.splice(components.indexOf(component), 1); } @@ -625,21 +633,21 @@ export class Entity extends EngineObject { * @internal */ _registerModifyListener(onChange: (flag: EntityModifyFlags) => void): void { - (this._updateFlagManager ||= new UpdateFlagManager()).addListener(onChange); + (this._modifyFlagManager ||= new UpdateFlagManager()).addListener(onChange); } /** * @internal */ _unRegisterModifyListener(onChange: (flag: EntityModifyFlags) => void): void { - this._updateFlagManager?.removeListener(onChange); + this._modifyFlagManager?.removeListener(onChange); } /** * @internal */ _dispatchModify(flag: EntityModifyFlags, param?: any): void { - this._updateFlagManager?.dispatch(flag, param); + this._modifyFlagManager?.dispatch(flag, param); } private _addToChildrenList(index: number, child: Entity): void { diff --git a/packages/core/src/RenderPipeline/RenderQueue.ts b/packages/core/src/RenderPipeline/RenderQueue.ts index de43edb770..6440a549d8 100644 --- a/packages/core/src/RenderPipeline/RenderQueue.ts +++ b/packages/core/src/RenderPipeline/RenderQueue.ts @@ -186,7 +186,7 @@ export class RenderQueue { renderState._applyStates( engine, - renderer._transformEntity.transform._isFrontFaceInvert(), + renderer._isFrontFaceInvert(), shaderPass._renderStateDataMap, material.shaderData, customStates diff --git a/packages/core/src/Renderer.ts b/packages/core/src/Renderer.ts index bc0d9975ca..cb07946dcc 100644 --- a/packages/core/src/Renderer.ts +++ b/packages/core/src/Renderer.ts @@ -55,9 +55,6 @@ export class Renderer extends Component implements IComponentCustomClone { /** @internal */ @ignoreClone _batchedTransformShaderData: boolean = false; - /** @internal */ - @ignoreClone - _transformEntity: Entity; @ignoreClone protected _overrideUpdate: boolean = false; @@ -71,6 +68,8 @@ export class Renderer extends Component implements IComponentCustomClone { protected _localBounds: BoundingBox = new BoundingBox(); @ignoreClone protected _bounds: BoundingBox = new BoundingBox(); + @ignoreClone + protected _transformEntity: Entity; @deepClone private _shaderData: ShaderData = new ShaderData(ShaderDataGroup.Renderer); @@ -376,6 +375,13 @@ export class Renderer extends Component implements IComponentCustomClone { } } + /** + * @internal + */ + _isFrontFaceInvert(): boolean { + return this._transformEntity.transform._isFrontFaceInvert(); + } + /** * @internal */ @@ -494,7 +500,7 @@ export class Renderer extends Component implements IComponentCustomClone { protected _updateLocalBounds(localBounds: BoundingBox): void {} protected _updateBounds(worldBounds: BoundingBox): void { - BoundingBox.transform(this.localBounds, this._transform.worldMatrix, worldBounds); + BoundingBox.transform(this.localBounds, this._transformEntity.transform.worldMatrix, worldBounds); } protected _render(context: RenderContext): void { diff --git a/packages/core/src/Transform.ts b/packages/core/src/Transform.ts index 5f09803a67..3616b13d2f 100644 --- a/packages/core/src/Transform.ts +++ b/packages/core/src/Transform.ts @@ -340,12 +340,6 @@ export class Transform extends Component { this._worldRotationQuaternion._onValueChanged = this._onWorldRotationQuaternionChanged; //@ts-ignore this._scale._onValueChanged = this._onScaleChanged; - - if (entity._transform) { - throw `Entity already has a transform.`; - } else { - entity._transform = this; - } } /** diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 6a28d2b3ae..e017d663ee 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -12,7 +12,7 @@ export { Entity } from "./Entity"; export { Component } from "./Component"; export { Script } from "./Script"; export { Renderer, RendererUpdateFlags } from "./Renderer"; -export { DependentMode, dependentComponents, markAsInherited } from "./ComponentsDependencies"; +export { DependentMode, dependentComponents } from "./ComponentsDependencies"; export { Camera } from "./Camera"; export { Transform } from "./Transform"; export { BoolUpdateFlag } from "./BoolUpdateFlag"; diff --git a/packages/core/src/material/PBRMaterial.ts b/packages/core/src/material/PBRMaterial.ts index 9b0d65ba30..d711947aa9 100644 --- a/packages/core/src/material/PBRMaterial.ts +++ b/packages/core/src/material/PBRMaterial.ts @@ -1,4 +1,4 @@ -import { MathUtil, Vector2, Vector3, Vector4 } from "@galacean/engine-math"; +import { MathUtil, Vector2, Vector3, Vector4, Color } from "@galacean/engine-math"; import { Engine } from "../Engine"; import { ShaderProperty } from "../shader"; import { Shader } from "../shader/Shader"; @@ -25,6 +25,12 @@ export class PBRMaterial extends PBRBaseMaterial { private static _iridescenceTextureProp = ShaderProperty.getByName("material_IridescenceTexture"); private _iridescenceRange = new Vector2(100, 400); + private _sheenEnabled = false; + private static _sheenColorProp = ShaderProperty.getByName("material_SheenColor"); + private static _sheenRoughnessProp = ShaderProperty.getByName("material_SheenRoughness"); + private static _sheenTextureProp = ShaderProperty.getByName("material_SheenTexture"); + private static _sheenRoughnessTextureProp = ShaderProperty.getByName("material_SheenRoughnessTexture"); + /** * Index Of Refraction. * @defaultValue `1.5` @@ -190,7 +196,7 @@ export class PBRMaterial extends PBRBaseMaterial { /** * The range of iridescence thickness, x is minimum, y is maximum. - * @defaultValue `[100, 400]`. + * @defaultValue `[100, 400]` */ get iridescenceThicknessRange(): Vector2 { return this._iridescenceRange; @@ -222,6 +228,67 @@ export class PBRMaterial extends PBRBaseMaterial { } } + /** + * Sheen color. + * @defaultValue `[0,0,0]` + */ + get sheenColor(): Color { + return this.shaderData.getColor(PBRMaterial._sheenColorProp); + } + + set sheenColor(value: Color) { + const sheenColor = this.shaderData.getColor(PBRMaterial._sheenColorProp); + if (value !== sheenColor) { + sheenColor.copyFrom(value); + } + } + + /** + * Sheen roughness, from 0.0 to 1.0. + * @defaultValue `0.0` + */ + get sheenRoughness(): number { + return this.shaderData.getFloat(PBRMaterial._sheenRoughnessProp); + } + + set sheenRoughness(value: number) { + value = Math.max(0, Math.min(1, value)); + this.shaderData.setFloat(PBRMaterial._sheenRoughnessProp, value); + } + + /** + * Sheen color texture, multiply ‘sheenColor’. + */ + get sheenColorTexture(): Texture2D { + return this.shaderData.getTexture(PBRMaterial._sheenTextureProp); + } + + set sheenColorTexture(value: Texture2D) { + this.shaderData.setTexture(PBRMaterial._sheenTextureProp, value); + if (value) { + this.shaderData.enableMacro("MATERIAL_HAS_SHEEN_TEXTURE"); + } else { + this.shaderData.disableMacro("MATERIAL_HAS_SHEEN_TEXTURE"); + } + } + + /** + * Sheen roughness texture. + * @remarks Use alpha channel, and multiply 'sheenRoughness'. + */ + get sheenRoughnessTexture(): Texture2D { + return this.shaderData.getTexture(PBRMaterial._sheenRoughnessTextureProp); + } + + set sheenRoughnessTexture(value: Texture2D) { + this.shaderData.setTexture(PBRMaterial._sheenRoughnessTextureProp, value); + if (value) { + this.shaderData.enableMacro("MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE"); + } else { + this.shaderData.disableMacro("MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE"); + } + } + /** * Create a pbr metallic-roughness workflow material instance. * @param engine - Engine to which the material belongs @@ -235,8 +302,22 @@ export class PBRMaterial extends PBRBaseMaterial { shaderData.setFloat(PBRMaterial._iorProp, 1.5); shaderData.setVector3(PBRMaterial._anisotropyInfoProp, new Vector3(1, 0, 0)); shaderData.setVector4(PBRMaterial._iridescenceInfoProp, new Vector4(0, 1.3, 100, 400)); + const sheenColor = new Color(0, 0, 0); + shaderData.setColor(PBRMaterial._sheenColorProp, sheenColor); // @ts-ignore this._iridescenceRange._onValueChanged = this._onIridescenceRangeChanged.bind(this); + // @ts-ignore + sheenColor._onValueChanged = () => { + const enableSheen = sheenColor.r + sheenColor.g + sheenColor.b > 0; + if (enableSheen !== this._sheenEnabled) { + this._sheenEnabled = enableSheen; + if (enableSheen) { + this.shaderData.enableMacro("MATERIAL_ENABLE_SHEEN"); + } else { + this.shaderData.disableMacro("MATERIAL_ENABLE_SHEEN"); + } + } + }; } private _onIridescenceRangeChanged(): void { diff --git a/packages/core/src/mesh/MeshRenderer.ts b/packages/core/src/mesh/MeshRenderer.ts index 95c0c72b9f..a7978a7dbb 100644 --- a/packages/core/src/mesh/MeshRenderer.ts +++ b/packages/core/src/mesh/MeshRenderer.ts @@ -188,11 +188,11 @@ export class MeshRenderer extends Renderer { } /** - * @remarks Extends `RendererUpdateFlag`. + * @remarks Extends `RendererUpdateFlags`. */ enum MeshRendererUpdateFlags { /** VertexElementMacro. */ - VertexElementMacro = 0x2, + VertexElementMacro = 0x10, /** All. */ - All = 0x3 + All = 0x1f } diff --git a/packages/core/src/physics/joint/Joint.ts b/packages/core/src/physics/joint/Joint.ts index d86fae052c..7b81f6c1b8 100644 --- a/packages/core/src/physics/joint/Joint.ts +++ b/packages/core/src/physics/joint/Joint.ts @@ -1,11 +1,11 @@ import { IJoint } from "@galacean/engine-design"; import { Vector3 } from "@galacean/engine-math"; -import { deepClone, ignoreClone } from "../../clone/CloneManager"; import { Component } from "../../Component"; -import { dependentComponents, DependentMode } from "../../ComponentsDependencies"; +import { DependentMode, dependentComponents } from "../../ComponentsDependencies"; import { Entity } from "../../Entity"; -import { Collider } from "../Collider"; import { TransformModifyFlags } from "../../Transform"; +import { deepClone, ignoreClone } from "../../clone/CloneManager"; +import { Collider } from "../Collider"; /** * A base class providing common functionality for joints. @@ -33,8 +33,9 @@ export abstract class Joint extends Component { } set connectedCollider(value: Collider) { - if (this._connectedColliderInfo.collider !== value) { - this._connectedColliderInfo.collider?.entity._updateFlagManager.removeListener(this._onConnectedTransformChanged); + const preCollider = this._connectedColliderInfo.collider; + if (preCollider !== value) { + preCollider?.entity._updateFlagManager.removeListener(this._onConnectedTransformChanged); value?.entity._updateFlagManager.addListener(this._onConnectedTransformChanged); this._connectedColliderInfo.collider = value; this._nativeJoint?.setConnectedCollider(value._nativeCollider); diff --git a/packages/design/src/ui/IUIElement.ts b/packages/design/src/ui/IUIElement.ts deleted file mode 100644 index 1395bddef6..0000000000 --- a/packages/design/src/ui/IUIElement.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface IUIElement { - _onUIUpdateIndex: number; - _onUpdate(): void; -} diff --git a/packages/design/src/ui/index.ts b/packages/design/src/ui/index.ts index b34b368166..eb1df2dabf 100644 --- a/packages/design/src/ui/index.ts +++ b/packages/design/src/ui/index.ts @@ -1,2 +1 @@ export type { IUICanvas } from "./IUICanvas"; -export type { IUIElement } from "./IUIElement"; diff --git a/packages/loader/src/gltf/extensions/KHR_materials_sheen.ts b/packages/loader/src/gltf/extensions/KHR_materials_sheen.ts index e69de29bb2..426f15820d 100644 --- a/packages/loader/src/gltf/extensions/KHR_materials_sheen.ts +++ b/packages/loader/src/gltf/extensions/KHR_materials_sheen.ts @@ -0,0 +1,41 @@ +import { PBRMaterial, Texture2D } from "@galacean/engine-core"; +import { Color } from "@galacean/engine-math"; +import { GLTFMaterialParser } from "../parser/GLTFMaterialParser"; +import { registerGLTFExtension } from "../parser/GLTFParser"; +import { GLTFParserContext, GLTFParserType } from "../parser/GLTFParserContext"; +import { GLTFExtensionMode, GLTFExtensionParser } from "./GLTFExtensionParser"; +import { IKHRMaterialsSheen } from "./GLTFExtensionSchema"; + +@registerGLTFExtension("KHR_materials_sheen", GLTFExtensionMode.AdditiveParse) +class KHR_materials_sheen extends GLTFExtensionParser { + override additiveParse(context: GLTFParserContext, material: PBRMaterial, schema: IKHRMaterialsSheen): void { + const { sheenColorFactor, sheenColorTexture, sheenRoughnessFactor = 0, sheenRoughnessTexture } = schema; + + if (sheenColorFactor) { + material.sheenColor.set( + Color.linearToGammaSpace(sheenColorFactor[0]), + Color.linearToGammaSpace(sheenColorFactor[1]), + Color.linearToGammaSpace(sheenColorFactor[2]), + undefined + ); + } + + material.sheenRoughness = sheenRoughnessFactor; + + if (sheenColorTexture) { + GLTFMaterialParser._checkOtherTextureTransform(sheenColorTexture, "Sheen texture"); + + context.get(GLTFParserType.Texture, sheenColorTexture.index).then((texture) => { + material.sheenColorTexture = texture; + }); + } + + if (sheenRoughnessTexture) { + GLTFMaterialParser._checkOtherTextureTransform(sheenRoughnessTexture, "SheenRoughness texture"); + + context.get(GLTFParserType.Texture, sheenRoughnessTexture.index).then((texture) => { + material.sheenRoughnessTexture = texture; + }); + } + } +} diff --git a/packages/ui/src/Utils.ts b/packages/ui/src/Utils.ts index 23593b3477..a788fe8968 100644 --- a/packages/ui/src/Utils.ts +++ b/packages/ui/src/Utils.ts @@ -35,7 +35,7 @@ export class Utils { listeningEntities.length = 0; } - static getCanvasInParents(entity: Entity, root?: Entity): UICanvas { + static getRootCanvasInParents(entity: Entity, root?: Entity): UICanvas { entity = entity.parent; let rootCanvas: UICanvas = null; while (entity && entity !== root) { @@ -56,8 +56,7 @@ export class Utils { } static getGroupInParents(entity: Entity, canvasEntity: Entity): UIGroup { - entity = entity.parent; - const root = canvasEntity?.parent; + const root = canvasEntity.parent; while (entity && entity !== root) { // @ts-ignore const components = entity._components; @@ -93,6 +92,15 @@ export class Utils { Utils._registerListener(element.entity, canvas?.entity, element._canvasListener, element._canvasListeningEntities); } + static _registerCanvasToCanvasListener(canvas: UICanvas, rootCanvas: UICanvas): void { + Utils._registerListener( + canvas.entity.parent, + rootCanvas?.entity, + canvas._canvasListener, + canvas._canvasListeningEntities + ); + } + static _registerElementToGroup(element: IGroupAble, pre: UIGroup, cur: UIGroup): void { if (pre !== cur) { if (pre) { @@ -114,6 +122,10 @@ export class Utils { Utils._registerListener(element.entity, canvas?.entity, element._groupListener, element._groupListeningEntities); } + static _registerGroupToGroupListener(group: UIGroup, canvas: UICanvas): void { + Utils._registerListener(group.entity.parent, canvas?.entity, group._groupListener, group._groupListeningEntities); + } + static _onGroupDirty(element: IGroupAble, preGroup: UIGroup): void { if (element._isGroupDirty) return; element._isGroupDirty = true; diff --git a/packages/ui/src/component/UICanvas.ts b/packages/ui/src/component/UICanvas.ts index 0515be54d4..bc297e7704 100644 --- a/packages/ui/src/component/UICanvas.ts +++ b/packages/ui/src/component/UICanvas.ts @@ -167,17 +167,13 @@ export class UICanvas extends Component implements IElement { set distance(val: number) { if (this._distance !== val) { this._distance = val; - this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera && this._adapterPoseInScreenSpace(); + if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) { + this._adapterPoseInScreenSpace(); + this._adapterSizeInScreenSpace(); + } } } - /** - * @internal - */ - get canvas(): UICanvas { - return this._canvas; - } - /** * @internal */ @@ -211,6 +207,13 @@ export class UICanvas extends Component implements IElement { return false; } + /** + * @internal + */ + _getCanvas(): UICanvas { + return this._canvas; + } + /** * @internal */ @@ -276,14 +279,14 @@ export class UICanvas extends Component implements IElement { const entity = this.entity; // @ts-ignore entity._dispatchModify(EntityUIModifyFlags.CanvasEnableInScene, this); - const rootCanvas = Utils.getCanvasInParents(entity); + const rootCanvas = Utils.getRootCanvasInParents(entity); if (rootCanvas) { this._setIsRootCanvas(false); Utils._registerElementToCanvas(this, null, rootCanvas); } else { this._setIsRootCanvas(true); } - Utils._registerElementToCanvasListener(this, rootCanvas); + Utils._registerCanvasToCanvasListener(this, rootCanvas); } // @ts-ignore @@ -299,29 +302,28 @@ export class UICanvas extends Component implements IElement { _canvasListener(flag: number, param: any): void { if (this._isRootCanvas) { if (flag === EntityModifyFlags.Parent) { - const entity = this.entity; - const rootCanvas = Utils.getCanvasInParents(entity); + const rootCanvas = Utils.getRootCanvasInParents(this.entity); if (rootCanvas) { this._setIsRootCanvas(false); Utils._registerElementToCanvas(this, null, rootCanvas); } - Utils._registerElementToCanvasListener(this, rootCanvas); + Utils._registerCanvasToCanvasListener(this, rootCanvas); } else if (flag === EntityUIModifyFlags.CanvasEnableInScene) { this._setIsRootCanvas(false); const rootCanvas = param as UICanvas; Utils._registerElementToCanvas(this, null, rootCanvas); - Utils._registerElementToCanvasListener(this, rootCanvas); + Utils._registerCanvasToCanvasListener(this, rootCanvas); } } else { if (flag === EntityModifyFlags.Parent) { - const rootCanvas = Utils.getCanvasInParents(this.entity); + const rootCanvas = Utils.getRootCanvasInParents(this.entity); if (rootCanvas) { this._setIsRootCanvas(false); Utils._registerElementToCanvas(this, this._canvas, rootCanvas); } else { this._setIsRootCanvas(true); } - Utils._registerElementToCanvasListener(this, rootCanvas); + Utils._registerCanvasToCanvasListener(this, rootCanvas); } } } @@ -447,13 +449,13 @@ export class UICanvas extends Component implements IElement { this._cameraObserver = camera; if (preCamera) { // @ts-ignore - preCamera.entity.transform._updateFlagManager.removeListener(this._onCameraTransformListener); + preCamera.entity._updateFlagManager.removeListener(this._onCameraTransformListener); // @ts-ignore preCamera._unRegisterModifyListener(this._onCameraModifyListener); } if (camera) { // @ts-ignore - camera.entity.transform._updateFlagManager.addListener(this._onCameraTransformListener); + camera.entity._updateFlagManager.addListener(this._onCameraTransformListener); // @ts-ignore camera._registerModifyListener(this._onCameraModifyListener); } @@ -535,7 +537,7 @@ export class UICanvas extends Component implements IElement { const componentType = (element as unknown as Component)._componentType; if (componentType === ComponentType.UICanvas) { const canvas = element as unknown as UICanvas; - const rootCanvas = Utils.getCanvasInParents(element.entity, root); + const rootCanvas = Utils.getRootCanvasInParents(element.entity, root); if (rootCanvas) { canvas._setIsRootCanvas(false); Utils._registerElementToCanvas(canvas, this, rootCanvas); @@ -543,7 +545,7 @@ export class UICanvas extends Component implements IElement { canvas._setIsRootCanvas(true); Utils._registerElementToCanvas(canvas, this, null); } - Utils._registerElementToCanvasListener(canvas, rootCanvas); + Utils._registerCanvasToCanvasListener(canvas, rootCanvas); } else if (componentType === ComponentType.UIRenderer) { Utils._onCanvasDirty(element, this, true); } else { @@ -621,5 +623,5 @@ enum CanvasRealRenderMode { */ export enum EntityUIModifyFlags { CanvasEnableInScene = 0x4, - UIGroupEnableInScene = 0x8 + GroupEnableInScene = 0x8 } diff --git a/packages/ui/src/component/UIGroup.ts b/packages/ui/src/component/UIGroup.ts index f0c561be9e..410ef2ce63 100644 --- a/packages/ui/src/component/UIGroup.ts +++ b/packages/ui/src/component/UIGroup.ts @@ -40,8 +40,6 @@ export class UIGroup extends Component implements IGroupAble { private _interactive = true; @assignmentClone private _ignoreParentGroup = false; - @ignoreClone - private _entityListeners: Entity[] = []; /** @internal */ @ignoreClone @@ -59,40 +57,6 @@ export class UIGroup extends Component implements IGroupAble { @ignoreClone _groupDirtyFlags: number = GroupModifyFlags.None; - /** - * @internal - */ - get canvas(): UICanvas { - if (this._isCanvasDirty) { - const curCanvas = Utils.getCanvasInParents(this.entity); - Utils._registerElementToCanvas(this, this._canvas, curCanvas); - Utils._registerElementToCanvasListener(this, curCanvas); - this._isCanvasDirty = false; - } - return this._canvas; - } - - /** - * @internal - */ - get group(): UIGroup { - if (this._isGroupDirty) { - const canvas = this.canvas; - Utils._registerElementToGroup(this, this._group, Utils.getGroupInParents(this.entity, canvas?.entity)); - Utils._registerElementToGroupListener(this, canvas); - this._isGroupDirty = false; - } - return this._group; - } - - constructor(entity: Entity) { - super(entity); - // @ts-ignore - this._componentType = ComponentType.UIGroup; - this._canvasListener = this._canvasListener.bind(this); - this._groupListener = this._groupListener.bind(this); - } - get ignoreParentGroup(): boolean { return this._ignoreParentGroup; } @@ -129,8 +93,12 @@ export class UIGroup extends Component implements IGroupAble { get globalAlpha(): number { if (this._isContainDirtyFlag(GroupModifyFlags.GlobalAlpha)) { - const parentGroup = this.group; - this._globalAlpha = this._alpha * (parentGroup ? parentGroup.globalAlpha : 1); + if (this._ignoreParentGroup) { + this._globalAlpha = this._alpha; + } else { + const parentGroup = this._getGroup(); + this._globalAlpha = this._alpha * (parentGroup ? parentGroup.globalAlpha : 1); + } this._setDirtyFlagFalse(GroupModifyFlags.GlobalAlpha); } return this._globalAlpha; @@ -138,19 +106,31 @@ export class UIGroup extends Component implements IGroupAble { get globalInteractive(): boolean { if (this._isContainDirtyFlag(GroupModifyFlags.GlobalInteractive)) { - const parentGroup = this.group; - this._globalInteractive = this._interactive && (!parentGroup || parentGroup.globalInteractive); + if (this._ignoreParentGroup) { + this._globalInteractive = this._interactive; + } else { + const parentGroup = this._getGroup(); + this._globalInteractive = this._interactive && (!parentGroup || parentGroup.globalInteractive); + } this._setDirtyFlagFalse(GroupModifyFlags.GlobalInteractive); } return this._globalInteractive; } + constructor(entity: Entity) { + super(entity); + // @ts-ignore + this._componentType = ComponentType.UIGroup; + this._canvasListener = this._canvasListener.bind(this); + this._groupListener = this._groupListener.bind(this); + } + // @ts-ignore override _onEnableInScene(): void { - Utils._onGroupDirty(this, this._group); Utils._onCanvasDirty(this, this._canvas); + Utils._onGroupDirty(this, this._group); // @ts-ignore - this.entity._dispatchModify(EntityUIModifyFlags.UIGroupEnableInScene); + this.entity._dispatchModify(EntityUIModifyFlags.GroupEnableInScene); } // @ts-ignore @@ -166,13 +146,40 @@ export class UIGroup extends Component implements IGroupAble { this._isCanvasDirty = this._isGroupDirty = false; } + /** + * @internal + */ + _getCanvas(): UICanvas { + if (this._isCanvasDirty) { + const curCanvas = Utils.getRootCanvasInParents(this.entity); + Utils._registerElementToCanvas(this, this._canvas, curCanvas); + Utils._registerElementToCanvasListener(this, curCanvas); + this._isCanvasDirty = false; + } + return this._canvas; + } + + /** + * @internal + */ + _getGroup(): UIGroup { + if (this._isGroupDirty) { + const canvas = this._getCanvas(); + const group = canvas ? Utils.getGroupInParents(this.entity.parent, canvas.entity) : null; + Utils._registerElementToGroup(this, this._group, group); + Utils._registerGroupToGroupListener(this, canvas); + this._isGroupDirty = false; + } + return this._group; + } + /** * @internal */ @ignoreClone _groupListener(flag: number): void { if (this._isGroupDirty) return; - if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.UIGroupEnableInScene) { + if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) { Utils._onGroupDirty(this, this._group); } } @@ -183,7 +190,7 @@ export class UIGroup extends Component implements IGroupAble { @ignoreClone _canvasListener(flag: number): void { if (this._isCanvasDirty) return; - if (flag === EntityModifyFlags.Parent) { + if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) { Utils._onCanvasDirty(this, this._canvas); Utils._onGroupDirty(this, this._group); } @@ -192,13 +199,13 @@ export class UIGroup extends Component implements IGroupAble { /** * @internal */ - _onGroupModify(flags: GroupModifyFlags): void { - if (!this._isContainDirtyFlags(flags)) { - this._setDirtyFlagTrue(flags); - this._disorderedElements.forEach((element) => { - element._onGroupModify(flags); - }); - } + _onGroupModify(flags: GroupModifyFlags, isPass: boolean = false): void { + if (isPass && this._ignoreParentGroup) return; + if (this._isContainDirtyFlags(flags)) return; + this._setDirtyFlagTrue(flags); + this._disorderedElements.forEach((element) => { + element._onGroupModify(flags, true); + }); } private _isContainDirtyFlags(targetDirtyFlags: number): boolean { diff --git a/packages/ui/src/component/UIRenderer.ts b/packages/ui/src/component/UIRenderer.ts index dd16c61929..4fdd4d43dc 100644 --- a/packages/ui/src/component/UIRenderer.ts +++ b/packages/ui/src/component/UIRenderer.ts @@ -100,32 +100,6 @@ export abstract class UIRenderer extends Renderer implements IGraphics { this._raycastEnable = val; } - /** - * @internal - */ - get canvas(): UICanvas { - if (this._isCanvasDirty) { - const curCanvas = Utils.getCanvasInParents(this.entity); - Utils._registerElementToCanvas(this, this._canvas, curCanvas); - Utils._registerElementToCanvasListener(this, curCanvas); - this._isCanvasDirty = false; - } - return this._canvas; - } - - /** - * @internal - */ - get group(): UIGroup { - if (this._isGroupDirty) { - const canvas = this.canvas; - Utils._registerElementToGroup(this, this._group, Utils.getGroupInParents(this.entity, canvas?.entity)); - Utils._registerElementToGroupListener(this, canvas); - this._isGroupDirty = false; - } - return this._group; - } - /** * @internal */ @@ -193,13 +167,40 @@ export abstract class UIRenderer extends Renderer implements IGraphics { this._isCanvasDirty = this._isGroupDirty = false; } + /** + * @internal + */ + _getCanvas(): UICanvas { + if (this._isCanvasDirty) { + const curCanvas = Utils.getRootCanvasInParents(this.entity); + Utils._registerElementToCanvas(this, this._canvas, curCanvas); + Utils._registerElementToCanvasListener(this, curCanvas); + this._isCanvasDirty = false; + } + return this._canvas; + } + + /** + * @internal + */ + _getGroup(): UIGroup { + if (this._isGroupDirty) { + const canvas = this._getCanvas(); + const group = canvas ? Utils.getGroupInParents(this.entity, canvas.entity) : null; + Utils._registerElementToGroup(this, this._group, group); + Utils._registerElementToGroupListener(this, canvas); + this._isGroupDirty = false; + } + return this._group; + } + /** * @internal */ @ignoreClone _groupListener(flag: number): void { if (this._isGroupDirty) return; - if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.UIGroupEnableInScene) { + if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) { Utils._onGroupDirty(this, this._group); } } @@ -211,9 +212,9 @@ export abstract class UIRenderer extends Renderer implements IGraphics { _canvasListener(flag: number): void { if (this._isCanvasDirty) return; if (flag === EntityModifyFlags.SiblingIndex) { - const rootCanvas = this._canvas; + const rootCanvas = this._getCanvas(); rootCanvas && (rootCanvas._hierarchyDirty = true); - } else if (flag === EntityModifyFlags.Parent) { + } else if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) { Utils._onCanvasDirty(this, this._canvas, true); Utils._onGroupDirty(this, this._group); } @@ -246,7 +247,7 @@ export abstract class UIRenderer extends Renderer implements IGraphics { */ _raycast(ray: Ray, out: HitResult, distance: number = Number.MAX_SAFE_INTEGER): boolean { const plane = UIRenderer._tempPlane; - const transform = this._transform; + const transform = this._transformEntity.transform; const normal = plane.normal.copyFrom(transform.worldForward); plane.distance = -Vector3.dot(normal, transform.worldPosition); const curDistance = ray.intersectPlane(plane); @@ -270,7 +271,7 @@ export abstract class UIRenderer extends Renderer implements IGraphics { protected _hitTest(localPosition: Vector3): boolean { const { x, y } = localPosition; - const uiTransform = this._transform; + const uiTransform = this._transformEntity.transform; const { x: width, y: height } = uiTransform.size; const { x: pivotX, y: pivotY } = uiTransform.pivot; const { x: paddingLeft, y: paddingBottom, z: paddingRight, w: paddingTop } = this.raycastPadding; diff --git a/packages/ui/src/component/UITransform.ts b/packages/ui/src/component/UITransform.ts index f1b08e18c2..40cfb623a2 100644 --- a/packages/ui/src/component/UITransform.ts +++ b/packages/ui/src/component/UITransform.ts @@ -1,6 +1,5 @@ -import { Entity, Transform, Vector2, deepClone, ignoreClone, markAsInherited } from "@galacean/engine"; +import { Entity, Transform, Vector2, deepClone, ignoreClone } from "@galacean/engine"; -@markAsInherited() export class UITransform extends Transform { @deepClone private _size: Vector2 = new Vector2(100, 100); @@ -30,12 +29,6 @@ export class UITransform extends Transform { constructor(entity: Entity) { super(entity); // @ts-ignore - entity._transform.destroy(); - // @ts-ignore - entity._transform = this; - // @ts-ignore - entity._inverseWorldMatFlag = this.registerWorldChangeFlag(); - // @ts-ignore this._size._onValueChanged = this._onSizeChange.bind(this); // @ts-ignore this._pivot._onValueChanged = this._onPivotChange.bind(this); @@ -44,13 +37,13 @@ export class UITransform extends Transform { @ignoreClone private _onSizeChange(): void { // @ts-ignore - this._updateFlagManager.dispatch(UITransformModifyFlags.Size); + this._entity._updateFlagManager.dispatch(UITransformModifyFlags.Size); } @ignoreClone private _onPivotChange(): void { // @ts-ignore - this._updateFlagManager.dispatch(UITransformModifyFlags.Pivot); + this._entity._updateFlagManager.dispatch(UITransformModifyFlags.Pivot); } } @@ -60,7 +53,7 @@ export class UITransform extends Transform { */ export enum UITransformModifyFlags { /** Size. */ - Size = 0x100, + Size = 0x200, /** Pivot. */ - Pivot = 0x200 + Pivot = 0x400 } diff --git a/packages/ui/src/component/advanced/Image.ts b/packages/ui/src/component/advanced/Image.ts index c1b0190b3c..678965e80f 100644 --- a/packages/ui/src/component/advanced/Image.ts +++ b/packages/ui/src/component/advanced/Image.ts @@ -152,7 +152,7 @@ export class Image extends UIRenderer implements ISpriteRenderer { protected override _hitTest(localPosition: Vector3): boolean { let { x, y } = localPosition; - const uiTransform = this._transform; + const uiTransform = this._transformEntity.transform; const { x: width, y: height } = uiTransform.size; const { x: pivotX, y: pivotY } = uiTransform.pivot; const { x: paddingLeft, y: paddingBottom, z: paddingRight, w: paddingTop } = this.raycastPadding; @@ -187,7 +187,7 @@ export class Image extends UIRenderer implements ISpriteRenderer { protected override _updateLocalBounds(localBounds: BoundingBox): void { if (this._sprite) { - const transform = this._transform; + const transform = this._transformEntity.transform; const { x: width, y: height } = transform.size; const { x: pivotX, y: pivotY } = transform.pivot; localBounds.min.set(-width * pivotX, -height * pivotY, 0); @@ -203,7 +203,7 @@ export class Image extends UIRenderer implements ISpriteRenderer { */ protected override _render(context): void { const { _sprite: sprite } = this; - const transform = this._transform as UITransform; + const transform = this._transformEntity.transform; const { x: width, y: height } = transform.size; if (!sprite?.texture || !width || !height) { return; @@ -226,7 +226,7 @@ export class Image extends UIRenderer implements ISpriteRenderer { let { _dirtyUpdateFlag: dirtyUpdateFlag } = this; // Update position if (dirtyUpdateFlag & RendererUpdateFlags.AllPositions) { - this._assembler.updatePositions(this, width, height, transform.pivot); + this._assembler.updatePositions(this, transform.worldMatrix, width, height, transform.pivot); dirtyUpdateFlag &= ~RendererUpdateFlags.AllPositions; } @@ -245,7 +245,7 @@ export class Image extends UIRenderer implements ISpriteRenderer { this._dirtyUpdateFlag = dirtyUpdateFlag; // Init sub render element. const { engine } = context.camera; - const canvas = this.canvas; + const canvas = this._getCanvas(); const subRenderElement = engine._subRenderElementPool.get(); const subChunk = this._subChunk; subRenderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, this.sprite.texture, subChunk); @@ -332,7 +332,7 @@ export class Image extends UIRenderer implements ISpriteRenderer { } private _getUVByLocalPosition(position: Vector3, out: Vector2): boolean { - const { size, pivot } = this._transform; + const { size, pivot } = this._transformEntity.transform; return this._assembler.getUVByLocalPosition(this, size.x, size.y, pivot, position, out); } } diff --git a/packages/ui/src/component/advanced/Label.ts b/packages/ui/src/component/advanced/Label.ts index d9f0a0eb0c..19a21055d3 100644 --- a/packages/ui/src/component/advanced/Label.ts +++ b/packages/ui/src/component/advanced/Label.ts @@ -210,7 +210,6 @@ export class Label extends UIRenderer implements ITextRenderer { // @ts-ignore this.setMaterial(engine._basicResources.textDefaultMaterial); } - z; /** * @internal @@ -294,7 +293,7 @@ export class Label extends UIRenderer implements ITextRenderer { const engine = context.camera.engine; const textSubRenderElementPool = engine._textSubRenderElementPool; const material = this.getMaterial(); - const canvas = this.canvas; + const canvas = this._getCanvas(); const renderElement = canvas._renderElement; const textChunks = this._textChunks; const isOverlay = canvas._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay; @@ -382,7 +381,7 @@ export class Label extends UIRenderer implements ITextRenderer { const { min, max } = this._localBounds; const charRenderInfos = Label._charRenderInfos; const charFont = this._getSubFont(); - const size = (this._transform).size; + const size = (this._transformEntity.transform).size; const rendererWidth = size.x; const rendererHeight = size.y; const textMetrics = this.enableWrapping @@ -529,7 +528,7 @@ export class Label extends UIRenderer implements ITextRenderer { } private _isTextNoVisible(): boolean { - const size = (this._transform).size; + const size = (this._transformEntity.transform).size; return ( this._text === "" || this._fontSize === 0 || diff --git a/packages/ui/src/component/interactive/UIInteractive.ts b/packages/ui/src/component/interactive/UIInteractive.ts index 060e84e66c..d420c158d7 100644 --- a/packages/ui/src/component/interactive/UIInteractive.ts +++ b/packages/ui/src/component/interactive/UIInteractive.ts @@ -1,4 +1,4 @@ -import { Entity, EntityModifyFlags, PointerEventData, Script, ignoreClone } from "@galacean/engine"; +import { Entity, EntityModifyFlags, Script, ignoreClone } from "@galacean/engine"; import { UIGroup } from "../.."; import { Utils } from "../../Utils"; import { IGroupAble } from "../../interface/IGroupAble"; @@ -45,6 +45,7 @@ export class UIInteractive extends Script implements IGroupAble { protected _state: InteractiveState = InteractiveState.Normal; protected _transitions: Transition[] = []; + /** @todo Multi-touch points are not considered yet. */ private _isPointerInside: boolean = false; private _isPointerDragging: boolean = false; @@ -64,33 +65,25 @@ export class UIInteractive extends Script implements IGroupAble { return this._globalInteractive; } - /** - * @internal - */ - get canvas(): UICanvas { - if (this._isCanvasDirty) { - const curCanvas = Utils.getCanvasInParents(this.entity); - Utils._registerElementToCanvas(this, this._canvas, curCanvas); - Utils._registerElementToCanvasListener(this, curCanvas); - this._isCanvasDirty = false; - } - return this._canvas; + constructor(entity: Entity) { + super(entity); + this._groupListener = this._groupListener.bind(this); + this._canvasListener = this._canvasListener.bind(this); } - /** - * @internal - */ - get group(): UIGroup { - if (this._isGroupDirty) { - const canvas = this.canvas; - Utils._registerElementToGroup(this, this._group, Utils.getGroupInParents(this.entity, canvas?.entity)); - Utils._registerElementToGroupListener(this, canvas); - this._isGroupDirty = false; + getTransitions(type: new (interactive: UIInteractive) => T, results: T[]): T[] { + results.length = 0; + const transitions = this._transitions; + for (let i = 0, n = transitions.length; i < n; i++) { + const transition = transitions[i]; + if (transition instanceof type) { + results.push(transition); + } } - return this._group; + return results; } - getTransition(type: new () => T): T | null { + getTransition(type: new (interactive: UIInteractive) => T): T | null { const transitions = this._transitions; for (let i = 0, n = transitions.length; i < n; i++) { const transition = transitions[i]; @@ -101,34 +94,23 @@ export class UIInteractive extends Script implements IGroupAble { return null; } - addTransition Transition>(type: T): InstanceType { - const transition = new type() as InstanceType; + addTransition Transition>(type: T): InstanceType { + const transition = new type(this) as InstanceType; this._transitions.push(transition); transition._setState(this._state, true); return transition; } - removeTransition(type: new () => T): void { - const transitions = this._transitions; - for (let i = transitions.length - 1; i >= 0; i--) { - const transition = transitions[i]; - if (transition instanceof type) { - transitions.splice(i, 1); - transition._destroy(); - } - } - } - override onUpdate(deltaTime: number): void { - this._interactive && this._transitions.forEach((transition) => transition._onUpdate(deltaTime)); + this.globalInteractive && this._transitions.forEach((transition) => transition._onUpdate(deltaTime)); } - override onPointerBeginDrag(event: PointerEventData): void { + override onPointerBeginDrag(): void { this._isPointerDragging = true; this._updateState(false); } - override onPointerEndDrag(event: PointerEventData): void { + override onPointerEndDrag(): void { this._isPointerDragging = false; this._updateState(false); } @@ -143,12 +125,15 @@ export class UIInteractive extends Script implements IGroupAble { this._updateState(false); } + override onDestroy(): void { + super.onDestroy(); + this._transitions.forEach((transition) => transition.destroy()); + } + // @ts-ignore override _onEnableInScene(): void { // @ts-ignore super._onEnableInScene(); - // @ts-ignore - this.scene._componentsManager.addOnUpdateUIElement(this); Utils._onCanvasDirty(this, this._canvas); Utils._onGroupDirty(this, this._group); this._updateState(true); @@ -158,26 +143,50 @@ export class UIInteractive extends Script implements IGroupAble { override _onDisableInScene(): void { // @ts-ignore super._onDisableInScene(); - // @ts-ignore - this.scene._componentsManager.removeOnUpdateUIElement(this); Utils._unRegisterListener(this._canvasListener, this._canvasListeningEntities); Utils._unRegisterListener(this._groupListener, this._groupListeningEntities); this._isPointerInside = this._isPointerDragging = false; this._isCanvasDirty = this._isGroupDirty = false; } - override onDestroy(): void { - super.onDestroy(); - const transitions = this._transitions; - transitions.forEach((transition) => transition._destroy()); - transitions.length = 0; + /** + * @internal + */ + _getCanvas(): UICanvas { + if (this._isCanvasDirty) { + const curCanvas = Utils.getRootCanvasInParents(this.entity); + Utils._registerElementToCanvas(this, this._canvas, curCanvas); + Utils._registerElementToCanvasListener(this, curCanvas); + this._isCanvasDirty = false; + } + return this._canvas; } /** * @internal */ - _onUpdate(): void { - this._updateGlobalInteractive(); + _getGroup(): UIGroup { + if (this._isGroupDirty) { + const canvas = this._getCanvas(); + const group = canvas ? Utils.getGroupInParents(this.entity, canvas.entity) : null; + Utils._registerElementToGroup(this, this._group, group); + Utils._registerElementToGroupListener(this, canvas); + this._isGroupDirty = false; + } + return this._group; + } + + /** + * @internal + */ + _removeTransition(transition: Transition): void { + const transitions = this._transitions; + for (let i = transitions.length - 1; i >= 0; i--) { + if (transitions[i] === transition) { + transitions.splice(i, 1); + break; + } + } } /** @@ -186,7 +195,7 @@ export class UIInteractive extends Script implements IGroupAble { @ignoreClone _groupListener(flag: number): void { if (this._isGroupDirty) return; - if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.UIGroupEnableInScene) { + if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) { Utils._onGroupDirty(this, this._group); } } @@ -197,7 +206,7 @@ export class UIInteractive extends Script implements IGroupAble { @ignoreClone _canvasListener(flag: number): void { if (this._isCanvasDirty) return; - if (flag === EntityModifyFlags.Parent) { + if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) { Utils._onCanvasDirty(this, this._canvas); Utils._onGroupDirty(this, this._group); } @@ -215,7 +224,7 @@ export class UIInteractive extends Script implements IGroupAble { private _updateGlobalInteractive(): void { if (this._globalInteractiveDirty) { - const group = this.group; + const group = this._getGroup(); const globalInteractive = this._interactive && (!group || group.globalInteractive); if (this._globalInteractive !== globalInteractive) { this._globalInteractive = globalInteractive; @@ -234,7 +243,7 @@ export class UIInteractive extends Script implements IGroupAble { } private _getInteractiveState(): InteractiveState { - if (!this._globalInteractive) { + if (!this.globalInteractive) { return InteractiveState.Disable; } if (this._isPointerDragging) { diff --git a/packages/ui/src/component/interactive/transition/ColorTransition.ts b/packages/ui/src/component/interactive/transition/ColorTransition.ts index b09811a161..4641cc42a7 100644 --- a/packages/ui/src/component/interactive/transition/ColorTransition.ts +++ b/packages/ui/src/component/interactive/transition/ColorTransition.ts @@ -1,12 +1,12 @@ import { Color } from "@galacean/engine"; import { UIRenderer } from "../../UIRenderer"; import { Transition } from "./Transition"; -import { InteractiveState } from "../UIInteractive"; +import { InteractiveState, UIInteractive } from "../UIInteractive"; export class ColorTransition extends Transition { private _color: Color = new Color(); - constructor() { - super(); + constructor(interactive: UIInteractive) { + super(interactive); this._normal = new Color(1, 1, 1, 1); this._hover = new Color(245 / 255, 245 / 255, 245 / 255, 1); this._pressed = new Color(200 / 255, 200 / 255, 200 / 255, 1); diff --git a/packages/ui/src/component/interactive/transition/ScaleTransition.ts b/packages/ui/src/component/interactive/transition/ScaleTransition.ts index e5aaef3b50..5bc4995bca 100644 --- a/packages/ui/src/component/interactive/transition/ScaleTransition.ts +++ b/packages/ui/src/component/interactive/transition/ScaleTransition.ts @@ -1,9 +1,10 @@ import { UIRenderer } from "../../UIRenderer"; +import { UIInteractive } from "../UIInteractive"; import { Transition } from "./Transition"; export class ScaleTransition extends Transition { - constructor() { - super(); + constructor(interactive: UIInteractive) { + super(interactive); this._normal = 1; this._hover = 1; this._pressed = 1.2; diff --git a/packages/ui/src/component/interactive/transition/SpriteTransition.ts b/packages/ui/src/component/interactive/transition/SpriteTransition.ts index f6eb5e8d70..6deaaf7787 100644 --- a/packages/ui/src/component/interactive/transition/SpriteTransition.ts +++ b/packages/ui/src/component/interactive/transition/SpriteTransition.ts @@ -6,7 +6,8 @@ export class SpriteTransition extends Transition { /** * @internal */ - override _destroy(): void { + override destroy(): void { + super.destroy(); if (this._normal) { // @ts-ignore this._normal._addReferCount(-1); diff --git a/packages/ui/src/component/interactive/transition/Transition.ts b/packages/ui/src/component/interactive/transition/Transition.ts index 52883bacab..a4e84e907b 100644 --- a/packages/ui/src/component/interactive/transition/Transition.ts +++ b/packages/ui/src/component/interactive/transition/Transition.ts @@ -1,6 +1,6 @@ import { Color, ReferResource, Sprite } from "@galacean/engine"; import { UIRenderer } from "../../UIRenderer"; -import { InteractiveState } from "../UIInteractive"; +import { InteractiveState, UIInteractive } from "../UIInteractive"; export abstract class Transition< T extends TransitionValueType = TransitionValueType, @@ -93,6 +93,20 @@ export abstract class Transition< } } + /** + * @internal + */ + constructor(protected _interactive: UIInteractive) {} + + destroy(): void { + const interactive = this._interactive; + if (interactive) { + interactive._removeTransition(this); + this._interactive = null; + } + this._target = null; + } + /** * @internal */ @@ -120,13 +134,6 @@ export abstract class Transition< } } - /** - * @internal - */ - _destroy(): void { - this._target = null; - } - protected abstract _getTargetValueCopy(): T; protected abstract _updateCurrentValue(srcValue: T, destValue: T, weight: number): void; protected abstract _applyValue(value: T): void; diff --git a/packages/ui/src/input/UIPointerEventEmitter.ts b/packages/ui/src/input/UIPointerEventEmitter.ts index ec6f982195..4764557728 100644 --- a/packages/ui/src/input/UIPointerEventEmitter.ts +++ b/packages/ui/src/input/UIPointerEventEmitter.ts @@ -86,7 +86,6 @@ export class UIPointerEventEmitter extends PointerEventEmitter { } } } - return null; } override processDrag(pointer: Pointer): void { @@ -226,7 +225,7 @@ export class UIPointerEventEmitter extends PointerEventEmitter { path.length = 1; return path; } else { - const rootEntity = (element as unknown as IGraphics).canvas.entity; + const rootEntity = (element as unknown as IGraphics)._getCanvas().entity; for (; i < UIPointerEventEmitter._MAX_PATH_DEPTH && !!entity && entity !== rootEntity; i++) { entity = path[i] = entity.parent; } diff --git a/packages/ui/src/interface/IElement.ts b/packages/ui/src/interface/IElement.ts index dec42de27e..d8868b6862 100644 --- a/packages/ui/src/interface/IElement.ts +++ b/packages/ui/src/interface/IElement.ts @@ -3,11 +3,10 @@ import { UICanvas } from "../component/UICanvas"; export interface IElement { entity: Entity; - readonly canvas: UICanvas; - _indexInCanvas: number; _isCanvasDirty: boolean; - _canvasListeningEntities: Entity[]; + + _getCanvas(): UICanvas; _canvasListener: (flag: number, param?: any) => void; } diff --git a/packages/ui/src/interface/IGroupAble.ts b/packages/ui/src/interface/IGroupAble.ts index 6ca524dab8..de6fe00155 100644 --- a/packages/ui/src/interface/IGroupAble.ts +++ b/packages/ui/src/interface/IGroupAble.ts @@ -3,15 +3,13 @@ import { GroupModifyFlags, UIGroup } from "../component/UIGroup"; import { IElement } from "./IElement"; export interface IGroupAble extends IElement { - readonly group: UIGroup; _indexInGroup: number; _groupListeningEntities: Entity[]; _isGroupDirty: boolean; - _onUIUpdateIndex?: number; _globalAlpha?: number; _globalInteractive?: boolean; - _onUpdate?(): void; - _onGroupModify(flag: GroupModifyFlags): void; + _getGroup(): UIGroup; + _onGroupModify(flag: GroupModifyFlags, isPass?: boolean): void; _groupListener: (flag: number) => void; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 59463f798c..cf91c844f9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -304,6 +304,9 @@ importers: '@galacean/engine-shader-lab': specifier: workspace:* version: link:../packages/shader-lab + '@galacean/engine-ui': + specifier: workspace:* + version: link:../packages/ui devDependencies: '@vitest/browser': specifier: 2.1.3 diff --git a/tests/package.json b/tests/package.json index ff6a458f72..f0efc25bc0 100644 --- a/tests/package.json +++ b/tests/package.json @@ -23,7 +23,8 @@ "@galacean/engine-rhi-webgl": "workspace:*", "@galacean/engine-physics-lite": "workspace:*", "@galacean/engine-shader-lab": "workspace:*", - "@galacean/engine-physics-physx": "workspace:*" + "@galacean/engine-physics-physx": "workspace:*", + "@galacean/engine-ui": "workspace:*" }, "devDependencies": { "@vitest/browser": "2.1.3" diff --git a/tests/src/core/2d/text/TextUtils.test.ts b/tests/src/core/2d/text/TextUtils.test.ts index de51cda434..ecac363a30 100644 --- a/tests/src/core/2d/text/TextUtils.test.ts +++ b/tests/src/core/2d/text/TextUtils.test.ts @@ -1,7 +1,17 @@ -import { WebGLEngine } from "@galacean/engine-rhi-webgl"; -import { TextUtils, TextRenderer, Entity, Scene, Camera, Font, FontStyle, OverflowMode } from "@galacean/engine-core"; +import { + Camera, + Engine, + Entity, + Font, + FontStyle, + OverflowMode, + Scene, + TextRenderer, + TextUtils +} from "@galacean/engine-core"; import { Vector3 } from "@galacean/engine-math"; -import {describe, beforeAll, expect, it, afterAll } from "vitest"; +import { WebGLEngine } from "@galacean/engine-rhi-webgl"; +import { afterAll, beforeAll, describe, expect, it } from "vitest"; describe("TextUtils", () => { let engine: WebGLEngine; @@ -116,6 +126,8 @@ describe("TextUtils", () => { const text4 = " \n World"; it("measureTextWithWrap", () => { + // @ts-ignore + const { _pixelsPerUnit } = Engine; textRendererTruncate.overflowMode = OverflowMode.Truncate; textRendererTruncate.fontSize = 24; textRendererTruncate.width = 0.24; @@ -124,28 +136,109 @@ describe("TextUtils", () => { textRendererTruncate.text = text1; textRendererTruncate.bounds; - let result = TextUtils.measureTextWithWrap(textRendererTruncate); + let result = TextUtils.measureTextWithWrap( + textRendererTruncate, + textRendererTruncate.width * _pixelsPerUnit, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(24); expect(result.height).to.be.equal(100); - expect(result.lines).to.be.deep.equal(["趚", "今", "天", "天", "气", "很", "好", ",", "阳", "光", "明", "媚", "。", "我", "在", "公", "园", "里", "漫", "步", "。"]); + expect(result.lines).to.be.deep.equal([ + "趚", + "今", + "天", + "天", + "气", + "很", + "好", + ",", + "阳", + "光", + "明", + "媚", + "。", + "我", + "在", + "公", + "园", + "里", + "漫", + "步", + "。" + ]); expect(result.lineHeight).to.be.equal(27); textRendererTruncate.text = text2; - result = TextUtils.measureTextWithWrap(textRendererTruncate); + result = TextUtils.measureTextWithWrap( + textRendererTruncate, + textRendererTruncate.width * _pixelsPerUnit, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(24); expect(result.height).to.be.equal(100); - expect(result.lines).to.be.deep.equal(['T', 'h', 'e ', 'w', 'e', 'at', 'h', 'er', 'is ', 'gr', 'e', 'at', 'to', 'd', 'a', 'y.']); + expect(result.lines).to.be.deep.equal([ + "T", + "h", + "e ", + "w", + "e", + "at", + "h", + "er", + "is ", + "gr", + "e", + "at", + "to", + "d", + "a", + "y." + ]); expect(result.lineHeight).to.be.equal(27); textRendererTruncate.text = text3; - result = TextUtils.measureTextWithWrap(textRendererTruncate); + result = TextUtils.measureTextWithWrap( + textRendererTruncate, + textRendererTruncate.width * _pixelsPerUnit, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(24); expect(result.height).to.be.equal(100); - expect(result.lines).to.be.deep.equal(['阳', '光', '明', '媚', ',', 'th', 'e ', 'w', 'e', 'at', 'h', 'er', 'is ', 'gr', 'e', 'at', 'to', 'd', 'a', 'y', '。']); + expect(result.lines).to.be.deep.equal([ + "阳", + "光", + "明", + "媚", + ",", + "th", + "e ", + "w", + "e", + "at", + "h", + "er", + "is ", + "gr", + "e", + "at", + "to", + "d", + "a", + "y", + "。" + ]); expect(result.lineHeight).to.be.equal(27); textRendererTruncate.text = text4; - result = TextUtils.measureTextWithWrap(textRendererTruncate); + result = TextUtils.measureTextWithWrap( + textRendererTruncate, + textRendererTruncate.width * _pixelsPerUnit, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(23); expect(result.height).to.be.equal(100); - expect(result.lines).to.be.deep.equal([' ', ' ', 'W', 'or', 'ld']); + expect(result.lines).to.be.deep.equal([" ", " ", "W", "or", "ld"]); expect(result.lineHeight).to.be.equal(27); // Test that measureTextWithWrap works correctly, while set overflow mode to overflow. @@ -157,28 +250,113 @@ describe("TextUtils", () => { textRendererOverflow.text = text1; textRendererOverflow.bounds; - result = TextUtils.measureTextWithWrap(textRendererOverflow); + result = TextUtils.measureTextWithWrap( + textRendererOverflow, + textRendererTruncate.width * _pixelsPerUnit, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(24); expect(result.height).to.be.equal(567); - expect(result.lines).to.be.deep.equal(["趚", "今", "天", "天", "气", "很", "好", ",", "阳", "光", "明", "媚", "。", "我", "在", "公", "园", "里", "漫", "步", "。"]); + expect(result.lines).to.be.deep.equal([ + "趚", + "今", + "天", + "天", + "气", + "很", + "好", + ",", + "阳", + "光", + "明", + "媚", + "。", + "我", + "在", + "公", + "园", + "里", + "漫", + "步", + "。" + ]); expect(result.lineHeight).to.be.equal(27); textRendererOverflow.text = text2; - result = TextUtils.measureTextWithWrap(textRendererOverflow); + result = TextUtils.measureTextWithWrap( + textRendererOverflow, + textRendererTruncate.width * _pixelsPerUnit, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(20); expect(result.height).to.be.equal(486); - expect(result.lines).to.be.deep.equal(['T', 'h', 'e ', 'w', 'e', 'at', 'h', 'e', 'r ', 'is', 'g', 'r', 'e', 'at', 'to', 'd', 'a', 'y.']); + expect(result.lines).to.be.deep.equal([ + "T", + "h", + "e ", + "w", + "e", + "at", + "h", + "e", + "r ", + "is", + "g", + "r", + "e", + "at", + "to", + "d", + "a", + "y." + ]); expect(result.lineHeight).to.be.equal(27); textRendererOverflow.text = text3; - result = TextUtils.measureTextWithWrap(textRendererOverflow); + result = TextUtils.measureTextWithWrap( + textRendererOverflow, + textRendererTruncate.width * _pixelsPerUnit, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(24); expect(result.height).to.be.equal(621); - expect(result.lines).to.be.deep.equal(['阳', '光', '明', '媚', ',', 'th', 'e ', 'w', 'e', 'at', 'h', 'e', 'r ', 'is', 'g', 'r', 'e', 'at', 'to', 'd', 'a', 'y', '。']); + expect(result.lines).to.be.deep.equal([ + "阳", + "光", + "明", + "媚", + ",", + "th", + "e ", + "w", + "e", + "at", + "h", + "e", + "r ", + "is", + "g", + "r", + "e", + "at", + "to", + "d", + "a", + "y", + "。" + ]); expect(result.lineHeight).to.be.equal(27); textRendererOverflow.text = text4; - result = TextUtils.measureTextWithWrap(textRendererOverflow); + result = TextUtils.measureTextWithWrap( + textRendererOverflow, + textRendererTruncate.width * _pixelsPerUnit, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(23); expect(result.height).to.be.equal(162); - expect(result.lines).to.be.deep.equal([' ', ' ', 'W', 'o', 'rl', 'd']); + expect(result.lines).to.be.deep.equal([" ", " ", "W", "o", "rl", "d"]); expect(result.lineHeight).to.be.equal(27); wrap1TextRenderer.enableWrapping = true; @@ -186,17 +364,29 @@ describe("TextUtils", () => { wrap1TextRenderer.fontSize = 60; wrap1TextRenderer.text = "测试"; wrap1TextRenderer.bounds; - const text1Metrics = TextUtils.measureTextWithWrap(wrap1TextRenderer); + const text1Metrics = TextUtils.measureTextWithWrap( + wrap1TextRenderer, + textRendererTruncate.width * _pixelsPerUnit, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); wrap2TextRenderer.enableWrapping = true; wrap2TextRenderer.width = 5; wrap2TextRenderer.fontSize = 60; wrap2TextRenderer.text = "测试。"; wrap2TextRenderer.bounds; - const text2Metrics = TextUtils.measureTextWithWrap(wrap2TextRenderer); + const text2Metrics = TextUtils.measureTextWithWrap( + wrap2TextRenderer, + textRendererTruncate.width * _pixelsPerUnit, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(text1Metrics.lineMaxSizes[0].size).to.be.equal(text2Metrics.lineMaxSizes[0].size); }); it("measureTextWithoutWrap", () => { + // @ts-ignore + const { _pixelsPerUnit } = Engine; textRendererTruncate.overflowMode = OverflowMode.Truncate; textRendererTruncate.fontSize = 24; textRendererTruncate.width = 0.24; @@ -204,28 +394,44 @@ describe("TextUtils", () => { textRendererTruncate.enableWrapping = true; textRendererTruncate.text = text1; - let result = TextUtils.measureTextWithoutWrap(textRendererTruncate); + let result = TextUtils.measureTextWithoutWrap( + textRendererTruncate, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(518); expect(result.height).to.be.equal(100); expect(result.lines).to.be.deep.equal(["趚今天天气很好,阳光明媚。我 在公园里 漫步。"]); expect(result.lineWidths).to.be.deep.equal([518]); expect(result.lineHeight).to.be.equal(27); textRendererTruncate.text = text2; - result = TextUtils.measureTextWithoutWrap(textRendererTruncate); + result = TextUtils.measureTextWithoutWrap( + textRendererTruncate, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(289); expect(result.height).to.be.equal(100); expect(result.lines).to.be.deep.equal(["The weather is great today."]); expect(result.lineWidths).to.be.deep.equal([289]); expect(result.lineHeight).to.be.equal(27); textRendererTruncate.text = text3; - result = TextUtils.measureTextWithoutWrap(textRendererTruncate); + result = TextUtils.measureTextWithoutWrap( + textRendererTruncate, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(418); expect(result.height).to.be.equal(100); expect(result.lines).to.be.deep.equal(["阳光明媚,the weather is great today。"]); expect(result.lineWidths).to.be.deep.equal([418]); expect(result.lineHeight).to.be.equal(27); textRendererTruncate.text = text4; - result = TextUtils.measureTextWithoutWrap(textRendererTruncate); + result = TextUtils.measureTextWithoutWrap( + textRendererTruncate, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(111); expect(result.height).to.be.equal(100); expect(result.lines).to.be.deep.equal([" ", " World"]); @@ -240,7 +446,11 @@ describe("TextUtils", () => { textRendererOverflow.enableWrapping = true; textRendererOverflow.text = ""; - result = TextUtils.measureTextWithoutWrap(textRendererOverflow); + result = TextUtils.measureTextWithoutWrap( + textRendererOverflow, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(0); expect(result.height).to.be.equal(0); expect(result.lines).to.be.deep.equal([]); @@ -248,7 +458,11 @@ describe("TextUtils", () => { expect(result.lineHeight).to.be.deep.equal(27); textRendererOverflow.text = undefined; - result = TextUtils.measureTextWithoutWrap(textRendererOverflow); + result = TextUtils.measureTextWithoutWrap( + textRendererOverflow, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(0); expect(result.height).to.be.equal(0); expect(result.lines).to.be.deep.equal([]); @@ -256,28 +470,44 @@ describe("TextUtils", () => { expect(result.lineHeight).to.be.deep.equal(27); textRendererOverflow.text = text1; - result = TextUtils.measureTextWithoutWrap(textRendererOverflow); + result = TextUtils.measureTextWithoutWrap( + textRendererOverflow, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(518); expect(result.height).to.be.equal(27); expect(result.lines).to.be.deep.equal(["趚今天天气很好,阳光明媚。我 在公园里 漫步。"]); expect(result.lineWidths).to.be.deep.equal([518]); expect(result.lineHeight).to.be.equal(27); textRendererOverflow.text = text2; - result = TextUtils.measureTextWithoutWrap(textRendererOverflow); + result = TextUtils.measureTextWithoutWrap( + textRendererOverflow, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(289); expect(result.height).to.be.equal(27); expect(result.lines).to.be.deep.equal(["The weather is great today."]); expect(result.lineWidths).to.be.deep.equal([289]); expect(result.lineHeight).to.be.equal(27); textRendererOverflow.text = text3; - result = TextUtils.measureTextWithoutWrap(textRendererOverflow); + result = TextUtils.measureTextWithoutWrap( + textRendererOverflow, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(418); expect(result.height).to.be.equal(27); expect(result.lines).to.be.deep.equal(["阳光明媚,the weather is great today。"]); expect(result.lineWidths).to.be.deep.equal([418]); expect(result.lineHeight).to.be.equal(27); textRendererOverflow.text = text4; - result = TextUtils.measureTextWithoutWrap(textRendererOverflow); + result = TextUtils.measureTextWithoutWrap( + textRendererOverflow, + textRendererTruncate.height * _pixelsPerUnit, + textRendererTruncate.lineSpacing * _pixelsPerUnit + ); expect(result.width).to.be.equal(111); expect(result.height).to.be.equal(54); expect(result.lines).to.be.deep.equal([" ", " World"]); diff --git a/tests/src/core/2d/ui/UICanvas.test.ts b/tests/src/core/2d/ui/UICanvas.test.ts deleted file mode 100644 index 12787a40fb..0000000000 --- a/tests/src/core/2d/ui/UICanvas.test.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Camera, CanvasRenderMode, UICanvas, UIImage, UITransform } from "@galacean/engine"; -import { WebGLEngine } from "@galacean/engine-rhi-webgl"; - -describe("UICanvas", async () => { - const canvas = document.createElement("canvas"); - const engine = await WebGLEngine.create({ canvas: canvas }); - const webCanvas = engine.canvas; - webCanvas.height = 1334; - webCanvas.width = 750; - const scene = engine.sceneManager.scenes[0]; - const root = scene.createRootEntity("root"); - const uiCanvas = root.addComponent(UICanvas); - const cameraEntity = root.createChild("camera"); - const camera = cameraEntity.addComponent(Camera); - - engine.run(); - - // Check default properties - it("WorldSpace", () => { - const imageEntity = root.createChild("image"); - const image = imageEntity.addComponent(UIImage); - const uiTransform = imageEntity.transform; - uiTransform.rect.x = 100; - uiTransform.rect.y = 100; - - uiCanvas.renderMode = CanvasRenderMode.WorldSpace; - cameraEntity.transform.position.set(0, 0, 100); - }); -}); diff --git a/tests/src/core/SkinnedMeshRenderer.test.ts b/tests/src/core/SkinnedMeshRenderer.test.ts index 7021e8190c..4f6c04cec2 100644 --- a/tests/src/core/SkinnedMeshRenderer.test.ts +++ b/tests/src/core/SkinnedMeshRenderer.test.ts @@ -52,16 +52,6 @@ describe("SkinnedMeshRenderer", async () => { expect(skinnedMR.blendShapeWeights).to.be.deep.equal(new Float32Array([0.4])); }); - it("localBounds", () => { - // Test that the localBounds is set correctly. - const entity = rootEntity.createChild("LocalBoundsEntity"); - const skinnedMR = entity.addComponent(SkinnedMeshRenderer); - - skinnedMR.localBounds = new BoundingBox(new Vector3(-1, -1, -1), new Vector3(1, 1, 1)); - expect(skinnedMR.localBounds.min).to.be.deep.include({ x: -1, y: -1, z: -1 }); - expect(skinnedMR.localBounds.max).to.be.deep.include({ x: 1, y: 1, z: 1 }); - }); - it("skin and rootBone", () => { const skin = new Skin("TestSkin"); skin.skeleton = "RootBone"; diff --git a/tests/src/core/Sprite.test.ts b/tests/src/core/Sprite.test.ts index 6ced9a8a49..59c99876d4 100644 --- a/tests/src/core/Sprite.test.ts +++ b/tests/src/core/Sprite.test.ts @@ -83,23 +83,23 @@ describe("Sprite", async () => { expect(sprite.height).to.eq(0); sprite.texture = texture1; // automatic - expect(sprite.width).to.eq(20); - expect(sprite.height).to.eq(10); + expect(sprite.width).to.eq(2000); + expect(sprite.height).to.eq(1000); sprite.texture = texture2; - expect(sprite.width).to.eq(10); - expect(sprite.height).to.eq(20); + expect(sprite.width).to.eq(1000); + expect(sprite.height).to.eq(2000); sprite.atlasRegion = new Rect(0, 0, 0.5, 0.5); - expect(sprite.width).to.eq(5); - expect(sprite.height).to.eq(10); + expect(sprite.width).to.eq(500); + expect(sprite.height).to.eq(1000); sprite.atlasRegion = new Rect(0, 0, 0.5, 0.5); - expect(sprite.width).to.eq(5); - expect(sprite.height).to.eq(10); + expect(sprite.width).to.eq(500); + expect(sprite.height).to.eq(1000); sprite.region = new Rect(0, 0, 0.5, 0.5); - expect(sprite.width).to.eq(2.5); - expect(sprite.height).to.eq(5); + expect(sprite.width).to.eq(250); + expect(sprite.height).to.eq(500); sprite.atlasRegionOffset = new Vector4(0.1, 0.1, 0.1, 0.1); - expect(sprite.width).to.eq(3.125); - expect(sprite.height).to.eq(6.25); + expect(sprite.width).to.eq(312.5); + expect(sprite.height).to.eq(625); // custom sprite.width = 100; sprite.height = 200; @@ -166,19 +166,6 @@ describe("Sprite", async () => { expect(uvs[3]).to.deep.eq(new Vector2(0.25, 0.25)); }); - it("_getBounds", () => { - const sprite = new Sprite(engine, new Texture2D(engine, 100, 200)); - // @ts-ignore - let bounds = sprite._getBounds(); - expect(bounds.min).to.deep.eq(new Vector3(0, 0, 0)); - expect(bounds.max).to.deep.eq(new Vector3(1, 1, 0)); - sprite.region = new Rect(0, 0, 0.5, 0.5); - // @ts-ignore - bounds = sprite._getBounds(); - expect(bounds.min).to.deep.eq(new Vector3(0, 0, 0)); - expect(bounds.max).to.deep.eq(new Vector3(1, 1, 0)); - }); - it("destroy", () => { const spriteRenderer = scene.rootEntities[0].addComponent(SpriteRenderer); const spriteMask = scene.rootEntities[0].addComponent(SpriteMask); diff --git a/tests/src/core/SpriteMask.test.ts b/tests/src/core/SpriteMask.test.ts index 41e3c57e67..27d0ea3487 100644 --- a/tests/src/core/SpriteMask.test.ts +++ b/tests/src/core/SpriteMask.test.ts @@ -195,10 +195,8 @@ describe("SpriteMask", async () => { expect(uvs[1]).to.deep.eq(new Vector2(0, 0)); expect(uvs[2]).to.deep.eq(new Vector2(0, 0)); expect(uvs[3]).to.deep.eq(new Vector2(0, 0)); - // @ts-ignore - const { min, max } = spriteMask._bounds; - expect(min).to.deep.eq(new Vector3(0, 0, 0)); - expect(max).to.deep.eq(new Vector3(0, 0, 0)); + expect(spriteMask.bounds.min).to.deep.eq(new Vector3(0, 0, 0)); + expect(spriteMask.bounds.max).to.deep.eq(new Vector3(0, 0, 0)); const sprite = new Sprite(engine, texture2d); spriteMask.sprite = sprite; @@ -212,7 +210,6 @@ describe("SpriteMask", async () => { uvs.push(new Vector2(vertices[index + 3], vertices[index + 4])); index += 9; } - // @ts-ignore expect(positions[0]).to.deep.eq(new Vector3(-0.5, -1, 0)); expect(positions[1]).to.deep.eq(new Vector3(0.5, -1, 0)); expect(positions[2]).to.deep.eq(new Vector3(-0.5, 1, 0)); @@ -221,8 +218,7 @@ describe("SpriteMask", async () => { expect(uvs[1]).to.deep.eq(new Vector2(1, 1)); expect(uvs[2]).to.deep.eq(new Vector2(0, 0)); expect(uvs[3]).to.deep.eq(new Vector2(1, 0)); - // @ts-ignore - expect(min).to.deep.eq(new Vector3(-0.5, -1, 0)); - expect(max).to.deep.eq(new Vector3(0.5, 1, 0)); + expect(spriteMask.bounds.min).to.deep.eq(new Vector3(-0.5, -1, 0)); + expect(spriteMask.bounds.max).to.deep.eq(new Vector3(0.5, 1, 0)); }); }); diff --git a/tests/src/core/SpriteRenderer.test.ts b/tests/src/core/SpriteRenderer.test.ts index bc18eb2ba1..2877946f57 100644 --- a/tests/src/core/SpriteRenderer.test.ts +++ b/tests/src/core/SpriteRenderer.test.ts @@ -10,7 +10,7 @@ import { } from "@galacean/engine-core"; import { Color, Rect, Vector2, Vector3, Vector4 } from "@galacean/engine-math"; import { WebGLEngine } from "@galacean/engine-rhi-webgl"; -import { describe, beforeEach, expect, it } from "vitest"; +import { beforeEach, describe, expect, it } from "vitest"; describe("SpriteRenderer", async () => { const canvas = document.createElement("canvas"); @@ -193,10 +193,9 @@ describe("SpriteRenderer", async () => { const uvs: Array = []; let index = subChunk.vertexArea.start; sprite.pivot = new Vector2(0.5, 0.5); + const context = { camera: { engine: engine, _renderPipeline: { pushRenderElement: () => {} } } }; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); for (let i = 0; i < 4; ++i) { positions.push(new Vector3(vertices[index], vertices[index + 1], vertices[index + 2])); uvs.push(new Vector2(vertices[index + 3], vertices[index + 4])); @@ -213,9 +212,7 @@ describe("SpriteRenderer", async () => { sprite.pivot = new Vector2(1, 1); // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); positions.length = 0; uvs.length = 0; index = subChunk.vertexArea.start; @@ -235,9 +232,7 @@ describe("SpriteRenderer", async () => { sprite.pivot = new Vector2(0, 0); // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); positions.length = 0; uvs.length = 0; index = subChunk.vertexArea.start; @@ -273,10 +268,9 @@ describe("SpriteRenderer", async () => { sprite.border = new Vector4(0.3, 0.3, 0.3, 0.3); spriteRenderer.width = 0.5; spriteRenderer.height = 0.5; + const context = { camera: { engine: engine, _renderPipeline: { pushRenderElement: () => {} } } }; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); for (let i = 0; i < 16; ++i) { positions.push(new Vector3(vertices[index], vertices[index + 1], vertices[index + 2])); uvs.push(new Vector2(vertices[index + 3], vertices[index + 4])); @@ -318,9 +312,7 @@ describe("SpriteRenderer", async () => { spriteRenderer.width = 15; spriteRenderer.height = 15; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); positions.length = 0; uvs.length = 0; index = subChunk.vertexArea.start; @@ -381,10 +373,9 @@ describe("SpriteRenderer", async () => { sprite.pivot = new Vector2(0, 0); sprite.border = new Vector4(0.5, 0.3, 0.5, 0.3); spriteRenderer.tileMode = SpriteTileMode.Continuous; + const context = { camera: { engine: engine, _renderPipeline: { pushRenderElement: () => {} } } }; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); for (let i = 0; i < 40; ++i) { positions.push(new Vector3(vertices[index], vertices[index + 1], vertices[index + 2])); uvs.push(new Vector2(vertices[index + 3], vertices[index + 4])); @@ -470,12 +461,9 @@ describe("SpriteRenderer", async () => { expect(Vector2.equals(uvs[37], new Vector2(1, 0.3))).to.eq(true); expect(Vector2.equals(uvs[38], new Vector2(0.5, 0))).to.eq(true); expect(Vector2.equals(uvs[39], new Vector2(1, 0))).to.eq(true); - spriteRenderer.tileMode = SpriteTileMode.Adaptive; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); positions.length = 0; uvs.length = 0; index = subChunk.vertexArea.start; @@ -484,93 +472,92 @@ describe("SpriteRenderer", async () => { uvs.push(new Vector2(vertices[index + 3], vertices[index + 4])); index += 9; } + expect(Vector3.equals(positions[0], new Vector3(0, 0, 0))).to.eq(true); expect(Vector3.equals(positions[1], new Vector3(1, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[2], new Vector3(0, 0.8333333333333331, 0))).to.eq(true); - expect(Vector3.equals(positions[3], new Vector3(1, 0.8333333333333331, 0))).to.eq(true); + expect(Vector3.equals(positions[2], new Vector3(0, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[3], new Vector3(1, 0.8999999761581421, 0))).to.eq(true); expect(Vector3.equals(positions[4], new Vector3(4, 0, 0))).to.eq(true); expect(Vector3.equals(positions[5], new Vector3(5, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[6], new Vector3(4, 0.8333333333333331, 0))).to.eq(true); - expect(Vector3.equals(positions[7], new Vector3(5, 0.8333333333333331, 0))).to.eq(true); - expect(Vector3.equals(positions[8], new Vector3(0, 0.8333333333333331, 0))).to.eq(true); - expect(Vector3.equals(positions[9], new Vector3(1, 0.8333333333333331, 0))).to.eq(true); - expect(Vector3.equals(positions[10], new Vector3(0, 2.011111111111111, 0))).to.eq(true); - expect(Vector3.equals(positions[11], new Vector3(1, 2.011111111111111, 0))).to.eq(true); - expect(Vector3.equals(positions[12], new Vector3(4, 0.8333333333333331, 0))).to.eq(true); - expect(Vector3.equals(positions[13], new Vector3(5, 0.8333333333333331, 0))).to.eq(true); - expect(Vector3.equals(positions[14], new Vector3(4, 2.011111111111111, 0))).to.eq(true); - expect(Vector3.equals(positions[15], new Vector3(5, 2.011111111111111, 0))).to.eq(true); - expect(Vector3.equals(positions[16], new Vector3(0, 2.011111111111111, 0))).to.eq(true); - expect(Vector3.equals(positions[17], new Vector3(1, 2.011111111111111, 0))).to.eq(true); - expect(Vector3.equals(positions[18], new Vector3(0, 3.1222222222222222, 0))).to.eq(true); - expect(Vector3.equals(positions[19], new Vector3(1, 3.1222222222222222, 0))).to.eq(true); - expect(Vector3.equals(positions[20], new Vector3(4, 2.011111111111111, 0))).to.eq(true); - expect(Vector3.equals(positions[21], new Vector3(5, 2.011111111111111, 0))).to.eq(true); - expect(Vector3.equals(positions[22], new Vector3(4, 3.1222222222222222, 0))).to.eq(true); - expect(Vector3.equals(positions[23], new Vector3(5, 3.1222222222222222, 0))).to.eq(true); - expect(Vector3.equals(positions[24], new Vector3(0, 3.1222222222222222, 0))).to.eq(true); - expect(Vector3.equals(positions[25], new Vector3(1, 3.1222222222222222, 0))).to.eq(true); - expect(Vector3.equals(positions[26], new Vector3(0, 4.166666666666667, 0))).to.eq(true); - expect(Vector3.equals(positions[27], new Vector3(1, 4.166666666666667, 0))).to.eq(true); - expect(Vector3.equals(positions[28], new Vector3(4, 3.1222222222222222, 0))).to.eq(true); - expect(Vector3.equals(positions[29], new Vector3(5, 3.1222222222222222, 0))).to.eq(true); - expect(Vector3.equals(positions[30], new Vector3(4, 4.166666666666667, 0))).to.eq(true); - expect(Vector3.equals(positions[31], new Vector3(5, 4.166666666666667, 0))).to.eq(true); - expect(Vector3.equals(positions[32], new Vector3(0, 4.166666666666667, 0))).to.eq(true); - expect(Vector3.equals(positions[33], new Vector3(1, 4.166666666666667, 0))).to.eq(true); + expect(Vector3.equals(positions[6], new Vector3(4, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[7], new Vector3(5, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[8], new Vector3(0, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[9], new Vector3(1, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[10], new Vector3(0, 1.9666666984558105, 0))).to.eq(true); + expect(Vector3.equals(positions[11], new Vector3(1, 1.9666666984558105, 0))).to.eq(true); + expect(Vector3.equals(positions[12], new Vector3(4, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[13], new Vector3(5, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[14], new Vector3(4, 1.9666666984558105, 0))).to.eq(true); + expect(Vector3.equals(positions[15], new Vector3(5, 1.9666666984558105, 0))).to.eq(true); + expect(Vector3.equals(positions[16], new Vector3(0, 1.9666666984558105, 0))).to.eq(true); + expect(Vector3.equals(positions[17], new Vector3(1, 1.9666666984558105, 0))).to.eq(true); + expect(Vector3.equals(positions[18], new Vector3(0, 3.0333333015441895, 0))).to.eq(true); + expect(Vector3.equals(positions[19], new Vector3(1, 3.0333333015441895, 0))).to.eq(true); + expect(Vector3.equals(positions[20], new Vector3(4, 1.9666666984558105, 0))).to.eq(true); + expect(Vector3.equals(positions[21], new Vector3(5, 1.9666666984558105, 0))).to.eq(true); + expect(Vector3.equals(positions[22], new Vector3(4, 3.0333333015441895, 0))).to.eq(true); + expect(Vector3.equals(positions[23], new Vector3(5, 3.0333333015441895, 0))).to.eq(true); + expect(Vector3.equals(positions[24], new Vector3(0, 3.0333333015441895, 0))).to.eq(true); + expect(Vector3.equals(positions[25], new Vector3(1, 3.0333333015441895, 0))).to.eq(true); + expect(Vector3.equals(positions[26], new Vector3(0, 4.099999904632568, 0))).to.eq(true); + expect(Vector3.equals(positions[27], new Vector3(1, 4.099999904632568, 0))).to.eq(true); + expect(Vector3.equals(positions[28], new Vector3(4, 3.0333333015441895, 0))).to.eq(true); + expect(Vector3.equals(positions[29], new Vector3(5, 3.0333333015441895, 0))).to.eq(true); + expect(Vector3.equals(positions[30], new Vector3(4, 4.099999904632568, 0))).to.eq(true); + expect(Vector3.equals(positions[31], new Vector3(5, 4.099999904632568, 0))).to.eq(true); + expect(Vector3.equals(positions[32], new Vector3(0, 4.099999904632568, 0))).to.eq(true); + expect(Vector3.equals(positions[33], new Vector3(1, 4.099999904632568, 0))).to.eq(true); expect(Vector3.equals(positions[34], new Vector3(0, 5, 0))).to.eq(true); expect(Vector3.equals(positions[35], new Vector3(1, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[36], new Vector3(4, 4.166666666666667, 0))).to.eq(true); - expect(Vector3.equals(positions[37], new Vector3(5, 4.166666666666667, 0))).to.eq(true); + expect(Vector3.equals(positions[36], new Vector3(4, 4.099999904632568, 0))).to.eq(true); + expect(Vector3.equals(positions[37], new Vector3(5, 4.099999904632568, 0))).to.eq(true); expect(Vector3.equals(positions[38], new Vector3(4, 5, 0))).to.eq(true); expect(Vector3.equals(positions[39], new Vector3(5, 5, 0))).to.eq(true); expect(Vector2.equals(uvs[0], new Vector2(0, 1))).to.eq(true); expect(Vector2.equals(uvs[1], new Vector2(0.5, 1))).to.eq(true); - expect(Vector2.equals(uvs[2], new Vector2(0, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[3], new Vector2(0.5, 0.7))).to.eq(true); + expect(Vector2.equals(uvs[2], new Vector2(0, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[3], new Vector2(0.5, 0.699999988079071))).to.eq(true); expect(Vector2.equals(uvs[4], new Vector2(0.5, 1))).to.eq(true); expect(Vector2.equals(uvs[5], new Vector2(1, 1))).to.eq(true); - expect(Vector2.equals(uvs[6], new Vector2(0.5, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[7], new Vector2(1, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[8], new Vector2(0, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[9], new Vector2(0.5, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[10], new Vector2(0, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[11], new Vector2(0.5, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[12], new Vector2(0.5, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[13], new Vector2(1, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[14], new Vector2(0.5, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[15], new Vector2(1, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[16], new Vector2(0, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[17], new Vector2(0.5, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[18], new Vector2(0, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[19], new Vector2(0.5, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[20], new Vector2(0.5, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[21], new Vector2(1, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[22], new Vector2(0.5, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[23], new Vector2(1, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[24], new Vector2(0, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[25], new Vector2(0.5, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[26], new Vector2(0, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[27], new Vector2(0.5, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[28], new Vector2(0.5, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[29], new Vector2(1, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[30], new Vector2(0.5, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[31], new Vector2(1, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[32], new Vector2(0, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[33], new Vector2(0.5, 0.3))).to.eq(true); + expect(Vector2.equals(uvs[6], new Vector2(0.5, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[7], new Vector2(1, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[8], new Vector2(0, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[9], new Vector2(0.5, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[10], new Vector2(0, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[11], new Vector2(0.5, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[12], new Vector2(0.5, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[13], new Vector2(1, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[14], new Vector2(0.5, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[15], new Vector2(1, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[16], new Vector2(0, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[17], new Vector2(0.5, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[18], new Vector2(0, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[19], new Vector2(0.5, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[20], new Vector2(0.5, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[21], new Vector2(1, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[22], new Vector2(0.5, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[23], new Vector2(1, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[24], new Vector2(0, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[25], new Vector2(0.5, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[26], new Vector2(0, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[27], new Vector2(0.5, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[28], new Vector2(0.5, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[29], new Vector2(1, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[30], new Vector2(0.5, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[31], new Vector2(1, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[32], new Vector2(0, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[33], new Vector2(0.5, 0.30000001192092896))).to.eq(true); expect(Vector2.equals(uvs[34], new Vector2(0, 0))).to.eq(true); expect(Vector2.equals(uvs[35], new Vector2(0.5, 0))).to.eq(true); - expect(Vector2.equals(uvs[36], new Vector2(0.5, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[37], new Vector2(1, 0.3))).to.eq(true); + expect(Vector2.equals(uvs[36], new Vector2(0.5, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[37], new Vector2(1, 0.30000001192092896))).to.eq(true); expect(Vector2.equals(uvs[38], new Vector2(0.5, 0))).to.eq(true); expect(Vector2.equals(uvs[39], new Vector2(1, 0))).to.eq(true); sprite.border = new Vector4(0.3, 0.5, 0.3, 0.5); spriteRenderer.tileMode = SpriteTileMode.Continuous; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); positions.length = 0; uvs.length = 0; index = subChunk.vertexArea.start; @@ -580,123 +567,121 @@ describe("SpriteRenderer", async () => { index += 9; } expect(Vector3.equals(positions[0], new Vector3(0, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[1], new Vector3(0.6, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[1], new Vector3(0.6000000238418579, 0, 0))).to.eq(true); expect(Vector3.equals(positions[2], new Vector3(0, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[3], new Vector3(0.6, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[4], new Vector3(0.6, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[5], new Vector3(1.4, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[6], new Vector3(0.6, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[7], new Vector3(1.4, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[8], new Vector3(1.4, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[9], new Vector3(2.2, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[10], new Vector3(1.4, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[11], new Vector3(2.2, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[12], new Vector3(2.2, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[13], new Vector3(3.0000000000000004, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[14], new Vector3(2.2, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[15], new Vector3(3.0000000000000004, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[16], new Vector3(3.0000000000000004, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[17], new Vector3(3.8000000000000003, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[18], new Vector3(3.0000000000000004, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[19], new Vector3(3.8000000000000003, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[20], new Vector3(3.8000000000000003, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[21], new Vector3(4.4, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[22], new Vector3(3.8000000000000003, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[23], new Vector3(4.4, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[24], new Vector3(4.4, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[3], new Vector3(0.6000000238418579, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[4], new Vector3(0.6000000238418579, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[5], new Vector3(1.399999976158142, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[6], new Vector3(0.6000000238418579, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[7], new Vector3(1.399999976158142, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[8], new Vector3(1.399999976158142, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[9], new Vector3(2.200000047683716, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[10], new Vector3(1.399999976158142, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[11], new Vector3(2.200000047683716, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[12], new Vector3(2.200000047683716, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[13], new Vector3(3, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[14], new Vector3(2.200000047683716, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[15], new Vector3(3, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[16], new Vector3(3, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[17], new Vector3(3.799999952316284, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[18], new Vector3(3, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[19], new Vector3(3.799999952316284, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[20], new Vector3(3.799999952316284, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[21], new Vector3(4.400000095367432, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[22], new Vector3(3.799999952316284, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[23], new Vector3(4.400000095367432, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[24], new Vector3(4.400000095367432, 0, 0))).to.eq(true); expect(Vector3.equals(positions[25], new Vector3(5, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[26], new Vector3(4.4, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[26], new Vector3(4.400000095367432, 1.5, 0))).to.eq(true); expect(Vector3.equals(positions[27], new Vector3(5, 1.5, 0))).to.eq(true); expect(Vector3.equals(positions[28], new Vector3(0, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[29], new Vector3(0.6, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[29], new Vector3(0.6000000238418579, 3.5, 0))).to.eq(true); expect(Vector3.equals(positions[30], new Vector3(0, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[31], new Vector3(0.6, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[32], new Vector3(0.6, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[33], new Vector3(1.4, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[34], new Vector3(0.6, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[35], new Vector3(1.4, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[36], new Vector3(1.4, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[37], new Vector3(2.2, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[38], new Vector3(1.4, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[39], new Vector3(2.2, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[40], new Vector3(2.2, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[41], new Vector3(3.0000000000000004, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[42], new Vector3(2.2, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[43], new Vector3(3.0000000000000004, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[44], new Vector3(3.0000000000000004, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[45], new Vector3(3.8000000000000003, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[46], new Vector3(3.0000000000000004, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[47], new Vector3(3.8000000000000003, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[48], new Vector3(3.8000000000000003, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[49], new Vector3(4.4, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[50], new Vector3(3.8000000000000003, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[51], new Vector3(4.4, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[52], new Vector3(4.4, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[31], new Vector3(0.6000000238418579, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[32], new Vector3(0.6000000238418579, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[33], new Vector3(1.399999976158142, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[34], new Vector3(0.6000000238418579, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[35], new Vector3(1.399999976158142, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[36], new Vector3(1.399999976158142, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[37], new Vector3(2.200000047683716, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[38], new Vector3(1.399999976158142, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[39], new Vector3(2.200000047683716, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[40], new Vector3(2.200000047683716, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[41], new Vector3(3, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[42], new Vector3(2.200000047683716, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[43], new Vector3(3, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[44], new Vector3(3, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[45], new Vector3(3.799999952316284, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[46], new Vector3(3, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[47], new Vector3(3.799999952316284, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[48], new Vector3(3.799999952316284, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[49], new Vector3(4.400000095367432, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[50], new Vector3(3.799999952316284, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[51], new Vector3(4.400000095367432, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[52], new Vector3(4.400000095367432, 3.5, 0))).to.eq(true); expect(Vector3.equals(positions[53], new Vector3(5, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[54], new Vector3(4.4, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[54], new Vector3(4.400000095367432, 5, 0))).to.eq(true); expect(Vector3.equals(positions[55], new Vector3(5, 5, 0))).to.eq(true); expect(Vector2.equals(uvs[0], new Vector2(0, 1))).to.eq(true); - expect(Vector2.equals(uvs[1], new Vector2(0.3, 1))).to.eq(true); + expect(Vector2.equals(uvs[1], new Vector2(0.30000001192092896, 1))).to.eq(true); expect(Vector2.equals(uvs[2], new Vector2(0, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[3], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[4], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[5], new Vector2(0.7, 1))).to.eq(true); - expect(Vector2.equals(uvs[6], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[7], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[8], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[9], new Vector2(0.7, 1))).to.eq(true); - expect(Vector2.equals(uvs[10], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[11], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[12], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[13], new Vector2(0.7, 1))).to.eq(true); - expect(Vector2.equals(uvs[14], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[15], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[16], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[17], new Vector2(0.7, 1))).to.eq(true); - expect(Vector2.equals(uvs[18], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[19], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[20], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[21], new Vector2(0.5999999999999996, 1))).to.eq(true); - expect(Vector2.equals(uvs[22], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[23], new Vector2(0.5999999999999996, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[24], new Vector2(0.7, 1))).to.eq(true); + expect(Vector2.equals(uvs[3], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[4], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[5], new Vector2(0.699999988079071, 1))).to.eq(true); + expect(Vector2.equals(uvs[6], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[7], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[8], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[9], new Vector2(0.699999988079071, 1))).to.eq(true); + expect(Vector2.equals(uvs[10], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[11], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[12], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[13], new Vector2(0.699999988079071, 1))).to.eq(true); + expect(Vector2.equals(uvs[14], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[15], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[16], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[17], new Vector2(0.699999988079071, 1))).to.eq(true); + expect(Vector2.equals(uvs[18], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[19], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[20], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[21], new Vector2(0.6000000238418579, 1))).to.eq(true); + expect(Vector2.equals(uvs[22], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[23], new Vector2(0.6000000238418579, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[24], new Vector2(0.699999988079071, 1))).to.eq(true); expect(Vector2.equals(uvs[25], new Vector2(1, 1))).to.eq(true); - expect(Vector2.equals(uvs[26], new Vector2(0.7, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[26], new Vector2(0.699999988079071, 0.5))).to.eq(true); expect(Vector2.equals(uvs[27], new Vector2(1, 0.5))).to.eq(true); expect(Vector2.equals(uvs[28], new Vector2(0, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[29], new Vector2(0.3, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[29], new Vector2(0.30000001192092896, 0.5))).to.eq(true); expect(Vector2.equals(uvs[30], new Vector2(0, 0))).to.eq(true); - expect(Vector2.equals(uvs[31], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[32], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[33], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[34], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[35], new Vector2(0.7, 0))).to.eq(true); - expect(Vector2.equals(uvs[36], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[37], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[38], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[39], new Vector2(0.7, 0))).to.eq(true); - expect(Vector2.equals(uvs[40], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[41], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[42], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[43], new Vector2(0.7, 0))).to.eq(true); - expect(Vector2.equals(uvs[44], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[45], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[46], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[47], new Vector2(0.7, 0))).to.eq(true); - expect(Vector2.equals(uvs[48], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[49], new Vector2(0.5999999999999996, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[50], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[51], new Vector2(0.5999999999999996, 0))).to.eq(true); - expect(Vector2.equals(uvs[52], new Vector2(0.7, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[31], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[32], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[33], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[34], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[35], new Vector2(0.699999988079071, 0))).to.eq(true); + expect(Vector2.equals(uvs[36], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[37], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[38], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[39], new Vector2(0.699999988079071, 0))).to.eq(true); + expect(Vector2.equals(uvs[40], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[41], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[42], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[43], new Vector2(0.699999988079071, 0))).to.eq(true); + expect(Vector2.equals(uvs[44], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[45], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[46], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[47], new Vector2(0.699999988079071, 0))).to.eq(true); + expect(Vector2.equals(uvs[48], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[49], new Vector2(0.6000000238418579, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[50], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[51], new Vector2(0.6000000238418579, 0))).to.eq(true); + expect(Vector2.equals(uvs[52], new Vector2(0.699999988079071, 0.5))).to.eq(true); expect(Vector2.equals(uvs[53], new Vector2(1, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[54], new Vector2(0.7, 0))).to.eq(true); + expect(Vector2.equals(uvs[54], new Vector2(0.699999988079071, 0))).to.eq(true); expect(Vector2.equals(uvs[55], new Vector2(1, 0))).to.eq(true); spriteRenderer.tileMode = SpriteTileMode.Adaptive; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); positions.length = 0; uvs.length = 0; index = subChunk.vertexArea.start; @@ -705,117 +690,118 @@ describe("SpriteRenderer", async () => { uvs.push(new Vector2(vertices[index + 3], vertices[index + 4])); index += 9; } + expect(Vector3.equals(positions[0], new Vector3(0, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[1], new Vector3(0.5769230769230769, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[1], new Vector3(0.6000000238418579, 0, 0))).to.eq(true); expect(Vector3.equals(positions[2], new Vector3(0, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[3], new Vector3(0.5769230769230769, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[4], new Vector3(0.5769230769230769, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[5], new Vector3(1.3692307692307693, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[6], new Vector3(0.5769230769230769, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[7], new Vector3(1.3692307692307693, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[8], new Vector3(1.3692307692307693, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[9], new Vector3(2.1384615384615384, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[10], new Vector3(1.3692307692307693, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[11], new Vector3(2.1384615384615384, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[12], new Vector3(2.1384615384615384, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[13], new Vector3(2.907692307692308, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[14], new Vector3(2.1384615384615384, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[15], new Vector3(2.907692307692308, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[16], new Vector3(2.907692307692308, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[17], new Vector3(3.6769230769230767, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[18], new Vector3(2.907692307692308, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[19], new Vector3(3.6769230769230767, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[20], new Vector3(3.6769230769230767, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[21], new Vector3(4.423076923076923, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[22], new Vector3(3.6769230769230767, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[23], new Vector3(4.423076923076923, 1.5, 0))).to.eq(true); - expect(Vector3.equals(positions[24], new Vector3(4.423076923076923, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[3], new Vector3(0.6000000238418579, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[4], new Vector3(0.6000000238418579, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[5], new Vector3(1.3600000143051147, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[6], new Vector3(0.6000000238418579, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[7], new Vector3(1.3600000143051147, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[8], new Vector3(1.3600000143051147, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[9], new Vector3(2.119999885559082, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[10], new Vector3(1.3600000143051147, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[11], new Vector3(2.119999885559082, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[12], new Vector3(2.119999885559082, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[13], new Vector3(2.880000114440918, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[14], new Vector3(2.119999885559082, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[15], new Vector3(2.880000114440918, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[16], new Vector3(2.880000114440918, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[17], new Vector3(3.640000104904175, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[18], new Vector3(2.880000114440918, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[19], new Vector3(3.640000104904175, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[20], new Vector3(3.640000104904175, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[21], new Vector3(4.400000095367432, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[22], new Vector3(3.640000104904175, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[23], new Vector3(4.400000095367432, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[24], new Vector3(4.400000095367432, 0, 0))).to.eq(true); expect(Vector3.equals(positions[25], new Vector3(5, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[26], new Vector3(4.423076923076923, 1.5, 0))).to.eq(true); + expect(Vector3.equals(positions[26], new Vector3(4.400000095367432, 1.5, 0))).to.eq(true); expect(Vector3.equals(positions[27], new Vector3(5, 1.5, 0))).to.eq(true); expect(Vector3.equals(positions[28], new Vector3(0, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[29], new Vector3(0.5769230769230769, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[29], new Vector3(0.6000000238418579, 3.5, 0))).to.eq(true); expect(Vector3.equals(positions[30], new Vector3(0, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[31], new Vector3(0.5769230769230769, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[32], new Vector3(0.5769230769230769, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[33], new Vector3(1.3692307692307693, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[34], new Vector3(0.5769230769230769, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[35], new Vector3(1.3692307692307693, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[36], new Vector3(1.3692307692307693, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[37], new Vector3(2.1384615384615384, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[38], new Vector3(1.3692307692307693, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[39], new Vector3(2.1384615384615384, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[40], new Vector3(2.1384615384615384, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[41], new Vector3(2.907692307692308, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[42], new Vector3(2.1384615384615384, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[43], new Vector3(2.907692307692308, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[44], new Vector3(2.907692307692308, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[45], new Vector3(3.6769230769230767, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[46], new Vector3(2.907692307692308, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[47], new Vector3(3.6769230769230767, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[48], new Vector3(3.6769230769230767, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[49], new Vector3(4.423076923076923, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[50], new Vector3(3.6769230769230767, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[51], new Vector3(4.423076923076923, 5, 0))).to.eq(true); - expect(Vector3.equals(positions[52], new Vector3(4.423076923076923, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[31], new Vector3(0.6000000238418579, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[32], new Vector3(0.6000000238418579, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[33], new Vector3(1.3600000143051147, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[34], new Vector3(0.6000000238418579, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[35], new Vector3(1.3600000143051147, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[36], new Vector3(1.3600000143051147, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[37], new Vector3(2.119999885559082, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[38], new Vector3(1.3600000143051147, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[39], new Vector3(2.119999885559082, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[40], new Vector3(2.119999885559082, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[41], new Vector3(2.880000114440918, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[42], new Vector3(2.119999885559082, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[43], new Vector3(2.880000114440918, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[44], new Vector3(2.880000114440918, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[45], new Vector3(3.640000104904175, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[46], new Vector3(2.880000114440918, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[47], new Vector3(3.640000104904175, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[48], new Vector3(3.640000104904175, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[49], new Vector3(4.400000095367432, 3.5, 0))).to.eq(true); + expect(Vector3.equals(positions[50], new Vector3(3.640000104904175, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[51], new Vector3(4.400000095367432, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[52], new Vector3(4.400000095367432, 3.5, 0))).to.eq(true); expect(Vector3.equals(positions[53], new Vector3(5, 3.5, 0))).to.eq(true); - expect(Vector3.equals(positions[54], new Vector3(4.423076923076923, 5, 0))).to.eq(true); + expect(Vector3.equals(positions[54], new Vector3(4.400000095367432, 5, 0))).to.eq(true); expect(Vector3.equals(positions[55], new Vector3(5, 5, 0))).to.eq(true); expect(Vector2.equals(uvs[0], new Vector2(0, 1))).to.eq(true); - expect(Vector2.equals(uvs[1], new Vector2(0.3, 1))).to.eq(true); + expect(Vector2.equals(uvs[1], new Vector2(0.30000001192092896, 1))).to.eq(true); expect(Vector2.equals(uvs[2], new Vector2(0, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[3], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[4], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[5], new Vector2(0.7, 1))).to.eq(true); - expect(Vector2.equals(uvs[6], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[7], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[8], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[9], new Vector2(0.7, 1))).to.eq(true); - expect(Vector2.equals(uvs[10], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[11], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[12], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[13], new Vector2(0.7, 1))).to.eq(true); - expect(Vector2.equals(uvs[14], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[15], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[16], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[17], new Vector2(0.7, 1))).to.eq(true); - expect(Vector2.equals(uvs[18], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[19], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[20], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[21], new Vector2(0.7, 1))).to.eq(true); - expect(Vector2.equals(uvs[22], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[23], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[24], new Vector2(0.7, 1))).to.eq(true); + expect(Vector2.equals(uvs[3], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[4], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[5], new Vector2(0.699999988079071, 1))).to.eq(true); + expect(Vector2.equals(uvs[6], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[7], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[8], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[9], new Vector2(0.699999988079071, 1))).to.eq(true); + expect(Vector2.equals(uvs[10], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[11], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[12], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[13], new Vector2(0.699999988079071, 1))).to.eq(true); + expect(Vector2.equals(uvs[14], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[15], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[16], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[17], new Vector2(0.699999988079071, 1))).to.eq(true); + expect(Vector2.equals(uvs[18], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[19], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[20], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[21], new Vector2(0.699999988079071, 1))).to.eq(true); + expect(Vector2.equals(uvs[22], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[23], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[24], new Vector2(0.699999988079071, 1))).to.eq(true); expect(Vector2.equals(uvs[25], new Vector2(1, 1))).to.eq(true); - expect(Vector2.equals(uvs[26], new Vector2(0.7, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[26], new Vector2(0.699999988079071, 0.5))).to.eq(true); expect(Vector2.equals(uvs[27], new Vector2(1, 0.5))).to.eq(true); expect(Vector2.equals(uvs[28], new Vector2(0, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[29], new Vector2(0.3, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[29], new Vector2(0.30000001192092896, 0.5))).to.eq(true); expect(Vector2.equals(uvs[30], new Vector2(0, 0))).to.eq(true); - expect(Vector2.equals(uvs[31], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[32], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[33], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[34], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[35], new Vector2(0.7, 0))).to.eq(true); - expect(Vector2.equals(uvs[36], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[37], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[38], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[39], new Vector2(0.7, 0))).to.eq(true); - expect(Vector2.equals(uvs[40], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[41], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[42], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[43], new Vector2(0.7, 0))).to.eq(true); - expect(Vector2.equals(uvs[44], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[45], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[46], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[47], new Vector2(0.7, 0))).to.eq(true); - expect(Vector2.equals(uvs[48], new Vector2(0.3, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[49], new Vector2(0.7, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[50], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[51], new Vector2(0.7, 0))).to.eq(true); - expect(Vector2.equals(uvs[52], new Vector2(0.7, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[31], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[32], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[33], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[34], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[35], new Vector2(0.699999988079071, 0))).to.eq(true); + expect(Vector2.equals(uvs[36], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[37], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[38], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[39], new Vector2(0.699999988079071, 0))).to.eq(true); + expect(Vector2.equals(uvs[40], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[41], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[42], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[43], new Vector2(0.699999988079071, 0))).to.eq(true); + expect(Vector2.equals(uvs[44], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[45], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[46], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[47], new Vector2(0.699999988079071, 0))).to.eq(true); + expect(Vector2.equals(uvs[48], new Vector2(0.30000001192092896, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[49], new Vector2(0.699999988079071, 0.5))).to.eq(true); + expect(Vector2.equals(uvs[50], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[51], new Vector2(0.699999988079071, 0))).to.eq(true); + expect(Vector2.equals(uvs[52], new Vector2(0.699999988079071, 0.5))).to.eq(true); expect(Vector2.equals(uvs[53], new Vector2(1, 0.5))).to.eq(true); - expect(Vector2.equals(uvs[54], new Vector2(0.7, 0))).to.eq(true); + expect(Vector2.equals(uvs[54], new Vector2(0.699999988079071, 0))).to.eq(true); expect(Vector2.equals(uvs[55], new Vector2(1, 0))).to.eq(true); sprite.border = new Vector4(0.3, 0.3, 0.3, 0.3); @@ -823,9 +809,7 @@ describe("SpriteRenderer", async () => { spriteRenderer.height = 0.5; spriteRenderer.tileMode = SpriteTileMode.Continuous; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); positions.length = 0; uvs.length = 0; index = subChunk.vertexArea.start; @@ -834,6 +818,7 @@ describe("SpriteRenderer", async () => { uvs.push(new Vector2(vertices[index + 3], vertices[index + 4])); index += 9; } + expect(Vector3.equals(positions[0], new Vector3(0, 0, 0))).to.eq(true); expect(Vector3.equals(positions[1], new Vector3(0.25, 0, 0))).to.eq(true); expect(Vector3.equals(positions[2], new Vector3(0, 0.25, 0))).to.eq(true); @@ -851,27 +836,25 @@ describe("SpriteRenderer", async () => { expect(Vector3.equals(positions[14], new Vector3(0.25, 0.5, 0))).to.eq(true); expect(Vector3.equals(positions[15], new Vector3(0.5, 0.5, 0))).to.eq(true); expect(Vector2.equals(uvs[0], new Vector2(0, 1))).to.eq(true); - expect(Vector2.equals(uvs[1], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[2], new Vector2(0, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[3], new Vector2(0.3, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[4], new Vector2(0.7, 1))).to.eq(true); + expect(Vector2.equals(uvs[1], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[2], new Vector2(0, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[3], new Vector2(0.30000001192092896, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[4], new Vector2(0.699999988079071, 1))).to.eq(true); expect(Vector2.equals(uvs[5], new Vector2(1, 1))).to.eq(true); - expect(Vector2.equals(uvs[6], new Vector2(0.7, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[7], new Vector2(1, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[8], new Vector2(0, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[9], new Vector2(0.3, 0.3))).to.eq(true); + expect(Vector2.equals(uvs[6], new Vector2(0.699999988079071, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[7], new Vector2(1, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[8], new Vector2(0, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[9], new Vector2(0.30000001192092896, 0.30000001192092896))).to.eq(true); expect(Vector2.equals(uvs[10], new Vector2(0, 0))).to.eq(true); - expect(Vector2.equals(uvs[11], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[12], new Vector2(0.7, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[13], new Vector2(1, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[14], new Vector2(0.7, 0))).to.eq(true); + expect(Vector2.equals(uvs[11], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[12], new Vector2(0.699999988079071, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[13], new Vector2(1, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[14], new Vector2(0.699999988079071, 0))).to.eq(true); expect(Vector2.equals(uvs[15], new Vector2(1, 0))).to.eq(true); spriteRenderer.tileMode = SpriteTileMode.Adaptive; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); positions.length = 0; uvs.length = 0; index = subChunk.vertexArea.start; @@ -880,6 +863,7 @@ describe("SpriteRenderer", async () => { uvs.push(new Vector2(vertices[index + 3], vertices[index + 4])); index += 9; } + expect(Vector3.equals(positions[0], new Vector3(0, 0, 0))).to.eq(true); expect(Vector3.equals(positions[1], new Vector3(0.25, 0, 0))).to.eq(true); expect(Vector3.equals(positions[2], new Vector3(0, 0.25, 0))).to.eq(true); @@ -897,29 +881,29 @@ describe("SpriteRenderer", async () => { expect(Vector3.equals(positions[14], new Vector3(0.25, 0.5, 0))).to.eq(true); expect(Vector3.equals(positions[15], new Vector3(0.5, 0.5, 0))).to.eq(true); expect(Vector2.equals(uvs[0], new Vector2(0, 1))).to.eq(true); - expect(Vector2.equals(uvs[1], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[2], new Vector2(0, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[3], new Vector2(0.3, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[4], new Vector2(0.7, 1))).to.eq(true); + expect(Vector2.equals(uvs[1], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[2], new Vector2(0, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[3], new Vector2(0.30000001192092896, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[4], new Vector2(0.699999988079071, 1))).to.eq(true); expect(Vector2.equals(uvs[5], new Vector2(1, 1))).to.eq(true); - expect(Vector2.equals(uvs[6], new Vector2(0.7, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[7], new Vector2(1, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[8], new Vector2(0, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[9], new Vector2(0.3, 0.3))).to.eq(true); + expect(Vector2.equals(uvs[6], new Vector2(0.699999988079071, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[7], new Vector2(1, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[8], new Vector2(0, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[9], new Vector2(0.30000001192092896, 0.30000001192092896))).to.eq(true); expect(Vector2.equals(uvs[10], new Vector2(0, 0))).to.eq(true); - expect(Vector2.equals(uvs[11], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[12], new Vector2(0.7, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[13], new Vector2(1, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[14], new Vector2(0.7, 0))).to.eq(true); + expect(Vector2.equals(uvs[11], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[12], new Vector2(0.699999988079071, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[13], new Vector2(1, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[14], new Vector2(0.699999988079071, 0))).to.eq(true); expect(Vector2.equals(uvs[15], new Vector2(1, 0))).to.eq(true); spriteRenderer.width = 0.01; spriteRenderer.height = 0.01; spriteRenderer.tileMode = SpriteTileMode.Adaptive; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); + spriteRenderer._render(context); // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + positions.length = 0; uvs.length = 0; index = subChunk.vertexArea.start; @@ -963,9 +947,7 @@ describe("SpriteRenderer", async () => { spriteRenderer.tileMode = SpriteTileMode.Continuous; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); positions.length = 0; uvs.length = 0; index = subChunk.vertexArea.start; @@ -1011,9 +993,7 @@ describe("SpriteRenderer", async () => { spriteRenderer.height = 100000; spriteRenderer.tileMode = SpriteTileMode.Continuous; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); positions.length = 0; uvs.length = 0; index = subChunk.vertexArea.start; @@ -1033,9 +1013,7 @@ describe("SpriteRenderer", async () => { spriteRenderer.tileMode = SpriteTileMode.Adaptive; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); positions.length = 0; uvs.length = 0; index = subChunk.vertexArea.start; @@ -1057,9 +1035,7 @@ describe("SpriteRenderer", async () => { spriteRenderer.height = 4; spriteRenderer.tileMode = SpriteTileMode.Continuous; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); positions.length = 0; uvs.length = 0; index = subChunk.vertexArea.start; @@ -1231,9 +1207,7 @@ describe("SpriteRenderer", async () => { spriteRenderer.tileMode = SpriteTileMode.Adaptive; // @ts-ignore - spriteRenderer._assembler.updatePositions(spriteRenderer); - // @ts-ignore - spriteRenderer._assembler.updateUVs(spriteRenderer); + spriteRenderer._render(context); positions.length = 0; uvs.length = 0; index = subChunk.vertexArea.start; @@ -1242,165 +1216,166 @@ describe("SpriteRenderer", async () => { uvs.push(new Vector2(vertices[index + 3], vertices[index + 4])); index += 9; } + expect(Vector3.equals(positions[0], new Vector3(0, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[1], new Vector3(0.6428571428571428, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[2], new Vector3(0, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[3], new Vector3(0.6428571428571428, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[4], new Vector3(0.6428571428571428, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[5], new Vector3(1.4571428571428573, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[6], new Vector3(0.6428571428571428, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[7], new Vector3(1.4571428571428573, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[8], new Vector3(1.4571428571428573, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[9], new Vector3(2.357142857142857, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[10], new Vector3(1.4571428571428573, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[11], new Vector3(2.357142857142857, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[12], new Vector3(2.357142857142857, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[1], new Vector3(0.6000000238418579, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[2], new Vector3(0, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[3], new Vector3(0.6000000238418579, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[4], new Vector3(0.6000000238418579, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[5], new Vector3(1.5, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[6], new Vector3(0.6000000238418579, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[7], new Vector3(1.5, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[8], new Vector3(1.5, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[9], new Vector3(2.4000000953674316, 0, 0))).to.eq(true); + expect(Vector3.equals(positions[10], new Vector3(1.5, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[11], new Vector3(2.4000000953674316, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[12], new Vector3(2.4000000953674316, 0, 0))).to.eq(true); expect(Vector3.equals(positions[13], new Vector3(3, 0, 0))).to.eq(true); - expect(Vector3.equals(positions[14], new Vector3(2.357142857142857, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[15], new Vector3(3, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[16], new Vector3(0, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[17], new Vector3(0.6428571428571428, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[18], new Vector3(0, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[19], new Vector3(0.6428571428571428, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[20], new Vector3(0.6428571428571428, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[21], new Vector3(1.4571428571428573, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[22], new Vector3(0.6428571428571428, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[23], new Vector3(1.4571428571428573, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[24], new Vector3(1.4571428571428573, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[25], new Vector3(2.357142857142857, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[26], new Vector3(1.4571428571428573, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[27], new Vector3(2.357142857142857, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[28], new Vector3(2.357142857142857, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[29], new Vector3(3, 0.857142857142857, 0))).to.eq(true); - expect(Vector3.equals(positions[30], new Vector3(2.357142857142857, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[31], new Vector3(3, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[32], new Vector3(0, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[33], new Vector3(0.6428571428571428, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[34], new Vector3(0, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[35], new Vector3(0.6428571428571428, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[36], new Vector3(0.6428571428571428, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[37], new Vector3(1.4571428571428573, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[38], new Vector3(0.6428571428571428, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[39], new Vector3(1.4571428571428573, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[40], new Vector3(1.4571428571428573, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[41], new Vector3(2.357142857142857, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[42], new Vector3(1.4571428571428573, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[43], new Vector3(2.357142857142857, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[44], new Vector3(2.357142857142857, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[45], new Vector3(3, 2.0428571428571427, 0))).to.eq(true); - expect(Vector3.equals(positions[46], new Vector3(2.357142857142857, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[47], new Vector3(3, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[48], new Vector3(0, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[49], new Vector3(0.6428571428571428, 3.1428571428571432, 0))).to.eq(true); + expect(Vector3.equals(positions[14], new Vector3(2.4000000953674316, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[15], new Vector3(3, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[16], new Vector3(0, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[17], new Vector3(0.6000000238418579, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[18], new Vector3(0, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[19], new Vector3(0.6000000238418579, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[20], new Vector3(0.6000000238418579, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[21], new Vector3(1.5, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[22], new Vector3(0.6000000238418579, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[23], new Vector3(1.5, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[24], new Vector3(1.5, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[25], new Vector3(2.4000000953674316, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[26], new Vector3(1.5, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[27], new Vector3(2.4000000953674316, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[28], new Vector3(2.4000000953674316, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[29], new Vector3(3, 0.8999999761581421, 0))).to.eq(true); + expect(Vector3.equals(positions[30], new Vector3(2.4000000953674316, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[31], new Vector3(3, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[32], new Vector3(0, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[33], new Vector3(0.6000000238418579, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[34], new Vector3(0, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[35], new Vector3(0.6000000238418579, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[36], new Vector3(0.6000000238418579, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[37], new Vector3(1.5, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[38], new Vector3(0.6000000238418579, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[39], new Vector3(1.5, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[40], new Vector3(1.5, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[41], new Vector3(2.4000000953674316, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[42], new Vector3(1.5, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[43], new Vector3(2.4000000953674316, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[44], new Vector3(2.4000000953674316, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[45], new Vector3(3, 2, 0))).to.eq(true); + expect(Vector3.equals(positions[46], new Vector3(2.4000000953674316, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[47], new Vector3(3, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[48], new Vector3(0, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[49], new Vector3(0.6000000238418579, 3.0999999046325684, 0))).to.eq(true); expect(Vector3.equals(positions[50], new Vector3(0, 4, 0))).to.eq(true); - expect(Vector3.equals(positions[51], new Vector3(0.6428571428571428, 4, 0))).to.eq(true); - expect(Vector3.equals(positions[52], new Vector3(0.6428571428571428, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[53], new Vector3(1.4571428571428573, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[54], new Vector3(0.6428571428571428, 4, 0))).to.eq(true); - expect(Vector3.equals(positions[55], new Vector3(1.4571428571428573, 4, 0))).to.eq(true); - expect(Vector3.equals(positions[56], new Vector3(1.4571428571428573, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[57], new Vector3(2.357142857142857, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[58], new Vector3(1.4571428571428573, 4, 0))).to.eq(true); - expect(Vector3.equals(positions[59], new Vector3(2.357142857142857, 4, 0))).to.eq(true); - expect(Vector3.equals(positions[60], new Vector3(2.357142857142857, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[61], new Vector3(3, 3.1428571428571432, 0))).to.eq(true); - expect(Vector3.equals(positions[62], new Vector3(2.357142857142857, 4, 0))).to.eq(true); + expect(Vector3.equals(positions[51], new Vector3(0.6000000238418579, 4, 0))).to.eq(true); + expect(Vector3.equals(positions[52], new Vector3(0.6000000238418579, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[53], new Vector3(1.5, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[54], new Vector3(0.6000000238418579, 4, 0))).to.eq(true); + expect(Vector3.equals(positions[55], new Vector3(1.5, 4, 0))).to.eq(true); + expect(Vector3.equals(positions[56], new Vector3(1.5, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[57], new Vector3(2.4000000953674316, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[58], new Vector3(1.5, 4, 0))).to.eq(true); + expect(Vector3.equals(positions[59], new Vector3(2.4000000953674316, 4, 0))).to.eq(true); + expect(Vector3.equals(positions[60], new Vector3(2.4000000953674316, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[61], new Vector3(3, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[62], new Vector3(2.4000000953674316, 4, 0))).to.eq(true); expect(Vector3.equals(positions[63], new Vector3(3, 4, 0))).to.eq(true); - expect(Vector3.equals(positions[64], new Vector3(0.6, 3.1, 0))).to.eq(true); - expect(Vector3.equals(positions[65], new Vector3(1.4, 3.1, 0))).to.eq(true); - expect(Vector3.equals(positions[66], new Vector3(0.6, 4, 0))).to.eq(true); - expect(Vector3.equals(positions[67], new Vector3(1.4, 4, 0))).to.eq(true); - expect(Vector3.equals(positions[68], new Vector3(1.4, 3.1, 0))).to.eq(true); - expect(Vector3.equals(positions[69], new Vector3(2.2, 3.1, 0))).to.eq(true); - expect(Vector3.equals(positions[70], new Vector3(1.4, 4, 0))).to.eq(true); - expect(Vector3.equals(positions[71], new Vector3(2.2, 4, 0))).to.eq(true); - expect(Vector3.equals(positions[72], new Vector3(2.2, 3.1, 0))).to.eq(true); - expect(Vector3.equals(positions[73], new Vector3(2.4, 3.1, 0))).to.eq(true); - expect(Vector3.equals(positions[74], new Vector3(2.2, 4, 0))).to.eq(true); - expect(Vector3.equals(positions[75], new Vector3(2.4, 4, 0))).to.eq(true); - expect(Vector3.equals(positions[76], new Vector3(2.4, 3.1, 0))).to.eq(true); - expect(Vector3.equals(positions[77], new Vector3(3, 3.1, 0))).to.eq(true); - expect(Vector3.equals(positions[78], new Vector3(2.4, 4, 0))).to.eq(true); + expect(Vector3.equals(positions[64], new Vector3(0.6000000238418579, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[65], new Vector3(1.399999976158142, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[66], new Vector3(0.6000000238418579, 4, 0))).to.eq(true); + expect(Vector3.equals(positions[67], new Vector3(1.399999976158142, 4, 0))).to.eq(true); + expect(Vector3.equals(positions[68], new Vector3(1.399999976158142, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[69], new Vector3(2.200000047683716, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[70], new Vector3(1.399999976158142, 4, 0))).to.eq(true); + expect(Vector3.equals(positions[71], new Vector3(2.200000047683716, 4, 0))).to.eq(true); + expect(Vector3.equals(positions[72], new Vector3(2.200000047683716, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[73], new Vector3(2.4000000953674316, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[74], new Vector3(2.200000047683716, 4, 0))).to.eq(true); + expect(Vector3.equals(positions[75], new Vector3(2.4000000953674316, 4, 0))).to.eq(true); + expect(Vector3.equals(positions[76], new Vector3(2.4000000953674316, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[77], new Vector3(3, 3.0999999046325684, 0))).to.eq(true); + expect(Vector3.equals(positions[78], new Vector3(2.4000000953674316, 4, 0))).to.eq(true); expect(Vector3.equals(positions[79], new Vector3(3, 4, 0))).to.eq(true); expect(Vector2.equals(uvs[0], new Vector2(0, 1))).to.eq(true); - expect(Vector2.equals(uvs[1], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[2], new Vector2(0, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[3], new Vector2(0.3, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[4], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[5], new Vector2(0.7, 1))).to.eq(true); - expect(Vector2.equals(uvs[6], new Vector2(0.3, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[7], new Vector2(0.7, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[8], new Vector2(0.3, 1))).to.eq(true); - expect(Vector2.equals(uvs[9], new Vector2(0.7, 1))).to.eq(true); - expect(Vector2.equals(uvs[10], new Vector2(0.3, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[11], new Vector2(0.7, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[12], new Vector2(0.7, 1))).to.eq(true); + expect(Vector2.equals(uvs[1], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[2], new Vector2(0, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[3], new Vector2(0.30000001192092896, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[4], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[5], new Vector2(0.699999988079071, 1))).to.eq(true); + expect(Vector2.equals(uvs[6], new Vector2(0.30000001192092896, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[7], new Vector2(0.699999988079071, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[8], new Vector2(0.30000001192092896, 1))).to.eq(true); + expect(Vector2.equals(uvs[9], new Vector2(0.699999988079071, 1))).to.eq(true); + expect(Vector2.equals(uvs[10], new Vector2(0.30000001192092896, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[11], new Vector2(0.699999988079071, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[12], new Vector2(0.699999988079071, 1))).to.eq(true); expect(Vector2.equals(uvs[13], new Vector2(1, 1))).to.eq(true); - expect(Vector2.equals(uvs[14], new Vector2(0.7, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[15], new Vector2(1, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[16], new Vector2(0, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[17], new Vector2(0.3, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[18], new Vector2(0, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[19], new Vector2(0.3, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[20], new Vector2(0.3, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[21], new Vector2(0.7, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[22], new Vector2(0.3, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[23], new Vector2(0.7, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[24], new Vector2(0.3, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[25], new Vector2(0.7, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[26], new Vector2(0.3, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[27], new Vector2(0.7, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[28], new Vector2(0.7, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[29], new Vector2(1, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[30], new Vector2(0.7, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[31], new Vector2(1, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[32], new Vector2(0, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[33], new Vector2(0.3, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[34], new Vector2(0, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[35], new Vector2(0.3, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[36], new Vector2(0.3, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[37], new Vector2(0.7, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[38], new Vector2(0.3, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[39], new Vector2(0.7, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[40], new Vector2(0.3, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[41], new Vector2(0.7, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[42], new Vector2(0.3, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[43], new Vector2(0.7, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[44], new Vector2(0.7, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[45], new Vector2(1, 0.7))).to.eq(true); - expect(Vector2.equals(uvs[46], new Vector2(0.7, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[47], new Vector2(1, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[48], new Vector2(0, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[49], new Vector2(0.3, 0.3))).to.eq(true); + expect(Vector2.equals(uvs[14], new Vector2(0.699999988079071, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[15], new Vector2(1, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[16], new Vector2(0, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[17], new Vector2(0.30000001192092896, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[18], new Vector2(0, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[19], new Vector2(0.30000001192092896, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[20], new Vector2(0.30000001192092896, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[21], new Vector2(0.699999988079071, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[22], new Vector2(0.30000001192092896, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[23], new Vector2(0.699999988079071, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[24], new Vector2(0.30000001192092896, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[25], new Vector2(0.699999988079071, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[26], new Vector2(0.30000001192092896, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[27], new Vector2(0.699999988079071, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[28], new Vector2(0.699999988079071, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[29], new Vector2(1, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[30], new Vector2(0.699999988079071, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[31], new Vector2(1, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[32], new Vector2(0, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[33], new Vector2(0.30000001192092896, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[34], new Vector2(0, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[35], new Vector2(0.30000001192092896, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[36], new Vector2(0.30000001192092896, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[37], new Vector2(0.699999988079071, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[38], new Vector2(0.30000001192092896, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[39], new Vector2(0.699999988079071, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[40], new Vector2(0.30000001192092896, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[41], new Vector2(0.699999988079071, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[42], new Vector2(0.30000001192092896, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[43], new Vector2(0.699999988079071, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[44], new Vector2(0.699999988079071, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[45], new Vector2(1, 0.699999988079071))).to.eq(true); + expect(Vector2.equals(uvs[46], new Vector2(0.699999988079071, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[47], new Vector2(1, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[48], new Vector2(0, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[49], new Vector2(0.30000001192092896, 0.30000001192092896))).to.eq(true); expect(Vector2.equals(uvs[50], new Vector2(0, 0))).to.eq(true); - expect(Vector2.equals(uvs[51], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[52], new Vector2(0.3, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[53], new Vector2(0.7, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[54], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[55], new Vector2(0.7, 0))).to.eq(true); - expect(Vector2.equals(uvs[56], new Vector2(0.3, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[57], new Vector2(0.7, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[58], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[59], new Vector2(0.7, 0))).to.eq(true); - expect(Vector2.equals(uvs[60], new Vector2(0.7, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[61], new Vector2(1, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[62], new Vector2(0.7, 0))).to.eq(true); + expect(Vector2.equals(uvs[51], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[52], new Vector2(0.30000001192092896, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[53], new Vector2(0.699999988079071, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[54], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[55], new Vector2(0.699999988079071, 0))).to.eq(true); + expect(Vector2.equals(uvs[56], new Vector2(0.30000001192092896, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[57], new Vector2(0.699999988079071, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[58], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[59], new Vector2(0.699999988079071, 0))).to.eq(true); + expect(Vector2.equals(uvs[60], new Vector2(0.699999988079071, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[61], new Vector2(1, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[62], new Vector2(0.699999988079071, 0))).to.eq(true); expect(Vector2.equals(uvs[63], new Vector2(1, 0))).to.eq(true); - expect(Vector2.equals(uvs[64], new Vector2(0.3, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[65], new Vector2(0.7, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[66], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[67], new Vector2(0.7, 0))).to.eq(true); - expect(Vector2.equals(uvs[68], new Vector2(0.3, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[69], new Vector2(0.7, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[70], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[71], new Vector2(0.7, 0))).to.eq(true); - expect(Vector2.equals(uvs[72], new Vector2(0.3, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[73], new Vector2(0.4, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[74], new Vector2(0.3, 0))).to.eq(true); - expect(Vector2.equals(uvs[75], new Vector2(0.4, 0))).to.eq(true); - expect(Vector2.equals(uvs[76], new Vector2(0.7, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[77], new Vector2(1, 0.3))).to.eq(true); - expect(Vector2.equals(uvs[78], new Vector2(0.7, 0))).to.eq(true); + expect(Vector2.equals(uvs[64], new Vector2(0.30000001192092896, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[65], new Vector2(0.699999988079071, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[66], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[67], new Vector2(0.699999988079071, 0))).to.eq(true); + expect(Vector2.equals(uvs[68], new Vector2(0.30000001192092896, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[69], new Vector2(0.699999988079071, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[70], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[71], new Vector2(0.699999988079071, 0))).to.eq(true); + expect(Vector2.equals(uvs[72], new Vector2(0.30000001192092896, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[73], new Vector2(0.4000000059604645, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[74], new Vector2(0.30000001192092896, 0))).to.eq(true); + expect(Vector2.equals(uvs[75], new Vector2(0.4000000059604645, 0))).to.eq(true); + expect(Vector2.equals(uvs[76], new Vector2(0.699999988079071, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[77], new Vector2(1, 0.30000001192092896))).to.eq(true); + expect(Vector2.equals(uvs[78], new Vector2(0.699999988079071, 0))).to.eq(true); expect(Vector2.equals(uvs[79], new Vector2(1, 0))).to.eq(true); }); @@ -1574,10 +1549,8 @@ describe("SpriteRenderer", async () => { expect(uvs[1]).to.deep.eq(new Vector2(0, 0)); expect(uvs[2]).to.deep.eq(new Vector2(0, 0)); expect(uvs[3]).to.deep.eq(new Vector2(0, 0)); - // @ts-ignore - const { min, max } = spriteRenderer._bounds; - expect(min).to.deep.eq(new Vector3(0, 0, 0)); - expect(max).to.deep.eq(new Vector3(0, 0, 0)); + expect(spriteRenderer.bounds.min).to.deep.eq(new Vector3(0, 0, 0)); + expect(spriteRenderer.bounds.max).to.deep.eq(new Vector3(0, 0, 0)); const sprite = new Sprite(engine, texture2d); spriteRenderer.sprite = sprite; @@ -1600,8 +1573,26 @@ describe("SpriteRenderer", async () => { expect(uvs[1]).to.deep.eq(new Vector2(1, 1)); expect(uvs[2]).to.deep.eq(new Vector2(0, 0)); expect(uvs[3]).to.deep.eq(new Vector2(1, 0)); - // @ts-ignore - expect(min).to.deep.eq(new Vector3(-0.5, -1, 0)); - expect(max).to.deep.eq(new Vector3(0.5, 1, 0)); + expect(spriteRenderer.bounds.min).to.deep.eq(new Vector3(-0.5, -1, 0)); + expect(spriteRenderer.bounds.max).to.deep.eq(new Vector3(0.5, 1, 0)); }); }); + +function log(positions: Vector3[], uv: Vector2[]): void { + for (let i = 0; i < positions.length; i++) { + console.log( + "expect(Vector3.equals(positions[", + i, + "], new Vector3(", + positions[i].x, + ", ", + positions[i].y, + ", ", + positions[i].z, + "))).to.eq(true);" + ); + } + for (let i = 0; i < uv.length; i++) { + console.log("expect(Vector2.equals(uvs[", i, "], new Vector2(", uv[i].x, ", ", uv[i].y, "))).to.eq(true);"); + } +} diff --git a/tests/src/core/Transform.test.ts b/tests/src/core/Transform.test.ts index f7e29e8d69..a7522f908d 100644 --- a/tests/src/core/Transform.test.ts +++ b/tests/src/core/Transform.test.ts @@ -98,12 +98,17 @@ describe("Transform test", function () { expect((entity5.transform as SubClassOfTransform).size).to.deep.include({ x: 100, y: 100 }); // Add component - expect(() => { - entity0.addComponent(SubClassOfTransform); - }).to.throw("Entity already has a transform."); - expect(() => { - entity1.addComponent(Transform); - }).to.throw("Entity already has a transform."); + const preTransform0 = entity0.transform; + entity0.addComponent(SubClassOfTransform); + expect(preTransform0.destroyed).to.equal(true); + expect(entity0.transform instanceof Transform).to.equal(true); + expect(entity0.transform instanceof SubClassOfTransform).to.equal(true); + + const preTransform1 = entity1.transform; + entity1.addComponent(Transform); + expect(preTransform1.destroyed).to.equal(true); + expect(entity1.transform instanceof Transform).to.equal(true); + expect(entity1.transform instanceof SubClassOfTransform).to.equal(false); }); }); diff --git a/tests/src/ui/Image.test.ts b/tests/src/ui/Image.test.ts new file mode 100644 index 0000000000..e0d78fa728 --- /dev/null +++ b/tests/src/ui/Image.test.ts @@ -0,0 +1,59 @@ +import { Sprite, SpriteDrawMode, SpriteTileMode, Texture2D } from "@galacean/engine-core"; +import { WebGLEngine } from "@galacean/engine-rhi-webgl"; +import { Image } from "@galacean/engine-ui"; +import { describe, expect, it } from "vitest"; + +describe("Image", async () => { + const canvas = document.createElement("canvas"); + const engine = await WebGLEngine.create({ canvas: canvas }); + const webCanvas = engine.canvas; + webCanvas.width = 750; + webCanvas.height = 1334; + const scene = engine.sceneManager.scenes[0]; + const root = scene.createRootEntity("root"); + + const canvasEntity = root.createChild("canvas"); + const image = canvasEntity.addComponent(Image); + + it("Set and Get", () => { + // Sprite + const texture = new Texture2D(engine, 100, 100); + const sprite = new Sprite(engine, texture); + image.sprite = sprite; + expect(image.sprite).to.eq(sprite); + image.sprite = sprite; + expect(image.sprite).to.eq(sprite); + image.sprite = null; + expect(image.sprite).to.eq(null); + + // Alpha HitTest MinimumThreshold + image.alphaHitTestMinimumThreshold = 0.5; + expect(image.alphaHitTestMinimumThreshold).to.eq(0.5); + image.alphaHitTestMinimumThreshold = -0.5; + expect(image.alphaHitTestMinimumThreshold).to.eq(0); + image.alphaHitTestMinimumThreshold = 1.5; + expect(image.alphaHitTestMinimumThreshold).to.eq(1); + + // Draw Mode + image.drawMode = SpriteDrawMode.Simple; + expect(image.drawMode).to.eq(SpriteDrawMode.Simple); + image.drawMode = SpriteDrawMode.Sliced; + expect(image.drawMode).to.eq(SpriteDrawMode.Sliced); + image.drawMode = SpriteDrawMode.Tiled; + expect(image.drawMode).to.eq(SpriteDrawMode.Tiled); + + // Tile Mode + image.tileMode = SpriteTileMode.Adaptive; + expect(image.tileMode).to.eq(SpriteTileMode.Adaptive); + image.tileMode = SpriteTileMode.Continuous; + expect(image.tileMode).to.eq(SpriteTileMode.Continuous); + + // Tiled Adaptive Threshold + image.tiledAdaptiveThreshold = 0.5; + expect(image.tiledAdaptiveThreshold).to.eq(0.5); + image.tiledAdaptiveThreshold = -0.5; + expect(image.tiledAdaptiveThreshold).to.eq(0); + image.tiledAdaptiveThreshold = 1.5; + expect(image.tiledAdaptiveThreshold).to.eq(1); + }); +}); diff --git a/tests/src/ui/UICanvas.test.ts b/tests/src/ui/UICanvas.test.ts new file mode 100644 index 0000000000..8cb0a6a1f2 --- /dev/null +++ b/tests/src/ui/UICanvas.test.ts @@ -0,0 +1,225 @@ +import { Camera } from "@galacean/engine-core"; +import { Vector2 } from "@galacean/engine-math"; +import { WebGLEngine } from "@galacean/engine-rhi-webgl"; +import { CanvasRenderMode, ResolutionAdaptationStrategy, UICanvas, UITransform } from "@galacean/engine-ui"; +import { describe, expect, it } from "vitest"; + +describe("UICanvas", async () => { + const canvas = document.createElement("canvas"); + const engine = await WebGLEngine.create({ canvas: canvas }); + const webCanvas = engine.canvas; + webCanvas.width = 750; + webCanvas.height = 1334; + const scene = engine.sceneManager.scenes[0]; + const root = scene.createRootEntity("root"); + + const canvasEntity = root.createChild("canvas"); + const rootCanvas = canvasEntity.addComponent(UICanvas); + + const cameraEntity = root.createChild("camera"); + const camera = cameraEntity.addComponent(Camera); + + it("Set and Get", () => { + // Render Mode + rootCanvas.renderMode = CanvasRenderMode.WorldSpace; + expect(rootCanvas.renderMode).to.eq(CanvasRenderMode.WorldSpace); + rootCanvas.renderMode = CanvasRenderMode.ScreenSpaceCamera; + expect(rootCanvas.renderMode).to.eq(CanvasRenderMode.ScreenSpaceCamera); + rootCanvas.renderMode = CanvasRenderMode.ScreenSpaceOverlay; + expect(rootCanvas.renderMode).to.eq(CanvasRenderMode.ScreenSpaceOverlay); + + // Reference Resolution + const vec2 = new Vector2(750, 1334); + rootCanvas.referenceResolution = vec2; + expect(rootCanvas.referenceResolution).to.deep.include({ x: 750, y: 1334 }); + vec2.set(800, 600); + expect(rootCanvas.referenceResolution).to.deep.include({ x: 750, y: 1334 }); + rootCanvas.referenceResolution = vec2; + expect(rootCanvas.referenceResolution).to.deep.include({ x: 800, y: 600 }); + + // Render Camera + expect(!!rootCanvas.renderCamera).to.eq(false); + rootCanvas.renderCamera = camera; + expect(rootCanvas.renderCamera).to.eq(camera); + + // Resolution Adaptation Strategy + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.WidthAdaptation; + expect(rootCanvas.resolutionAdaptationStrategy).to.eq(ResolutionAdaptationStrategy.WidthAdaptation); + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.HeightAdaptation; + expect(rootCanvas.resolutionAdaptationStrategy).to.eq(ResolutionAdaptationStrategy.HeightAdaptation); + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.BothAdaptation; + expect(rootCanvas.resolutionAdaptationStrategy).to.eq(ResolutionAdaptationStrategy.BothAdaptation); + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.ShrinkAdaptation; + expect(rootCanvas.resolutionAdaptationStrategy).to.eq(ResolutionAdaptationStrategy.ShrinkAdaptation); + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.ExpandAdaptation; + expect(rootCanvas.resolutionAdaptationStrategy).to.eq(ResolutionAdaptationStrategy.ExpandAdaptation); + + // Sort Order + rootCanvas.sortOrder = 0; + expect(rootCanvas.sortOrder).to.eq(0); + rootCanvas.sortOrder = 10; + expect(rootCanvas.sortOrder).to.eq(10); + + // The vertical distance between the canvas and the camera + rootCanvas.distance = 100; + expect(rootCanvas.distance).to.eq(100); + rootCanvas.distance = 50; + expect(rootCanvas.distance).to.eq(50); + }); + + // Is Root Canvas + it("Is root canvas", () => { + // @ts-ignore + expect(rootCanvas._isRootCanvas).to.eq(true); + const child = canvasEntity.createChild("childCanvas"); + const childCanvas = child.addComponent(UICanvas); + // @ts-ignore + expect(childCanvas._isRootCanvas).to.eq(false); + rootCanvas.enabled = false; + // @ts-ignore + expect(childCanvas._isRootCanvas).to.eq(true); + rootCanvas.enabled = true; + // @ts-ignore + expect(childCanvas._isRootCanvas).to.eq(false); + const parentCanvas = root.addComponent(UICanvas); + // @ts-ignore + expect(parentCanvas._isRootCanvas).to.eq(true); + // @ts-ignore + expect(rootCanvas._isRootCanvas).to.eq(false); + // @ts-ignore + expect(childCanvas._isRootCanvas).to.eq(false); + + parentCanvas.destroy(); + childCanvas.destroy(); + // @ts-ignore + expect(rootCanvas._isRootCanvas).to.eq(true); + }); + + // Size + it("Size Fit", () => { + rootCanvas.referenceResolution = new Vector2(800, 600); + rootCanvas.renderCamera = camera; + rootCanvas.renderMode = CanvasRenderMode.ScreenSpaceCamera; + rootCanvas.distance = 10; + const canvasTransform = canvasEntity.transform; + const canvasScale = canvasTransform.scale; + const canvasSize = canvasTransform.size; + + camera.fieldOfView = 60; + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.WidthAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(811); + expect(Math.floor(canvasScale.y * 100000)).to.eq(811); + expect(Math.floor(canvasScale.z * 100000)).to.eq(811); + expect(Math.floor(canvasSize.x)).to.eq(800); + expect(Math.floor(canvasSize.y)).to.eq(1422); + + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.HeightAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(1924); + expect(Math.floor(canvasScale.y * 100000)).to.eq(1924); + expect(Math.floor(canvasScale.z * 100000)).to.eq(1924); + expect(Math.floor(canvasSize.x)).to.eq(337); + expect(Math.floor(canvasSize.y)).to.eq(600); + + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.BothAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(811); + expect(Math.floor(canvasScale.y * 100000)).to.eq(1924); + expect(Math.floor(canvasScale.z * 100000)).to.eq(1367); + expect(Math.floor(canvasSize.x)).to.eq(800); + expect(Math.floor(canvasSize.y)).to.eq(600); + + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.ExpandAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(811); + expect(Math.floor(canvasScale.y * 100000)).to.eq(811); + expect(Math.floor(canvasScale.z * 100000)).to.eq(811); + expect(Math.floor(canvasSize.x)).to.eq(800); + expect(Math.floor(canvasSize.y)).to.eq(1422); + + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.ShrinkAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(1924); + expect(Math.floor(canvasScale.y * 100000)).to.eq(1924); + expect(Math.floor(canvasScale.z * 100000)).to.eq(1924); + expect(Math.floor(canvasSize.x)).to.eq(337); + expect(Math.floor(canvasSize.y)).to.eq(600); + + rootCanvas.distance = 100; + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.WidthAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(8114); + expect(Math.floor(canvasScale.y * 100000)).to.eq(8114); + expect(Math.floor(canvasScale.z * 100000)).to.eq(8114); + expect(Math.floor(canvasSize.x)).to.eq(800); + expect(Math.floor(canvasSize.y)).to.eq(1422); + + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.HeightAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(19245); + expect(Math.floor(canvasScale.y * 100000)).to.eq(19245); + expect(Math.floor(canvasScale.z * 100000)).to.eq(19245); + expect(Math.floor(canvasSize.x)).to.eq(337); + expect(Math.floor(canvasSize.y)).to.eq(600); + + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.BothAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(8114); + expect(Math.floor(canvasScale.y * 100000)).to.eq(19245); + expect(Math.floor(canvasScale.z * 100000)).to.eq(13679); + expect(Math.floor(canvasSize.x)).to.eq(800); + expect(Math.floor(canvasSize.y)).to.eq(600); + + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.ExpandAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(8114); + expect(Math.floor(canvasScale.y * 100000)).to.eq(8114); + expect(Math.floor(canvasScale.z * 100000)).to.eq(8114); + expect(Math.floor(canvasSize.x)).to.eq(800); + expect(Math.floor(canvasSize.y)).to.eq(1422); + + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.ShrinkAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(19245); + expect(Math.floor(canvasScale.y * 100000)).to.eq(19245); + expect(Math.floor(canvasScale.z * 100000)).to.eq(19245); + expect(Math.floor(canvasSize.x)).to.eq(337); + expect(Math.floor(canvasSize.y)).to.eq(600); + + camera.fieldOfView = 90; + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.WidthAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(14055); + expect(Math.floor(canvasScale.y * 100000)).to.eq(14055); + expect(Math.floor(canvasScale.z * 100000)).to.eq(14055); + expect(Math.floor(canvasSize.x)).to.eq(800); + expect(Math.floor(canvasSize.y)).to.eq(1422); + + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.HeightAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(33333); + expect(Math.floor(canvasScale.y * 100000)).to.eq(33333); + expect(Math.floor(canvasScale.z * 100000)).to.eq(33333); + expect(Math.floor(canvasSize.x)).to.eq(337); + expect(Math.floor(canvasSize.y)).to.eq(600); + + camera.isOrthographic = true; + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.WidthAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(1405); + expect(Math.floor(canvasScale.y * 100000)).to.eq(1405); + expect(Math.floor(canvasScale.z * 100000)).to.eq(1405); + expect(Math.floor(canvasSize.x)).to.eq(800); + expect(Math.floor(canvasSize.y)).to.eq(1422); + + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.HeightAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(3333); + expect(Math.floor(canvasScale.y * 100000)).to.eq(3333); + expect(Math.floor(canvasScale.z * 100000)).to.eq(3333); + expect(Math.floor(canvasSize.x)).to.eq(337); + expect(Math.floor(canvasSize.y)).to.eq(600); + + camera.viewport.set(0, 0, 0.5, 1); + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.WidthAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(702); + expect(Math.floor(canvasScale.y * 100000)).to.eq(702); + expect(Math.floor(canvasScale.z * 100000)).to.eq(702); + expect(Math.floor(canvasSize.x)).to.eq(800); + expect(Math.floor(canvasSize.y)).to.eq(2845); + + rootCanvas.resolutionAdaptationStrategy = ResolutionAdaptationStrategy.HeightAdaptation; + expect(Math.floor(canvasScale.x * 100000)).to.eq(3333); + expect(Math.floor(canvasScale.y * 100000)).to.eq(3333); + expect(Math.floor(canvasScale.z * 100000)).to.eq(3333); + expect(Math.floor(canvasSize.x)).to.eq(168); + expect(Math.floor(canvasSize.y)).to.eq(600); + }); +}); diff --git a/tests/src/ui/UIGroup.test.ts b/tests/src/ui/UIGroup.test.ts new file mode 100644 index 0000000000..698d90f743 --- /dev/null +++ b/tests/src/ui/UIGroup.test.ts @@ -0,0 +1,72 @@ +import { Camera } from "@galacean/engine-core"; +import { Vector3 } from "@galacean/engine-math"; +import { WebGLEngine } from "@galacean/engine-rhi-webgl"; +import { UICanvas, UIGroup } from "@galacean/engine-ui"; +import { describe, expect, it } from "vitest"; + +describe("UIGroup", async () => { + const canvas = document.createElement("canvas"); + const engine = await WebGLEngine.create({ canvas: canvas }); + const webCanvas = engine.canvas; + webCanvas.width = 750; + webCanvas.height = 1334; + const scene = engine.sceneManager.scenes[0]; + const root = scene.createRootEntity("root"); + + // Create camera + const cameraEntity = root.createChild("Camera"); + cameraEntity.transform.position = new Vector3(0, 0, 10); + const camera = cameraEntity.addComponent(Camera); + camera.fieldOfView = 60; + camera.farClipPlane = 200; + camera.nearClipPlane = 0.3; + camera.isOrthographic = true; + + // 添加 canvas + const canvasEntity = root.createChild("canvas"); + const group = canvasEntity.addComponent(UIGroup); + + it("Set and Get", () => { + // Ignore Parent Group + group.ignoreParentGroup = true; + expect(group.ignoreParentGroup).to.eq(true); + group.ignoreParentGroup = false; + expect(group.ignoreParentGroup).to.eq(false); + + // Alpha + group.alpha = 0.5; + expect(group.alpha).to.eq(0.5); + group.alpha = -0.5; + expect(group.alpha).to.eq(0); + group.alpha = 1.5; + expect(group.alpha).to.eq(1); + + // Interactive + group.interactive = false; + expect(group.interactive).to.eq(false); + group.interactive = true; + expect(group.interactive).to.eq(true); + }); + + it("Get Global", () => { + const rootGroup = root.addComponent(UIGroup); + // Alpha + rootGroup.alpha = 0.5; + group.alpha = 0.4; + expect(group.globalAlpha).to.eq(0.4); + root.addComponent(UICanvas); + expect(group.globalAlpha).to.eq(0.2); + rootGroup.enabled = false; + expect(group.globalAlpha).to.eq(0.4); + rootGroup.enabled = true; + expect(group.globalAlpha).to.eq(0.2); + group.ignoreParentGroup = true; + expect(group.globalAlpha).to.eq(0.4); + + // Interactive + rootGroup.interactive = false; + expect(group.globalInteractive).to.eq(true); + group.ignoreParentGroup = false; + expect(group.globalInteractive).to.eq(false); + }); +}); diff --git a/tests/src/ui/UIInteractive.test.ts b/tests/src/ui/UIInteractive.test.ts new file mode 100644 index 0000000000..c9d0f98776 --- /dev/null +++ b/tests/src/ui/UIInteractive.test.ts @@ -0,0 +1,100 @@ +import { Camera, PointerEventData, SpriteDrawMode } from "@galacean/engine-core"; +import { Vector3 } from "@galacean/engine-math"; +import { WebGLEngine } from "@galacean/engine-rhi-webgl"; +import { Button, Image, Label, ScaleTransition, UICanvas, UIGroup, UITransform } from "@galacean/engine-ui"; +import { describe, expect, it } from "vitest"; + +describe("Button", async () => { + const canvas = document.createElement("canvas"); + const engine = await WebGLEngine.create({ canvas: canvas }); + const webCanvas = engine.canvas; + webCanvas.width = 750; + webCanvas.height = 1334; + const scene = engine.sceneManager.scenes[0]; + const root = scene.createRootEntity("root"); + + // Create camera + const cameraEntity = root.createChild("Camera"); + cameraEntity.transform.position = new Vector3(0, 0, 10); + const camera = cameraEntity.addComponent(Camera); + camera.fieldOfView = 60; + camera.farClipPlane = 200; + camera.nearClipPlane = 0.3; + camera.isOrthographic = true; + + // Create group + const canvasEntity = root.createChild("canvas"); + canvasEntity.addComponent(UIGroup); + + // Create button + const buttonEntity = canvasEntity.createChild("Image"); + const image = buttonEntity.addComponent(Image); + image.drawMode = SpriteDrawMode.Sliced; + (buttonEntity.transform).size.set(120, 40); + const textEntity = buttonEntity.createChild("Text"); + (textEntity.transform).size.set(120, 40); + const text = textEntity.addComponent(Label); + text.text = "Button"; + text.color.set(0, 0, 0, 1); + const button = buttonEntity.addComponent(Button); + + it("Set and Get", () => { + // Click + let clickCount = 0; + const onClick = () => { + clickCount++; + }; + button.addClicked(onClick); + button.onPointerClick(new PointerEventData()); + expect(clickCount).to.eq(1); + button.removeClicked(onClick); + button.onPointerClick(new PointerEventData()); + expect(clickCount).to.eq(1); + + // Transition + const scaleTransition = button.addTransition(ScaleTransition); + expect(button.getTransition(ScaleTransition)).to.eq(scaleTransition); + const result = []; + button.getTransitions(ScaleTransition, result); + expect(result.length).to.eq(1); + expect(result[0]).to.eq(scaleTransition); + scaleTransition.destroy(); + button.getTransitions(ScaleTransition, result); + expect(result.length).to.eq(0); + }); + + it("Interactive State", () => { + button.onPointerBeginDrag(); + // InteractiveState.Down + // @ts-ignore + expect(button._getInteractiveState()).to.eq(1); + button.onPointerEndDrag(); + // InteractiveState.Normal + // @ts-ignore + expect(button._getInteractiveState()).to.eq(0); + button.onPointerEnter(); + // InteractiveState.Pressed + // @ts-ignore + expect(button._getInteractiveState()).to.eq(2); + button.onPointerExit(); + // InteractiveState.Normal + // @ts-ignore + expect(button._getInteractiveState()).to.eq(0); + button.interactive = false; + // InteractiveState.Disable + // @ts-ignore + expect(button._getInteractiveState()).to.eq(3); + button.interactive = true; + // InteractiveState.Normal + // @ts-ignore + expect(button._getInteractiveState()).to.eq(0); + button.entity.addComponent(UIGroup).interactive = false; + // InteractiveState.Normal + // @ts-ignore + expect(button._getInteractiveState()).to.eq(0); + canvasEntity.addComponent(UICanvas); + // InteractiveState.Disable + // @ts-ignore + expect(button._getInteractiveState()).to.eq(3); + }); +});