Make animation module optional (#10257)

This commit is contained in:
Leslie Leigh (李的序)
2022-03-10 11:55:11 +08:00
committed by GitHub
parent df6465c723
commit 93b856b98e
41 changed files with 140 additions and 60 deletions
+2
View File
@@ -4,6 +4,8 @@
"gfx-webgl": { "modules": [ "gfx-webgl" ] },
"gfx-webgl2": { "modules": [ "gfx-webgl2" ] },
"3d": { "modules": [ "3d" ] },
"animation": { "modules": ["animation"] },
"skeletal-animation": { "modules": ["animation", "skeletal-animation"] },
"2d": { "modules": [ "2d" ] },
"ui": { "modules": [ "ui", "2d" ] },
"particle": { "modules": [ "particle" ] },
+1 -1
View File
@@ -32,7 +32,7 @@ import { ccclass, type, serializable } from 'cc.decorator';
import { CCString } from '../../core/data/utils/attribute';
import { Mat4 } from '../../core/math';
import { murmurhash2_32_gc } from '../../core/utils/murmurhash2_gc';
import { DataPoolManager } from '../skeletal-animation/data-pool-manager';
import type { DataPoolManager } from '../skeletal-animation/data-pool-manager';
import { Asset } from '../../core/assets/asset';
import { legacyCC } from '../../core/global-exports';
-1
View File
@@ -37,7 +37,6 @@ export * from './framework';
export * from './lights';
export * from './skinned-mesh-renderer';
export * from './skeletal-animation';
export {
utils,
};
@@ -0,0 +1,10 @@
import { Address, Filter, SamplerInfo } from '../../core/gfx';
export const jointTextureSamplerInfo = new SamplerInfo(
Filter.POINT,
Filter.POINT,
Filter.NONE,
Address.CLAMP,
Address.CLAMP,
Address.CLAMP,
);
+4 -3
View File
@@ -29,7 +29,7 @@
*/
import { JSB } from 'internal:constants';
import { AnimationClip } from '../../core/animation/animation-clip';
import type { AnimationClip } from '../../core/animation/animation-clip';
import { Mesh } from '../assets/mesh';
import { Skeleton } from '../assets/skeleton';
import { AABB } from '../../core/geometry';
@@ -37,12 +37,13 @@ import { BufferUsageBit, MemoryUsageBit, Attribute, DescriptorSet, Buffer, Buffe
import { INST_JOINT_ANIM_INFO, UBOSkinningAnimation, UBOSkinningTexture, UNIFORM_JOINT_TEXTURE_BINDING } from '../../core/pipeline/define';
import { Node } from '../../core/scene-graph';
import { IMacroPatch, Pass } from '../../core/renderer/core/pass';
import { DataPoolManager } from '../skeletal-animation/data-pool-manager';
import type { DataPoolManager } from '../skeletal-animation/data-pool-manager';
import { ModelType } from '../../core/renderer/scene/model';
import { IAnimInfo, IJointTextureHandle, jointTextureSamplerInfo } from '../skeletal-animation/skeletal-animation-utils';
import { IAnimInfo, IJointTextureHandle } from '../skeletal-animation/skeletal-animation-utils';
import { MorphModel } from './morph-model';
import { legacyCC } from '../../core/global-exports';
import { NativeAABB, NativeBakedSkinningModel } from '../../core/renderer/scene/native-scene';
import { jointTextureSamplerInfo } from '../misc/joint-texture-sampler-info';
interface IJointsInfo {
buffer: Buffer | null;
@@ -28,8 +28,8 @@
* @hidden
*/
import { AnimationClip } from '../../core/animation/animation-clip';
import { Skeleton } from '../assets';
import type { AnimationClip } from '../../core/animation/animation-clip';
import type { Skeleton } from '../assets';
import { Device } from '../../core/gfx';
import { JointAnimationInfo, JointTexturePool } from './skeletal-animation-utils';
import { legacyCC } from '../../core/global-exports';
@@ -31,7 +31,7 @@
import { DEBUG } from 'internal:constants';
import { Vec3, Quat, approx } from '../../core/math';
import { Node } from '../../core/scene-graph';
import { RuntimeBinding } from '../../core/animation/tracks/track';
import type { RuntimeBinding } from '../../core/animation/tracks/track';
import { assertIsTrue } from '../../core/data/utils/asserts';
export class BlendStateBuffer {
@@ -32,7 +32,7 @@ import { JSB } from 'internal:constants';
import { Mat4, Quat, Vec3 } from '../../core/math';
import { IAnimInfo, JointAnimationInfo } from './skeletal-animation-utils';
import { Node } from '../../core/scene-graph/node';
import { AnimationClip } from '../../core/animation/animation-clip';
import type { AnimationClip } from '../../core/animation/animation-clip';
import { AnimationState } from '../../core/animation/animation-state';
import { SkeletalAnimation, Socket } from './skeletal-animation';
import { SkelAnimDataHub } from './skeletal-animation-data-hub';
@@ -29,7 +29,7 @@
*/
import { EDITOR, JSB } from 'internal:constants';
import { AnimationClip } from '../../core/animation/animation-clip';
import type { AnimationClip } from '../../core/animation/animation-clip';
import { SkelAnimDataHub } from './skeletal-animation-data-hub';
import { getWorldTransformUntilRoot } from '../../core/animation/transform-utils';
import { Mesh } from '../assets/mesh';
@@ -41,6 +41,7 @@ import { Mat4, Quat, Vec3 } from '../../core/math';
import { UBOSkinningAnimation } from '../../core/pipeline/define';
import { Node } from '../../core/scene-graph';
import { ITextureBufferHandle, TextureBufferPool } from '../../core/renderer/core/texture-buffer-pool';
import { jointTextureSamplerInfo } from '../misc/joint-texture-sampler-info';
// change here and cc-skinning.chunk to use other skinning algorithms
export const uploadJointData = uploadJointDataLBS;
@@ -102,14 +103,7 @@ function roundUpTextureSize (targetLength: number, formatSize: number) {
return Math.ceil(Math.max(MINIMUM_JOINT_TEXTURE_SIZE * formatScale, targetLength) / 12) * 12;
}
export const jointTextureSamplerInfo = new SamplerInfo(
Filter.POINT,
Filter.POINT,
Filter.NONE,
Address.CLAMP,
Address.CLAMP,
Address.CLAMP,
);
export { jointTextureSamplerInfo };
interface IInternalJointAnimInfo {
downstream?: Mat4; // downstream default pose, if present
@@ -41,10 +41,10 @@ import { SkelAnimDataHub } from './skeletal-animation-data-hub';
import { SkeletalAnimationState } from './skeletal-animation-state';
import { getWorldTransformUntilRoot } from '../../core/animation/transform-utils';
import { legacyCC } from '../../core/global-exports';
import { AnimationManager } from '../../core/animation/animation-manager';
import { js } from '../../core/utils/js';
import type { AnimationState } from '../../core/animation/animation-state';
import { assertIsTrue } from '../../core/data/utils/asserts';
import { getGlobalAnimationManager } from '../../core/animation/global-animation-manager';
@ccclass('cc.SkeletalAnimation.Socket')
export class Socket {
@@ -119,7 +119,7 @@ export class SkeletalAnimation extends Animation {
set sockets (val) {
if (!this._useBakedAnimation) {
const animMgr = legacyCC.director.getAnimationManager() as AnimationManager;
const animMgr = getGlobalAnimationManager();
animMgr.removeSockets(this.node, this._sockets);
animMgr.addSockets(this.node, val);
}
@@ -154,9 +154,9 @@ export class SkeletalAnimation extends Animation {
});
if (this._useBakedAnimation) {
(legacyCC.director.getAnimationManager() as AnimationManager).removeSockets(this.node, this._sockets);
getGlobalAnimationManager().removeSockets(this.node, this._sockets);
} else {
(legacyCC.director.getAnimationManager() as AnimationManager).addSockets(this.node, this._sockets);
getGlobalAnimationManager().addSockets(this.node, this._sockets);
this._currentBakedState = null;
}
}
@@ -182,7 +182,7 @@ export class SkeletalAnimation extends Animation {
public onDestroy () {
super.onDestroy();
(legacyCC.director.root.dataPoolManager as DataPoolManager).jointAnimationInfo.destroy(this.node.uuid);
(legacyCC.director.getAnimationManager() as AnimationManager).removeSockets(this.node, this._sockets);
getGlobalAnimationManager().removeSockets(this.node, this._sockets);
this._removeAllUsers();
}
-6
View File
@@ -24,12 +24,6 @@
THE SOFTWARE.
*/
/**
* @packageDocumentation
* @hidden
*/
import '../skeletal-animation/data-pool-manager';
export { SkinnedMeshRenderer } from './skinned-mesh-renderer';
export { SkinnedMeshBatchRenderer, SkinnedMeshUnit } from './skinned-mesh-batch-renderer';
export * from './deprecated';
@@ -31,7 +31,7 @@
import {
ccclass, executeInEditMode, executionOrder, help, menu, tooltip, type,
} from 'cc.decorator';
import { AnimationClip } from '../../core/animation/animation-clip';
import type { AnimationClip } from '../../core/animation/animation-clip';
import { Material } from '../../core/assets';
import { Skeleton } from '../assets/skeleton';
import { Node } from '../../core/scene-graph/node';
+2 -1
View File
@@ -52,6 +52,7 @@ import { ObjectTrack } from './tracks/object-track';
import type { ExoticAnimation } from './exotic-animation/exotic-animation';
import './exotic-animation/exotic-animation';
import { array } from '../utils/js';
import { getGlobalAnimationManager } from './global-animation-manager';
export declare namespace AnimationClip {
export interface IEvent {
@@ -1159,7 +1160,7 @@ class EventEvaluator {
private _doFire (eventIndex: number, delay: boolean) {
if (delay) {
legacyCC.director.getAnimationManager().pushDelayEvent(this._checkAndFire, this, [eventIndex]);
getGlobalAnimationManager().pushDelayEvent(this._checkAndFire, this, [eventIndex]);
} else {
this._checkAndFire(eventIndex);
}
+2 -2
View File
@@ -32,8 +32,8 @@ import { binarySearchEpsilon as binarySearch } from '../algorithm/binary-search'
import { lerp, Quat } from '../math';
import { errorID } from '../platform/debug';
import { ValueType } from '../value-types';
import { bezierByTime, BezierControlPoints } from './bezier';
import * as easing from './easing';
import { bezierByTime, BezierControlPoints } from '../curves/bezier';
import * as easing from '../easing/easing';
import { ILerpable, isLerpable } from './types';
import { legacyCC } from '../global-exports';
import type * as legacy from './legacy-clip-data';
+6 -5
View File
@@ -40,6 +40,7 @@ import { debug } from '../platform/debug';
import { SkeletonMask } from './skeleton-mask';
import { PoseOutput } from './pose-output';
import { BlendStateBuffer } from '../../3d/skeletal-animation/skeletal-animation-blending';
import { getGlobalAnimationManager } from './global-animation-manager';
/**
* @en The event type supported by Animation
@@ -354,7 +355,7 @@ export class AnimationState extends Playable {
}
if (!this._doNotCreateEval) {
const pose = blendStateBuffer ?? legacyCC.director.getAnimationManager()?.blendState ?? null;
const pose = blendStateBuffer ?? getGlobalAnimationManager()?.blendState ?? null;
if (pose) {
this._poseOutput = new PoseOutput(pose);
}
@@ -371,7 +372,7 @@ export class AnimationState extends Playable {
public destroy () {
if (!this.isMotionless) {
legacyCC.director.getAnimationManager().removeAnimation(this);
getGlobalAnimationManager().removeAnimation(this);
}
if (this._poseOutput) {
this._poseOutput.destroy();
@@ -386,7 +387,7 @@ export class AnimationState extends Playable {
* To process animation events, use `Animation` instead.
*/
public emit (...args: any[]) {
legacyCC.director.getAnimationManager().pushDelayEvent(this._emit, this, args);
getGlobalAnimationManager().pushDelayEvent(this._emit, this, args);
}
/**
@@ -684,11 +685,11 @@ export class AnimationState extends Playable {
}
private _onReplayOrResume () {
legacyCC.director.getAnimationManager().addAnimation(this);
getGlobalAnimationManager().addAnimation(this);
}
private _onPauseOrStop () {
legacyCC.director.getAnimationManager().removeAnimation(this);
getGlobalAnimationManager().removeAnimation(this);
}
}
+2 -3
View File
@@ -32,8 +32,7 @@ import { clamp01 } from '../math/utils';
import { remove } from '../utils/array';
import { AnimationState } from './animation-state';
import { Playable } from './playable';
import { legacyCC } from '../global-exports';
import type { AnimationManager } from './animation-manager';
import { getGlobalAnimationManager } from './global-animation-manager';
interface IManagedState {
state: AnimationState | null;
@@ -60,7 +59,7 @@ export class CrossFade extends Playable {
constructor (scheduler?: CrossFadeScheduler) {
super();
this._scheduler = scheduler ?? legacyCC.director.getAnimationManager() as AnimationManager;
this._scheduler = scheduler ?? getGlobalAnimationManager();
}
public update (deltaTime: number) {
@@ -0,0 +1,7 @@
import { legacyCC } from "../global-exports";
import type { AnimationManager } from "./animation-manager";
export function getGlobalAnimationManager() {
const animationManager = legacyCC.director.getAnimationManager() as AnimationManager;
return animationManager;
}
+2 -2
View File
@@ -29,7 +29,7 @@
*/
import { ccclass } from 'cc.decorator';
import * as animation from './animation';
import * as easing from './easing';
import * as easing from '../easing/easing';
import { ComponentPath, HierarchyPath, ICustomTargetPath, TargetPath } from './target-path';
import { IValueProxyFactory } from './value-proxy';
import { UniformProxyFactory } from './value-proxy-factories/uniform';
@@ -38,7 +38,7 @@ import { legacyCC } from '../global-exports';
export * from './deprecated';
legacyCC.easing = easing;
export * from './bezier';
export * from '../curves/bezier';
export { easing };
export * from './animation-curve';
export { AnimationClip } from './animation-clip';
+2 -2
View File
@@ -1,7 +1,7 @@
import { ComponentPath, HierarchyPath, isPropertyPath, TargetPath } from './target-path';
import { IValueProxyFactory } from './value-proxy';
import * as easing from './easing';
import { BezierControlPoints } from './bezier';
import * as easing from '../easing/easing';
import { BezierControlPoints } from '../curves/bezier';
import { CompactValueTypeArray } from '../data/utils/compact-value-type-array';
import { serializable } from '../data/decorators';
import { AnimCurve, RatioSampler } from './animation-curve';
+1 -1
View File
@@ -1,4 +1,4 @@
import * as easing from '../animation/easing';
import * as easing from '../easing/easing';
import { assertIsTrue } from '../data/utils/asserts';
export enum EasingMethod {
+1 -1
View File
@@ -7,7 +7,7 @@ import { ccclass, serializable, uniquelyReferenced } from '../data/decorators';
import { deserializeTag, SerializationContext, SerializationInput, SerializationOutput, serializeTag } from '../data';
import { DeserializationContext } from '../data/custom-serializable';
import { getEasingFn } from './easing-method';
import { bezierByTime } from '../animation/bezier';
import { bezierByTime } from './bezier';
/**
* The method used for interpolation between values of a keyframe and its next keyframe.
+3
View File
@@ -0,0 +1,3 @@
import * as easing from './easing';
export { easing };
+1 -1
View File
@@ -38,7 +38,7 @@ import * as debug from './platform/debug';
import { Device, DeviceInfo, Swapchain, SwapchainInfo } from './gfx';
import { sys } from './platform/sys';
import { macro } from './platform/macro';
import { ICustomJointTextureLayout } from '../3d/skeletal-animation/skeletal-animation-utils';
import type { ICustomJointTextureLayout } from '../3d/skeletal-animation/skeletal-animation-utils';
import { legacyCC, VERSION } from './global-exports';
import { IPhysicsConfig } from '../physics/framework/physics-config';
import { bindingMappingInfo } from './pipeline/define';
-1
View File
@@ -60,5 +60,4 @@ export * from './asset-manager';
export * from './scene-graph';
export * from './components';
export * from './builtin';
export * from './animation';
export * from './curves';
+1 -1
View File
@@ -33,7 +33,7 @@ import { builtinResMgr } from './builtin';
import { Pool } from './memop';
import { RenderPipeline, createDefaultPipeline, DeferredPipeline } from './pipeline';
import { Camera, Light, Model, NativeRoot } from './renderer/scene';
import { DataPoolManager } from '../3d/skeletal-animation/data-pool-manager';
import type { DataPoolManager } from '../3d/skeletal-animation/data-pool-manager';
import { LightType } from './renderer/scene/light';
import { IRenderSceneInfo, RenderScene } from './renderer/scene/render-scene';
import { SphereLight } from './renderer/scene/sphere-light';
+1 -1
View File
@@ -28,7 +28,7 @@
* @hidden
*/
import * as easing from './animation/easing';
import * as easing from './easing/easing';
import { Material } from './assets/material';
import { clamp01 } from './math/utils';
import {
+1 -1
View File
@@ -28,7 +28,7 @@
* @hidden
*/
import { easing } from '../core/animation';
import { easing } from '../core/easing/index';
import { warnID, warn } from '../core';
import { ActionInterval } from './actions/action-interval';
import { ITweenOption } from './export-api';
+18 -1
View File
@@ -27,6 +27,18 @@
}
}
},
"animation": {
"label": "i18n:ENGINE.features.animation.label",
"description": "i18n:ENGINE.features.animation.description",
"default": ["animation"],
"category": "animation"
},
"skeletal-animation": {
"label": "i18n:ENGINE.features.skeletal_animation.label",
"description": "i18n:ENGINE.features.skeletal_animation.description",
"default": ["skeletal-animation"],
"category": "animation"
},
"3d": {
"default": ["3d"],
"label": "i18n:ENGINE.features.base_3d.label",
@@ -184,7 +196,8 @@
"default": ["marionette"],
"label": "Marionette 动画系统",
"description": "启用 Marionette 动画系统。",
"wechatPlugin": false
"wechatPlugin": false,
"category": "animation"
}
},
"categories": {
@@ -195,6 +208,10 @@
"3d": {
"label": "i18n:ENGINE.features.categories.3d.label",
"description": "i18n:ENGINE.features.categories.3d.description"
},
"animation": {
"label": "i18n:ENGINE.features.categories.animation.label",
"description": "i18n:ENGINE.features.categories.animation.description"
}
}
}
+12
View File
@@ -58,6 +58,9 @@
"3d": {
"$ref": "#/definitions/Item"
},
"animation": {
"$ref": "#/definitions/Item"
},
"audio": {
"$ref": "#/definitions/Item"
},
@@ -118,6 +121,9 @@
"profiler": {
"$ref": "#/definitions/Item"
},
"skeletal-animation": {
"$ref": "#/definitions/Item"
},
"spine": {
"$ref": "#/definitions/Item"
},
@@ -193,6 +199,9 @@
"3d": {
"$ref": "#/definitions/BaseItem"
},
"animation": {
"$ref": "#/definitions/BaseItem"
},
"audio": {
"$ref": "#/definitions/BaseItem"
},
@@ -253,6 +262,9 @@
"profiler": {
"$ref": "#/definitions/BaseItem"
},
"skeletal-animation": {
"$ref": "#/definitions/BaseItem"
},
"spine": {
"$ref": "#/definitions/BaseItem"
},
+3 -1
View File
@@ -29,7 +29,9 @@ export type EngineFeature =
| 'dragon-bones'
| 'primitive'
| 'profiler'
| 'marionette';
| 'marionette'
| 'animation'
| 'skeletal-animation';
export interface ModuleRenderConfig {
$schema?: string;
+12
View File
@@ -767,6 +767,10 @@ module.exports = {
label: '3D',
description: '3D',
},
animation: {
label: 'Animation',
description: 'Animation System.',
},
},
core: {
label: "Core",
@@ -884,6 +888,14 @@ module.exports = {
label: "DragonBones",
description: "DragonBones support.",
},
animation: {
label: "Basic Animation",
description: "Basic animation support.",
},
skeletal_animation: {
label: "Skeletal Animation",
description: "Skeletal animation support.",
},
},
renderable_2d: {
srcBlendFactor: 'Specifies the source blend mode, it will clone a new material object.',
+12
View File
@@ -748,6 +748,10 @@ module.exports = {
label: '3D',
description: '3D',
},
animation: {
label: '动画',
description: '动画系统。',
},
},
core: {
label: "核心功能",
@@ -865,6 +869,14 @@ module.exports = {
label: "DragonBones",
description: "DragonBones 支持。",
},
animation: {
label: "基础动画功能",
description: "基础动画功能支持。",
},
skeletal_animation: {
label: "骨骼动画",
description: "骨骼动画支持。",
},
},
renderable_2d: {
srcBlendFactor: '指定源的混合模式,这会克隆一个新的材质对象,注意这带来的性能和内存损耗',
+1
View File
@@ -0,0 +1 @@
export * from '../cocos/core/animation';
+1
View File
@@ -0,0 +1 @@
export * from '../cocos/3d/skeletal-animation';
+10 -4
View File
@@ -52,7 +52,10 @@ gulp.task('build-source', async () => {
});
});
gulp.task('build-h5-source', gulp.series('build-debug-infos', () => {
gulp.task('build-h5-source', gulp.series('build-debug-infos', async () => {
const outDir = ps.join('bin', 'dev', 'cc');
await fs.ensureDir(outDir);
await fs.emptyDir(outDir);
const cli = require.resolve('@cocos/build-engine/dist/cli');
return cp.spawn('node', [
cli,
@@ -61,7 +64,7 @@ gulp.task('build-h5-source', gulp.series('build-debug-infos', () => {
'--build-mode=BUILD',
'--platform=HTML5',
'--physics=cannon',
'--out=./bin/dev/cc',
`--out=${outDir}`,
], {
shell: true,
stdio: 'inherit',
@@ -69,7 +72,10 @@ gulp.task('build-h5-source', gulp.series('build-debug-infos', () => {
});
}));
gulp.task('build-h5-minified', gulp.series('build-debug-infos', () => {
gulp.task('build-h5-minified', gulp.series('build-debug-infos', async () => {
const outDir = ps.join('bin', 'dev', 'cc-min');
await fs.ensureDir(outDir);
await fs.emptyDir(outDir);
const cli = require.resolve('@cocos/build-engine/dist/cli');
return cp.spawn('node', [
cli,
@@ -80,7 +86,7 @@ gulp.task('build-h5-minified', gulp.series('build-debug-infos', () => {
'--build-mode=BUILD',
'--platform=HTML5',
'--physics=cannon',
'--out=./bin/dev/cc-min',
`--out=${outDir}`,
], {
shell: true,
stdio: 'inherit',
+1 -1
View File
@@ -1,4 +1,4 @@
import { AnimationClip } from '../../cocos/core';
import { AnimationClip } from '../../cocos/core/animation/animation-clip';
import { Animation } from '../../cocos/core/animation/animation-component';
describe('Animation Component', () => {
+2 -1
View File
@@ -1,5 +1,5 @@
import { AnimationClip, Component, Node, Vec2, Vec3, warnID } from '../../cocos/core';
import { Component, Node, Vec2, Vec3, warnID } from '../../cocos/core';
import { AnimationBlend1D, AnimationBlend2D, Condition, InvalidTransitionError, VariableNotDefinedError, __getDemoGraphs, ClipMotion, AnimationBlendDirect, VariableType } from '../../cocos/core/animation/marionette/asset-creation';
import { LayerBlending, AnimationGraph, StateMachine, Transition, isAnimationTransition, AnimationTransition } from '../../cocos/core/animation/marionette/animation-graph';
import { createEval } from '../../cocos/core/animation/marionette/create-eval';
@@ -22,6 +22,7 @@ import { AnimationController } from '../../cocos/core/animation/marionette/anima
import { StateMachineComponent } from '../../cocos/core/animation/marionette/state-machine-component';
import { VectorTrack } from '../../cocos/core/animation/animation';
import 'jest-extended';
import { AnimationClip } from '../../cocos/core/animation/animation-clip';
describe('NewGen Anim', () => {
const demoGraphs = __getDemoGraphs();
+1
View File
@@ -64,6 +64,7 @@ import { game, IGameConfig } from '../exports/base';
import './asset-manager/init';
import '../cocos/core/gfx/empty/empty-device';
import '../cocos/3d/skeletal-animation/data-pool-manager';
import '../cocos/core/animation';
const canvas = document.createElement('canvas');
const div = document.createElement('div');
+5
View File
@@ -1,3 +1,8 @@
// @ts-ignore
import * as matchers from 'jest-extended';
expect.extend(matchers);
const testPath = expect.getState().testPath;
if (testPath.match(/animation/)) {
require('../cocos/core/animation');
}