mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
skeletal bounds (#4891)
This commit is contained in:
committed by
Weiliang Wang
parent
6aab2566b4
commit
24fc221fee
+35
-21
@@ -1,7 +1,7 @@
|
||||
import { GFXAttributeName, GFXFormat, GFXFormatInfos, GFXFormatType, GFXPrimitiveMode, IGFXFormatInfo } from '../../gfx/define';
|
||||
export { find } from '../../scene-graph/find';
|
||||
import { Mat4, Vec3 } from '../../core/value-types';
|
||||
import { vec3 } from '../../core/vmath';
|
||||
import { mat4, vec3 } from '../../core/vmath';
|
||||
import { IGFXAttribute } from '../../gfx/input-assembler';
|
||||
import { Node } from '../../scene-graph';
|
||||
import { IMeshStruct, IPrimitive, IVertexBundle, Mesh } from '../assets/mesh';
|
||||
@@ -450,28 +450,42 @@ class BoneSpaceBoundsManager {
|
||||
}
|
||||
const boneSpaceBoundsManager = new BoneSpaceBoundsManager();
|
||||
const m4_1 = new Mat4();
|
||||
const m4_2 = new Mat4();
|
||||
const ab_1 = new aabb();
|
||||
const v3_3 = new Vec3();
|
||||
const v3_4 = new Vec3();
|
||||
export function calculateSkinnedBounds (out: aabb, comp: SkinningModelComponent) {
|
||||
if (!comp.model || !comp.mesh || !comp.skeleton) { return; }
|
||||
// const mesh = comp.mesh;
|
||||
// const skeleton = comp.skeleton;
|
||||
// const joints = comp.model.joints;
|
||||
// vec3.set(v3_3, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);
|
||||
// vec3.set(v3_4, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY);
|
||||
// const boundList = boneSpaceBoundsManager.use(mesh, skeleton);
|
||||
// const len = joints.length;
|
||||
// for (let i = 0; i < len; ++i) {
|
||||
// const bounds = boundList[i];
|
||||
// const targetNode = joints[i].node;
|
||||
// if (!bounds || !targetNode) { continue; }
|
||||
// targetNode.getWorldMatrix(m4_1);
|
||||
// aabb.transform(ab_1, bounds, m4_1);
|
||||
// ab_1.getBoundary(v3_1, v3_2);
|
||||
// vec3.min(v3_3, v3_3, v3_1);
|
||||
// vec3.max(v3_4, v3_4, v3_2);
|
||||
// }
|
||||
// aabb.fromPoints(out, v3_3, v3_4);
|
||||
// return true;
|
||||
if (!comp.model || !comp.mesh) { return; }
|
||||
const mesh = comp.mesh;
|
||||
const skeleton = comp.skeleton;
|
||||
const clip = comp.model.uploadedClip;
|
||||
const root = comp.skinningRoot;
|
||||
if (!skeleton || !root || !clip) {
|
||||
if (!comp.model.worldBounds) { return; }
|
||||
aabb.copy(out, comp.model.worldBounds);
|
||||
return true;
|
||||
}
|
||||
vec3.set(v3_3, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);
|
||||
vec3.set(v3_4, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY);
|
||||
root.getWorldMatrix(m4_1);
|
||||
const boundList = boneSpaceBoundsManager.use(mesh, skeleton);
|
||||
const len = skeleton.joints.length;
|
||||
const data = clip.convertedData;
|
||||
const fid = comp.model.getFrameID();
|
||||
for (let i = 0; i < len; ++i) {
|
||||
const bounds = boundList[i];
|
||||
const nodeData = data[skeleton.joints[i]];
|
||||
if (!bounds || !nodeData || !nodeData.props) { continue; }
|
||||
const position = nodeData.props.position.values[fid];
|
||||
const rotation = nodeData.props.rotation.values[fid];
|
||||
const scale = nodeData.props.scale.values[fid];
|
||||
mat4.fromRTS(m4_2, rotation, position, scale);
|
||||
mat4.multiply(m4_2, m4_1, m4_2);
|
||||
aabb.transform(ab_1, bounds, m4_2);
|
||||
ab_1.getBoundary(v3_1, v3_2);
|
||||
vec3.min(v3_3, v3_3, v3_1);
|
||||
vec3.max(v3_4, v3_4, v3_2);
|
||||
}
|
||||
aabb.fromPoints(out, v3_3, v3_4);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
* @category animation
|
||||
*/
|
||||
|
||||
import { IBindTRS } from '../3d/assets/skeleton';
|
||||
import { SkinningModelComponent } from '../3d/framework/skinning-model-component';
|
||||
import { ccclass, property } from '../core/data/class-decorator';
|
||||
import { ccclass } from '../core/data/class-decorator';
|
||||
import { quat, vec3 } from '../core/vmath';
|
||||
import { Node } from '../scene-graph';
|
||||
import { AnimationClip, ICurveData, IObjectCurveData, IPropertyCurve } from './animation-clip';
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
import { AnimationClip, AnimationState } from '../animation';
|
||||
import { CrossFade } from '../animation/cross-fade';
|
||||
import { Playable } from '../animation/playable';
|
||||
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../core/data/class-decorator';
|
||||
import { Event, EventTarget } from '../core/event';
|
||||
import { CallbacksInvoker, ICallbackTable } from '../core/event/callbacks-invoker';
|
||||
|
||||
@@ -48,6 +48,8 @@ interface IJointsInfo {
|
||||
|
||||
export class SkinningModel extends Model {
|
||||
|
||||
public uploadedClip: SkeletalAnimationClip | null = null;
|
||||
|
||||
private _jointsMedium: IJointsInfo;
|
||||
private _skeleton: Skeleton | null = null;
|
||||
|
||||
@@ -81,6 +83,7 @@ export class SkinningModel extends Model {
|
||||
public uploadAnimationClip (clip: SkeletalAnimationClip) {
|
||||
if (!this._skeleton) { return; }
|
||||
this._applyJointTexture(this._skeleton.getJointsTexture(this._device, clip));
|
||||
if (this._jointsMedium) { this.uploadedClip = clip; }
|
||||
}
|
||||
|
||||
public setFrameID (val: number) {
|
||||
|
||||
Reference in New Issue
Block a user