Skip to content

Commit

Permalink
Merge pull request #755 from galacean/feat/2.1
Browse files Browse the repository at this point in the history
Merge origin/feat/2.1 into origin/main
  • Loading branch information
yiiqii authored Nov 19, 2024
2 parents 31498c0 + 136b832 commit 6138311
Show file tree
Hide file tree
Showing 293 changed files with 12,230 additions and 4,341 deletions.
26 changes: 26 additions & 0 deletions packages/effects-core/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,32 @@ Repository: https://github.com/ampas/aces-dev

WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE ACADEMY SPECIFICALLY DISCLAIMS ANY REPRESENTATIONS OR WARRANTIES WHATSOEVER RELATED TO PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS IN THE ACADEMY COLOR ENCODING SYSTEM, OR APPLICATIONS THEREOF, HELD BY PARTIES OTHER THAN A.M.P.A.S.,WHETHER DISCLOSED OR UNDISCLOSED.

3. pixijs

License: [MIT License](https://github.com/pixijs/pixijs/blob/dev/LICENSE)

Repository: https://github.com/pixijs/pixijs

Copyright (c) 2013-2023 Mathew Groves, Chad Engler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Please refer to the corresponding repository for more information on each component's license and terms of use.

Galacean Effects Core Library is distributed under the MIT License. Please see the LICENSE file for the full text of the license.
5 changes: 3 additions & 2 deletions packages/effects-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@
"registry": "https://registry.npmjs.org"
},
"dependencies": {
"@galacean/effects-specification": "2.0.2",
"@galacean/effects-specification": "2.1.0",
"@galacean/effects-math": "1.1.0",
"flatbuffers": "24.3.25",
"uuid": "9.0.1"
"uuid": "9.0.1",
"libtess": "1.2.2"
}
}
85 changes: 85 additions & 0 deletions packages/effects-core/src/animation/color-playable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import * as spec from '@galacean/effects-specification';
import { createValueGetter, vecFill, vecMulCombine, type ValueGetter } from '../math';
import type { FrameContext } from '../plugins/cal/playable-graph';
import { Playable } from '../plugins/cal/playable-graph';
import { VFXItem } from '../vfx-item';
import type { Material } from '../material';
import type { ColorStop } from '../utils';
import { colorStopsFromGradient, getColorFromGradientStops } from '../utils';
import { BaseRenderComponent } from '../components';

export interface ColorPlayableAssetData extends spec.EffectsObjectData {
colorOverLifetime?: spec.ColorOverLifetime,
}

const tempColor: spec.RGBAColorValue = [1, 1, 1, 1];

export class ColorPlayable extends Playable {
clipData: { colorOverLifetime?: spec.ColorOverLifetime, startColor?: spec.RGBAColorValue };
colorOverLifetime: ColorStop[];
opacityOverLifetime: ValueGetter<number>;
startColor: spec.RGBAColorValue;
renderColor: spec.vec4 = [1, 1, 1, 1];
activeComponent?: BaseRenderComponent;
activeMaterial?: Material;

override processFrame (context: FrameContext): void {
const boundObject = context.output.getUserData();

if (!(boundObject instanceof VFXItem)) {
return;
}
if (!this.activeComponent) {
this.activeComponent = this.getActiveComponent(boundObject);
}
if (!this.activeMaterial) {
this.activeMaterial = this.activeComponent?.material;
const startColor = this.activeMaterial?.getVector4('_Color');

if (startColor) {
this.startColor = startColor.toArray();
}
}

this.activeComponent?.setAnimationTime(this.time);
let colorInc = vecFill(tempColor, 1);
let colorChanged;
const life = this.time / boundObject.duration;

const opacityOverLifetime = this.opacityOverLifetime;
const colorOverLifetime = this.colorOverLifetime;

if (colorOverLifetime) {
colorInc = getColorFromGradientStops(colorOverLifetime, life, true) as spec.vec4;
colorChanged = true;
}
if (opacityOverLifetime) {
colorInc[3] *= opacityOverLifetime.getValue(life);
colorChanged = true;
}

if (colorChanged) {
vecMulCombine<spec.vec4>(this.renderColor, colorInc, this.startColor);
this.activeMaterial?.getVector4('_Color')?.setFromArray(this.renderColor);
}
}

create (clipData: ColorPlayableAssetData) {
this.clipData = clipData;
const colorOverLifetime = clipData.colorOverLifetime;

if (colorOverLifetime) {
this.opacityOverLifetime = createValueGetter(colorOverLifetime.opacity ?? 1);
if (colorOverLifetime.color && colorOverLifetime.color[0] === spec.ValueType.GRADIENT_COLOR) {
this.colorOverLifetime = colorStopsFromGradient(colorOverLifetime.color[1]);
}
}

return this;
}

getActiveComponent (boundObject: VFXItem): BaseRenderComponent {
return boundObject.getComponent(BaseRenderComponent);
}

}
1 change: 1 addition & 0 deletions packages/effects-core/src/animation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './color-playable';
4 changes: 2 additions & 2 deletions packages/effects-core/src/asset-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class AssetLoader {

effectsObject.setInstanceId(effectsObjectData.id);
this.engine.addInstance(effectsObject);
SerializationHelper.deserializeTaggedProperties(effectsObjectData, effectsObject);
SerializationHelper.deserialize(effectsObjectData, effectsObject);

return effectsObject as T;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ export class AssetLoader {

effectsObject.setInstanceId(effectsObjectData.id);
this.engine.addInstance(effectsObject);
await SerializationHelper.deserializeTaggedPropertiesAsync(effectsObjectData, effectsObject);
await SerializationHelper.deserializeAsync(effectsObjectData, effectsObject);

return effectsObject as T;
}
Expand Down
Loading

0 comments on commit 6138311

Please sign in to comment.