Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/effects-core/src/components/base-render-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,12 @@ export class MaskableGraphic extends RendererComponent implements Maskable {
}
}

override fromData (data: unknown): void {
override fromData (data: MaskableGraphicData): void {
super.fromData(data);

const maskableGraphicData = (data as MaskableGraphicData);
const renderer = maskableGraphicData.renderer ?? {};
const renderer = data.renderer ?? {};

const maskOptions = maskableGraphicData.mask;
const maskOptions = data.mask;

if (maskOptions) {
this.maskManager.setMaskOptions(this.engine, maskOptions);
Expand Down
3 changes: 2 additions & 1 deletion packages/effects-core/src/components/component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as spec from '@galacean/effects-specification';
import { serialize } from '../decorators';
import { EffectsObject } from '../effects-object';
import { removeItem } from '../utils';
Expand Down Expand Up @@ -163,7 +164,7 @@ export abstract class Component extends EffectsObject {
}
}

override fromData (data: any): void {
override fromData (data: spec.ComponentData): void {
super.fromData(data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class CompositionComponent extends Component {
}
}

override fromData (data: any): void {
override fromData (data: spec.CompositionComponentData): void {
super.fromData(data);

this._timelineInstance = null;
Expand Down
7 changes: 6 additions & 1 deletion packages/effects-core/src/components/frame-component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as spec from '@galacean/effects-specification';
import { RendererComponent } from './renderer-component';
import type { VFXItem } from '../vfx-item';
import { Material, type Maskable } from '../material';
Expand All @@ -10,6 +11,10 @@ import { effectsClass } from '../decorators';
import type { HitTestTriangleParams } from '../plugins';
import { addItem } from '../utils';

interface FrameComponentData extends spec.ComponentData {
color?: spec.ColorData,
}

@effectsClass('FrameComponent')
export class FrameComponent extends RendererComponent implements Maskable {
color = new Color(1, 1, 1, 1);
Expand Down Expand Up @@ -113,7 +118,7 @@ export class FrameComponent extends RendererComponent implements Maskable {
this.maskManager.drawGeometryMask(this.engine.renderer, this.clipGeometry, this.worldMatrix, this.material, maskRef);
}

override fromData (data: any): void {
override fromData (data: FrameComponentData): void {
super.fromData(data);

if (data.color) {
Expand Down
11 changes: 7 additions & 4 deletions packages/effects-core/src/components/mesh-component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as spec from '@galacean/effects-specification';
import { serialize } from '../decorators';
import type { Engine } from '../engine';
import type { Maskable } from '../material';
Expand All @@ -6,6 +7,10 @@ import type { BoundingBoxTriangle, HitTestTriangleParams, BoundingBoxInfo } from
import type { Geometry, Renderer } from '../render';
import { RendererComponent } from './renderer-component';

interface MeshComponentData extends spec.ComponentData {
mask?: spec.MaskOptions,
}

/**
* Mesh 组件
*/
Expand Down Expand Up @@ -83,12 +88,10 @@ export class MeshComponent extends RendererComponent implements Maskable {
return this.boundingBoxInfo;
}

// TODO: Update data spec
override fromData (data: any): void {
override fromData (data: MeshComponentData): void {
super.fromData(data);

const maskableRendererData = data;
const maskOptions = maskableRendererData.mask;
const maskOptions = data.mask;

if (maskOptions) {
this.maskManager.setMaskOptions(this.engine, maskOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { Component } from '../../components';
import { effectsClass } from '../../decorators';
import type { Engine } from '../../engine';

interface CameraControllerData extends spec.ComponentData, spec.CameraContent {}

@effectsClass(spec.DataType.CameraController)
export class CameraController extends Component {
private options: CameraControllerOptions;

constructor (
engine: Engine,
props?: spec.CameraContent,
props?: CameraControllerData,
) {
super(engine);

Expand All @@ -34,7 +36,7 @@ export class CameraController extends Component {
}
}

override fromData (data: spec.CameraContent): void {
override fromData (data: CameraControllerData): void {
super.fromData(data);

this.options = data.options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export class InteractComponent extends RendererComponent {
};
}

override fromData (data: spec.InteractContent): void {
override fromData (data: spec.InteractComponentData): void {
super.fromData(data);
this.interactData = data;
if (data.options.type === spec.InteractType.DRAG) {
Expand Down
6 changes: 3 additions & 3 deletions packages/effects-core/src/plugins/particle/particle-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class ParticleSystem extends Component implements Maskable {

constructor (
engine: Engine,
props?: ParticleSystemProps,
props?: spec.ParticleSystemData,
) {
super(engine);

Expand Down Expand Up @@ -850,9 +850,9 @@ export class ParticleSystem extends Component implements Maskable {
}
};

override fromData (data: unknown): void {
override fromData (data: spec.ParticleSystemData): void {
super.fromData(data);
const props = data as ParticleSystemProps;
const props = data;

this.props = props;
const cachePrefix = '';
Expand Down
2 changes: 1 addition & 1 deletion packages/effects-core/src/plugins/timeline/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class TrackAsset extends PlayableAsset {
return clip.asset.createPlayable();
}

override fromData (data: spec.EffectsObjectData): void {
override fromData (data: spec.TrackAssetData): void {
super.fromData(data);
for (const child of this.children) {
child.parent = this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EffectsObjectData } from '@galacean/effects-specification';
import type { TrackAssetData } from '@galacean/effects-specification';
import { serialize } from '../../../decorators';
import { TrackAsset } from '../track';

Expand All @@ -9,7 +9,7 @@ export abstract class PropertyTrack extends TrackAsset {
@serialize()
protected path = '';

override fromData (data: EffectsObjectData): void {
override fromData (data: TrackAssetData): void {
super.fromData(data);
const propertyNames = this.path.split('.');

Expand Down
2 changes: 1 addition & 1 deletion packages/effects-threejs/src/material/three-material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export class ThreeMaterial extends Material {
throw new Error('Method not implemented.');
}

override fromData (data: unknown): void {
override fromData (data: spec.MaterialData): void {
//FIXME: 暂时不实现
throw new Error('Method not implemented.');
}
Expand Down
6 changes: 3 additions & 3 deletions packages/effects-threejs/src/three-texture.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
Engine, Texture2DSourceOptionsCompressed, Texture2DSourceOptionsData,
Texture2DSourceOptionsFramebuffer, Texture2DSourceOptionsImage,
Texture2DSourceOptionsVideo, TextureDataType, TextureSourceOptions,
Texture2DSourceOptionsVideo, TextureDataType, TextureSourceOptions, spec,
} from '@galacean/effects-core';
import { glContext, Texture, TextureSourceType } from '@galacean/effects-core';
import * as THREE from 'three';
Expand Down Expand Up @@ -126,10 +126,10 @@ export class ThreeTexture extends Texture {
* 通过图层设置创建贴图
* @param data - 图层设置
*/
override fromData (data: any): void {
override fromData (data: spec.EffectsObjectData): void {
super.fromData(data);

this.texture = this.createTextureByType(data);
this.texture = this.createTextureByType(data as unknown as TextureSourceOptions);
this.texture.needsUpdate = true;
Comment on lines +129 to 133
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify lifecycle paths and current disposal behavior around ThreeTexture.fromData.
rg -n --type=ts -C3 'new ThreeTexture\(' packages/effects-threejs
rg -n --type=ts -C3 '\.fromData\(' packages/effects-threejs
rg -n --type=ts -C3 'updateSource\s*\(|fromData\s*\(|this\.texture\.dispose\(' packages/effects-threejs/src/three-texture.ts

Repository: galacean/effects-runtime

Length of output: 3515


🏁 Script executed:

#!/bin/bash

# 1. Check constructor and initialization
echo "=== Constructor and initialization ==="
rg -n --type=ts -A20 'class ThreeTexture' packages/effects-threejs/src/three-texture.ts | head -40

# 2. Check if fromData is called repeatedly or once
echo -e "\n=== fromData usage patterns ==="
rg -n --type=ts 'fromData\(' packages/effects-threejs --max-count=20

# 3. Look for texture property initialization
echo -e "\n=== Texture property declaration and initialization ==="
rg -n --type=ts 'texture\s*[:=]|this\.texture\s*=' packages/effects-threejs/src/three-texture.ts

# 4. Check parent class to understand the contract
echo -e "\n=== Check base class structure ==="
rg -n --type=ts 'class Texture|fromData' packages/effects-core/src/texture.ts | head -30

Repository: galacean/effects-runtime

Length of output: 1772


🏁 Script executed:

#!/bin/bash

# 1. Get full constructor
echo "=== Constructor (full) ==="
rg -n --type=ts -B5 -A30 'constructor\s*\(' packages/effects-threejs/src/three-texture.ts

# 2. Find parent class location
echo -e "\n=== Find parent Texture class ==="
fd -t f '\.ts$' packages/effects-core | xargs rg -l 'export class Texture' | head -5

# 3. Check parent class fromData method
echo -e "\n=== Parent class fromData ==="
fd -t f '\.ts$' packages/effects-core | xargs rg -B3 -A10 'fromData\s*\(' | grep -A10 'class Texture' | head -30

Repository: galacean/effects-runtime

Length of output: 1208


🏁 Script executed:

#!/bin/bash

# 1. Find parent Texture class definition
echo "=== Parent Texture class definition ==="
rg -n --type=ts 'export class Texture' packages/effects-core/src

# 2. Check parent class fromData method
echo -e "\n=== Parent fromData in Texture class ==="
rg -n --type=ts -B2 -A15 'class Texture\b' packages/effects-core/src/texture/*.ts | grep -A20 'fromData'

# 3. Search for repeated fromData calls on texture objects to understand lifecycle
echo -e "\n=== Check if fromData is called multiple times ==="
rg -n --type=ts -B5 -A5 'fromData.*TextureSourceOptions|\.fromData\(.*data.*\)' packages/effects-threejs

# 4. Check if components/layers reuse texture instances
echo -e "\n=== Layer/component lifecycle ==="
rg -n --type=ts 'class.*Layer|class.*Component' packages/effects-threejs/src | head -10

Repository: galacean/effects-runtime

Length of output: 3381


🏁 Script executed:

#!/bin/bash

# 1. Check imports in three-texture.ts to find parent Texture
echo "=== Imports in three-texture.ts ==="
head -30 packages/effects-threejs/src/three-texture.ts | rg 'import|from'

# 2. Find Texture class in effects-core
echo -e "\n=== Search for Texture base class ==="
fd -t f '\.ts$' packages/effects-core/src | xargs rg -l 'export class Texture\b' 2>/dev/null

# 3. Check the actual parent class and its fromData method
echo -e "\n=== Texture base class fromData ==="
fd -t f '\.ts$' packages/effects-core | xargs rg -B5 -A15 'export class Texture\b' | head -60

Repository: galacean/effects-runtime

Length of output: 338


🏁 Script executed:

#!/bin/bash

# 1. Search more broadly for Texture in effects-core
echo "=== Search for Texture class definition ==="
rg -n 'class Texture' packages/effects-core/src --type=ts | head -20

# 2. Check index file for exports
echo -e "\n=== Texture exports in effects-core ==="
rg -n 'Texture' packages/effects-core/src/index.ts | head -20

# 3. Find the actual file
echo -e "\n=== Locate texture.ts files ==="
fd 'texture' packages/effects-core/src --type=f | grep -v node_modules

# 4. Check one of these files for Texture class
echo -e "\n=== Check main texture file ==="
rg -n -B2 -A20 'export.*class Texture\b' packages/effects-core/src/texture.ts 2>/dev/null || rg -n 'class Texture' packages/effects-core/src/texture.ts 2>/dev/null

Repository: galacean/effects-runtime

Length of output: 835


🏁 Script executed:

#!/bin/bash

# 1. Check parent Texture class and its fromData method
echo "=== Parent Texture class fromData ==="
rg -n -B3 -A15 'fromData' packages/effects-core/src/texture/texture.ts

# 2. Check if Texture.texture is initialized elsewhere
echo -e "\n=== Texture property in base class ==="
rg -n 'texture\s*:' packages/effects-core/src/texture/texture.ts

# 3. Check the full Texture class structure
echo -e "\n=== Full Texture class structure (first 50 lines) ==="
head -80 packages/effects-core/src/texture/texture.ts

Repository: galacean/effects-runtime

Length of output: 1944


🏁 Script executed:

#!/bin/bash

# 1. Check if fromData exists in parent Texture class
echo "=== Full search for fromData in texture.ts ==="
rg -n 'fromData' packages/effects-core/src/texture/texture.ts

# 2. Check EffectsObject for fromData
echo -e "\n=== fromData in EffectsObject ==="
rg -n -B3 -A10 'fromData' packages/effects-core/src/effects-object.ts

# 3. Check if texture instance can be reused across multiple fromData calls
echo -e "\n=== Check scene/layer structure for texture reuse ==="
rg -n 'new ThreeTexture\|\.texture\s*=' packages/effects-threejs/src/three-texture.ts

# 4. Check if components maintain texture across updates
echo -e "\n=== Component texture lifecycle ==="
rg -n -B5 -A5 'texture.*fromData\|fromData.*texture' packages/effects-threejs/src

Repository: galacean/effects-runtime

Length of output: 528


Dispose previous texture before reassigning in fromData.

At lines 132-133, this.texture is reassigned without disposing the old instance. Since updateSource() properly disposes before reassignment (line 77), fromData() should follow the same pattern to prevent GPU memory leaks on repeated calls.

🛠️ Suggested fix
  override fromData (data: spec.EffectsObjectData): void {
    super.fromData(data);

-   this.texture = this.createTextureByType(data as unknown as TextureSourceOptions);
+   const nextTexture = this.createTextureByType(data as unknown as TextureSourceOptions);
+   this.texture?.dispose();
    this.texture = nextTexture;
    this.texture.needsUpdate = true;
  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/effects-threejs/src/three-texture.ts` around lines 129 - 133,
fromData currently reassigns this.texture via createTextureByType and sets
needsUpdate without disposing the previous THREE texture, causing GPU leaks;
modify fromData (the override method) to check for an existing this.texture and
call its dispose (matching the pattern used in updateSource) before assigning a
new texture from createTextureByType, then set this.texture.needsUpdate = true.

}

Expand Down
6 changes: 3 additions & 3 deletions packages/effects-webgl/src/gl-texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class GLTexture extends Texture implements Disposable, RestoreHandler {
constructor (engine: Engine, source?: TextureSourceOptions) {
super(engine);
if (source) {
this.fromData(source);
this.fromData(source as unknown as spec.EffectsObjectData);
}
}

Expand Down Expand Up @@ -322,9 +322,9 @@ export class GLTexture extends Texture implements Disposable, RestoreHandler {
gl.texParameteri(target, gl.TEXTURE_WRAP_T, isPot ? wrapT : gl.CLAMP_TO_EDGE);
}

override fromData (data: any): void {
override fromData (data: spec.EffectsObjectData): void {
super.fromData(data);
const source = data as TextureSourceOptions;
const source = data as unknown as TextureSourceOptions;
const options = this.assembleOptions(source);
const { sourceType, sourceFrom, name = '' } = options;

Expand Down
10 changes: 8 additions & 2 deletions plugin-packages/editor-gizmo/src/gizmo-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import { moveToPointWidthFixDistance } from './util';
import { WireframeGeometryType, createModeWireframe, destroyWireframeMesh, updateWireframeMesh } from './wireframe';
import { GeometryType } from './geometry';

// TODO: Move to spec
interface GizmoComponentData extends spec.ComponentData {
options: GizmoVFXItemOptions,
transform?: Record<string, unknown>,
}

const editorRenderPassName = 'editor-gizmo';
const frontRenderPassName = 'front-gizmo';
const behindRenderPassName = 'behind-gizmo';
Expand Down Expand Up @@ -564,15 +570,15 @@ export class GizmoComponent extends RendererComponent {
this.targetItem = item;
}

override fromData (data: any): void {
override fromData (data: GizmoComponentData): void {
super.fromData(data);
const item = this.item;

item.duration = 999;
const {
target, subType, renderMode, size, depthTest,
color = [255, 255, 255],
} = data.options as GizmoVFXItemOptions;
} = data.options;

this.target = target;
this.subType = subType;
Expand Down
7 changes: 5 additions & 2 deletions plugin-packages/model/src/plugin/model-tree-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import type { Engine } from '@galacean/effects';
import { Behaviour, effectsClass, spec } from '@galacean/effects';
import type { ModelTreeContent } from '../index';

// TODO: Move to spec
interface ModelTreeComponentData extends spec.ComponentData, ModelTreeContent {}

/**
* 插件场景树组件类,实现 3D 场景树功能
*
Expand All @@ -20,7 +23,7 @@ export class ModelTreeComponent extends Behaviour {
* @param engine
* @param options
*/
constructor (engine: Engine, options?: ModelTreeContent) {
constructor (engine: Engine, options?: ModelTreeComponentData) {
super(engine);
if (options) {
this.fromData(options);
Expand All @@ -31,7 +34,7 @@ export class ModelTreeComponent extends Behaviour {
* 反序列化,保存入参和创建节点树元素
* @param options
*/
override fromData (options: ModelTreeContent): void {
override fromData (options: ModelTreeComponentData): void {
super.fromData(options);
this.options = options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@ import type { spec } from '@galacean/effects';
import { Behaviour, effectsClass } from '@galacean/effects';
import type { CompositionTransformerAcceler } from './composition-transformer-acceler';

// TODO: Move to spec
interface OrientationComponentData extends spec.ComponentData {
options: {
targets?: spec.PluginGyroscopeTarget[],
},
}

/**
* Orientation component class
*/
@effectsClass('OrientationComponent')
export class OrientationComponent extends Behaviour {
private targets: spec.PluginGyroscopeTarget[];

override fromData (data: any) {
override fromData (data: OrientationComponentData): void {
super.fromData(data);

const { targets } = data.options;

if (targets) {
this.targets = targets.map((t: any) => ({
this.targets = targets.map(t => ({
name: t.name,
xMin: +t.xMin || 0,
yMin: +t.yMin || 0,
Expand Down
Loading
Loading