mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-03 17:42:41 +08:00
fix anim bounds & shader compiling (#6106)
This commit is contained in:
@@ -29,23 +29,11 @@
|
||||
|
||||
import { ccclass, property } from '../../core/data/class-decorator';
|
||||
import { CCString } from '../../core/data/utils/attribute';
|
||||
import { Mat4, Quat, Vec3 } from '../../core/math';
|
||||
import { Mat4 } from '../../core/math';
|
||||
import { murmurhash2_32_gc } from '../../core/utils/murmurhash2_gc';
|
||||
import { aabb } from '../geom-utils';
|
||||
import { DataPoolManager } from '../renderer/data-pool-manager';
|
||||
import { Asset } from './asset';
|
||||
|
||||
export interface IBindTRS {
|
||||
position: Vec3;
|
||||
rotation: Quat;
|
||||
scale: Vec3;
|
||||
}
|
||||
|
||||
const m4_1 = new Mat4();
|
||||
const v3_1 = new Vec3();
|
||||
const v3_min = new Vec3();
|
||||
const v3_max = new Vec3();
|
||||
|
||||
/**
|
||||
* 骨骼资源。
|
||||
* 骨骼资源记录了每个关节(相对于`SkinningModelComponent.skinningRoot`)的路径以及它的绑定姿势矩阵。
|
||||
@@ -60,7 +48,6 @@ export class Skeleton extends Asset {
|
||||
private _bindposes: Mat4[] = [];
|
||||
|
||||
private _hash = 0;
|
||||
private _bounds = new aabb();
|
||||
|
||||
/**
|
||||
* 所有关节的绑定姿势矩阵。该数组的长度始终与 `this.joints` 的长度相同。
|
||||
@@ -72,8 +59,6 @@ export class Skeleton extends Asset {
|
||||
set bindposes (value) {
|
||||
this._bindposes = value;
|
||||
let str = '';
|
||||
Vec3.set(v3_min, Infinity, Infinity, Infinity);
|
||||
Vec3.set(v3_max, -Infinity, -Infinity, -Infinity);
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const ibm = value[i];
|
||||
str +=
|
||||
@@ -81,13 +66,8 @@ export class Skeleton extends Asset {
|
||||
ibm.m04.toPrecision(2) + ' ' + ibm.m05.toPrecision(2) + ' ' + ibm.m06.toPrecision(2) + ' ' + ibm.m07.toPrecision(2) + ' ' +
|
||||
ibm.m08.toPrecision(2) + ' ' + ibm.m09.toPrecision(2) + ' ' + ibm.m10.toPrecision(2) + ' ' + ibm.m11.toPrecision(2) + ' ' +
|
||||
ibm.m12.toPrecision(2) + ' ' + ibm.m13.toPrecision(2) + ' ' + ibm.m14.toPrecision(2) + ' ' + ibm.m15.toPrecision(2) + '\n';
|
||||
Mat4.invert(m4_1, ibm);
|
||||
Vec3.set(v3_1, m4_1.m12, m4_1.m13, m4_1.m14);
|
||||
Vec3.min(v3_min, v3_min, v3_1);
|
||||
Vec3.max(v3_max, v3_max, v3_1);
|
||||
}
|
||||
this._hash = murmurhash2_32_gc(str, 666);
|
||||
aabb.fromPoints(this._bounds, v3_min, v3_max);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,10 +85,6 @@ export class Skeleton extends Asset {
|
||||
return this._hash;
|
||||
}
|
||||
|
||||
get bounds () {
|
||||
return this._bounds;
|
||||
}
|
||||
|
||||
public onLoaded () {
|
||||
this.bindposes = this._bindposes;
|
||||
}
|
||||
|
||||
@@ -391,6 +391,10 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
} else if ((sys.platform !== sys.WECHAT_GAME || sys.os !== sys.OS_IOS)) { this._useVAO = true; }
|
||||
}
|
||||
|
||||
if ((sys.platform === sys.WECHAT_GAME && sys.os === sys.OS_ANDROID)) {
|
||||
gl.detachShader = () => {}; // Android WeChat may throw errors on detach shader
|
||||
}
|
||||
|
||||
if (this._OES_element_index_uint) {
|
||||
this._features[GFXFeature.ELEMENT_INDEX_UINT] = true;
|
||||
}
|
||||
|
||||
@@ -326,10 +326,10 @@ const ab_1 = new aabb();
|
||||
|
||||
export class AnimatedBoundsInfo {
|
||||
private _perJointBoundsPool = new Map<number, Map<number, Array<aabb | null>>>(); // per Mesh per Skeleton
|
||||
private _fullClipBoundsPool = new Map<number, Map<number, aabb[]>>(); // per Skeleton per AnimationClip
|
||||
private _fullClipBoundsPool = new Map<number, Map<number, Map<number, aabb[]>>>(); // per Mesh per Skeleton per AnimationClip
|
||||
|
||||
public get (mesh: Mesh, skeleton: Skeleton, clip: AnimationClip) {
|
||||
const list: aabb[] = this._getFullClipBounds(skeleton, clip) || [];
|
||||
const list: aabb[] = this._getFullClipBounds(mesh, skeleton, clip) || [];
|
||||
if (list.length) { return list; }
|
||||
let perJointBounds = this._getPerJointBounds(mesh, skeleton);
|
||||
if (!perJointBounds) {
|
||||
@@ -361,7 +361,7 @@ export class AnimatedBoundsInfo {
|
||||
const { center, halfExtents } = list[fid];
|
||||
aabb.fromPoints(list[fid], center, halfExtents);
|
||||
}
|
||||
this._setFullClipBounds(skeleton, clip, list);
|
||||
this._setFullClipBounds(mesh, skeleton, clip, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -408,23 +408,34 @@ export class AnimatedBoundsInfo {
|
||||
|
||||
public releaseMesh (mesh: Mesh) {
|
||||
this._perJointBoundsPool.delete(mesh.hash);
|
||||
this._fullClipBoundsPool.delete(mesh.hash);
|
||||
}
|
||||
|
||||
public releaseSkeleton (skeleton: Skeleton) {
|
||||
const it = this._perJointBoundsPool.values();
|
||||
let res = it.next();
|
||||
while (!res.done) {
|
||||
res.value.delete(skeleton.hash);
|
||||
res = it.next();
|
||||
const it1 = this._perJointBoundsPool.values();
|
||||
let res1 = it1.next();
|
||||
while (!res1.done) {
|
||||
res1.value.delete(skeleton.hash);
|
||||
res1 = it1.next();
|
||||
}
|
||||
const it2 = this._fullClipBoundsPool.values();
|
||||
let res2 = it2.next();
|
||||
while (!res2.done) {
|
||||
res2.value.delete(skeleton.hash);
|
||||
res2 = it2.next();
|
||||
}
|
||||
this._fullClipBoundsPool.delete(skeleton.hash);
|
||||
}
|
||||
|
||||
public releaseAnimationClip (clip: AnimationClip) {
|
||||
const it = this._fullClipBoundsPool.values();
|
||||
let res = it.next();
|
||||
while (!res.done) {
|
||||
res.value.delete(clip.hash);
|
||||
const it2 = res.value.values();
|
||||
let res2 = it2.next();
|
||||
while (!res2.done) {
|
||||
res2.value.delete(clip.hash);
|
||||
res2 = it2.next();
|
||||
}
|
||||
res = it.next();
|
||||
}
|
||||
}
|
||||
@@ -434,9 +445,10 @@ export class AnimatedBoundsInfo {
|
||||
return m && m.get(skeleton.hash);
|
||||
}
|
||||
|
||||
private _getFullClipBounds (skeleton: Skeleton, clip: AnimationClip) {
|
||||
const m = this._fullClipBoundsPool.get(skeleton.hash);
|
||||
return m && m.get(clip.hash);
|
||||
private _getFullClipBounds (mesh: Mesh, skeleton: Skeleton, clip: AnimationClip) {
|
||||
const m = this._fullClipBoundsPool.get(mesh.hash);
|
||||
const s = m && m.get(skeleton.hash);
|
||||
return s && s.get(clip.hash);
|
||||
}
|
||||
|
||||
private _setPerJointBounds (mesh: Mesh, skeleton: Skeleton, bounds: Array<aabb | null>) {
|
||||
@@ -445,9 +457,11 @@ export class AnimatedBoundsInfo {
|
||||
m.set(skeleton.hash, bounds);
|
||||
}
|
||||
|
||||
private _setFullClipBounds (skeleton: Skeleton, clip: AnimationClip, bounds: aabb[]) {
|
||||
let m = this._fullClipBoundsPool.get(skeleton.hash);
|
||||
if (!m) { m = new Map<number, aabb[]>(); this._fullClipBoundsPool.set(skeleton.hash, m); }
|
||||
m.set(clip.hash, bounds);
|
||||
private _setFullClipBounds (mesh: Mesh, skeleton: Skeleton, clip: AnimationClip, bounds: aabb[]) {
|
||||
let m = this._fullClipBoundsPool.get(mesh.hash);
|
||||
if (!m) { m = new Map<number, Map<number, aabb[]>>(); this._fullClipBoundsPool.set(mesh.hash, m); }
|
||||
let s = m.get(skeleton.hash);
|
||||
if (!s) { s = new Map<number, aabb[]>(); m.set(skeleton.hash, s); }
|
||||
s.set(clip.hash, bounds);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user