Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add:增加3D动画的boolean类型 #1715

Open
wants to merge 2 commits into
base: Master3.0
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion bin/sample-resource
Submodule sample-resource updated from a61b0c to 8e103d
4 changes: 3 additions & 1 deletion src/layaAir/laya/ModuleDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ import { PolygonPoint2D } from "./display/Scene2DSpecial/Light2D/PolygonPoint2D"
import { Gradient } from "./maths/Gradient";
import { FloatKeyframe } from "./maths/FloatKeyframe";
import { Line2DRender } from "./display/Scene2DSpecial/Line2D/Line2DRender";
import { Area2D } from "./display/Area2D";
import { Trail2DRender } from "./display/Scene2DSpecial/Trail2D/Trail2DRender";
import { BooleanKeyframe } from "./maths/BooleanKeyframe";

let c = ClassUtils.regClass;
c("Record", Object);
Expand Down Expand Up @@ -119,6 +120,7 @@ c("BaseRenderNode2D", BaseRenderNode2D);
c("Mesh2D", Mesh2D);
c("Gradient", Gradient);
c("FloatKeyframe", FloatKeyframe);
c("BooleanKeyframe", BooleanKeyframe);

c("BaseLight2D", BaseLight2D);
c("DirectionLight2D", DirectionLight2D);
Expand Down
10 changes: 9 additions & 1 deletion src/layaAir/laya/d3/animation/AnimationClip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { QuaternionKeyframe } from "../../maths/QuaternionKeyframe";
import { Vector2Keyframe } from "../../maths/Vector2Keyframe";
import { Vector3Keyframe } from "../../maths/Vector3Keyframe";
import { Vector4Keyframe } from "../../maths/Vector4Keyframe";
import { BooleanKeyframe } from "../../maths/BooleanKeyframe";

/**
* @en The AnimationClip class is used for animation clip resources.
Expand Down Expand Up @@ -430,7 +431,7 @@ export class AnimationClip extends Resource {
* @param frontPlay 是否是前向播放。
* @param outDatas 计算好的动画数据。
*/
_evaluateClipDatasRealTime(nodes: KeyframeNodeList, playCurTime: number, realTimeCurrentFrameIndexes: Int16Array, addtive: boolean, frontPlay: boolean, outDatas: Array<number | Vector3 | Quaternion | Vector4 | Vector2>, avatarMask: AvatarMask): void {
_evaluateClipDatasRealTime(nodes: KeyframeNodeList, playCurTime: number, realTimeCurrentFrameIndexes: Int16Array, addtive: boolean, frontPlay: boolean, outDatas: Array<boolean | number | Vector3 | Quaternion | Vector4 | Vector2>, avatarMask: AvatarMask): void {
for (var i = 0, n = nodes.count; i < n; i++) {
var node = nodes.getNodeByIndex(i);
var type = node.type;
Expand Down Expand Up @@ -474,6 +475,13 @@ export class AnimationClip extends Resource {

var isEnd = nextFrameIndex === keyFramesCount;
switch (type) {
case KeyFrameValueType.Boolean:
if (frameIndex !== -1) {
outDatas[i] = (<BooleanKeyframe>keyFrames[frameIndex]).value;
} else {
outDatas[i] = (<BooleanKeyframe>keyFrames[0]).value;
}
break;
case KeyFrameValueType.Float:
if (frameIndex !== -1) {
var frame = (<FloatKeyframe>keyFrames[frameIndex]);
Expand Down
7 changes: 7 additions & 0 deletions src/layaAir/laya/d3/animation/AnimationClipParser04.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { QuaternionKeyframe } from "../../maths/QuaternionKeyframe";
import { Vector2Keyframe } from "../../maths/Vector2Keyframe";
import { Vector3Keyframe } from "../../maths/Vector3Keyframe";
import { Vector4Keyframe } from "../../maths/Vector4Keyframe";
import { BooleanKeyframe } from "../../maths/BooleanKeyframe";

/**
* @internal
Expand Down Expand Up @@ -260,6 +261,12 @@ export class AnimationClipParser04 {
for (j = 0; j < keyframeCount; j++) {
let isWeight = 1;
switch (type) {
case KeyFrameValueType.Boolean:
let booleanKeyframe = new BooleanKeyframe();
node._setKeyframeByIndex(j, booleanKeyframe);
booleanKeyframe.time = startTimeTypes[reader.getUint16()];
booleanKeyframe.value = reader.getByte() == 1;
break;
case KeyFrameValueType.Float:
var floatKeyframe: FloatKeyframe = new FloatKeyframe();
node._setKeyframeByIndex(j, floatKeyframe);
Expand Down
21 changes: 20 additions & 1 deletion src/layaAir/laya/d3/component/Animator/Animator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class Animator extends Component {
keyframeNodeOwner.type = node.type;

if (property) {//查询成功后赋默认值
if (node.type === 0) {
if (node.type === KeyFrameValueType.Float || node.type === KeyFrameValueType.Boolean) {
keyframeNodeOwner.defaultValue = property;
} else {
var defaultValue = new property.constructor();
Expand Down Expand Up @@ -740,6 +740,9 @@ export class Animator extends Component {
let lastpro;
if (pro) {
switch (nodeOwner.type) {
case KeyFrameValueType.Boolean:
console.log("Animator:Boolean not support3");
break;
case KeyFrameValueType.Float: //Float
var proPat: string[] = nodeOwner.property!;
var m: number = proPat.length - 1;
Expand Down Expand Up @@ -915,6 +918,19 @@ export class Animator extends Component {
let value: string;
if (pro) {
switch (nodeOwner.type) {
case KeyFrameValueType.Boolean:
var proPat: string[] = nodeOwner.property!;
var m: number = proPat.length - 1;
for (var j: number = 0; j < m; j++) {
pro = pro[proPat[j]];
if (!pro)//属性可能或被置空
break;
}
let lastBoolPro = proPat[m];
if (!nodeOwner.isMaterial) {
pro && (pro[lastBoolPro] = realtimeDatas[i])
}
break;
case KeyFrameValueType.Float: //Float
var proPat: string[] = nodeOwner.property!;
var m: number = proPat.length - 1;
Expand Down Expand Up @@ -1110,6 +1126,9 @@ export class Animator extends Component {
let value: string;
if (pro) {
switch (nodeOwner.type) {
case KeyFrameValueType.Boolean:
console.log("Animator:Boolean not support2");
break;
case KeyFrameValueType.Float:
var proPat: string[] = nodeOwner.property!;
var m: number = proPat.length - 1;
Expand Down
1 change: 1 addition & 0 deletions src/layaAir/laya/d3/component/Animator/AnimatorState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class AnimatorState extends EventDispatcher implements IClone {
this._realtimeDatas.length = count;
for (var i: number = 0; i < count; i++) {
switch (clipNodes.getNodeByIndex(i).type) {
case KeyFrameValueType.Boolean:
case KeyFrameValueType.Float:
break;
case KeyFrameValueType.Position:
Expand Down
3 changes: 2 additions & 1 deletion src/layaAir/laya/d3/component/Animator/KeyframeNodeOwner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export enum KeyFrameValueType {
Vector2 = 5,
Vector3 = 6,
Vector4 = 7,
Color = 8
Color = 8,
Boolean = 9,
}
/**
* @internal
Expand Down
31 changes: 31 additions & 0 deletions src/layaAir/laya/maths/BooleanKeyframe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Keyframe } from "./Keyframe";
export class BooleanKeyframe extends Keyframe {
/**
* @en The value of the keyframe.
* @zh 关键帧的值。
*/
value: boolean;

/**
* @inheritDoc
* @override
* @en Clones the data to another object.
* @param destObject The target object to clone to.
* @zh 克隆数据到目标对象。
* @param destObject 拷贝数据结构
*/
cloneTo(destObject: BooleanKeyframe): void {
super.cloneTo(destObject);;
destObject.value = this.value;
}

/**
* @en Clones.
* @zh 克隆
*/
clone(): BooleanKeyframe {
let f = new BooleanKeyframe();
this.cloneTo(f);
return f;
}
}