fix skinning model type when not enabled immediately (#6542)

* fix skinning model type update

* unbatch util

* camera property display order

* fix model type order
This commit is contained in:
Yun Hsiao Wu
2020-04-14 12:47:58 +08:00
committed by GitHub
parent ec34f5970b
commit 3bedccdeaa
9 changed files with 251 additions and 188 deletions
+139 -123
View File
@@ -124,23 +124,6 @@ export class CameraComponent extends Component {
return this._camera!;
}
/**
* @en Projection type of the camera.
* @zh 相机的投影类型。
*/
@property({
type: ProjectionType,
tooltip: 'i18n:camera.projection',
})
get projection () {
return this._projection;
}
set projection (val) {
this._projection = val;
if (this._camera) { this._camera.projectionType = val; }
}
/**
* @en
* Render priority of the camera, should be statically set in editor.<br>
@@ -149,6 +132,7 @@ export class CameraComponent extends Component {
*/
@property({
tooltip: 'i18n:camera.priority',
displayOrder: 0,
})
get priority () {
return this._priority;
@@ -161,6 +145,120 @@ export class CameraComponent extends Component {
}
}
/**
* @en Visibility mask of the camera, based on what layer the target node is in,
* to filter out the models that don't need to render for this camera.
* @zh 相机可见性掩码,对应模型所在节点的 layer 信息,用于过滤相机不需要渲染的物体。
*/
@property({
type: Layers.BitMask,
tooltip: 'i18n:camera.visibility',
displayOrder: 1,
})
get visibility () {
return this._visibility;
}
set visibility (val) {
this._visibility = val;
if (this._camera) {
this._camera.visibility = val;
}
}
/**
* @en Clearing flags of the camera, specifies which part of the framebuffer will be actually cleared every frame.
* @zh 相机的缓冲清除标志位,指定帧缓冲的哪部分要每帧清除。
*/
@property({
type: ClearFlag,
tooltip: 'i18n:camera.clear_flags',
displayOrder: 2,
})
get clearFlags () {
return this._clearFlags;
}
set clearFlags (val) {
this._clearFlags = val;
if (this._camera) { this._camera.clearFlag = val; }
}
/**
* @en Clearing color of the camera.
* @zh 相机的颜色缓冲默认值。
*/
@property({
tooltip: 'i18n:camera.color',
displayOrder: 3,
})
// @constget
get clearColor (): Readonly<Color> {
return this._color;
}
set clearColor (val) {
this._color.set(val);
if (this._camera) {
this._camera.clearColor.r = this._color.x;
this._camera.clearColor.g = this._color.y;
this._camera.clearColor.b = this._color.z;
this._camera.clearColor.a = this._color.w;
}
}
/**
* @en Clearing depth of the camera.
* @zh 相机的深度缓冲默认值。
*/
@property({
tooltip: 'i18n:camera.depth',
displayOrder: 4,
})
get clearDepth () {
return this._depth;
}
set clearDepth (val) {
this._depth = val;
if (this._camera) { this._camera.clearDepth = val; }
}
/**
* @en Clearing stencil of the camera.
* @zh 相机的模板缓冲默认值。
*/
@property({
tooltip: 'i18n:camera.stencil',
displayOrder: 5,
})
get clearStencil () {
return this._stencil;
}
set clearStencil (val) {
this._stencil = val;
if (this._camera) { this._camera.clearStencil = val; }
}
/**
* @en Projection type of the camera.
* @zh 相机的投影类型。
*/
@property({
type: ProjectionType,
tooltip: 'i18n:camera.projection',
displayOrder: 6,
})
get projection () {
return this._projection;
}
set projection (val) {
this._projection = val;
if (this._camera) { this._camera.projectionType = val; }
}
/**
* @en Axis of the field of view of the camera.
* @zh 相机的视角轴。
@@ -168,6 +266,7 @@ export class CameraComponent extends Component {
@property({
type: FOVAxis,
tooltip: 'i18n:camera.fov_axis',
displayOrder: 7,
})
get fovAxis () {
return this._fovAxis;
@@ -189,6 +288,7 @@ export class CameraComponent extends Component {
*/
@property({
tooltip: 'i18n:camera.fov',
displayOrder: 8,
})
get fov () {
return this._fov;
@@ -205,6 +305,7 @@ export class CameraComponent extends Component {
*/
@property({
tooltip: 'i18n:camera.ortho_height',
displayOrder: 9,
})
get orthoHeight () {
return this._orthoHeight;
@@ -221,6 +322,7 @@ export class CameraComponent extends Component {
*/
@property({
tooltip: 'i18n:camera.near',
displayOrder: 10,
})
get near () {
return this._near;
@@ -237,6 +339,7 @@ export class CameraComponent extends Component {
*/
@property({
tooltip: 'i18n:camera.far',
displayOrder: 11,
})
get far () {
return this._far;
@@ -247,83 +350,13 @@ export class CameraComponent extends Component {
if (this._camera) { this._camera.farClip = val; }
}
/**
* @en Clearing color of the camera.
* @zh 相机的颜色缓冲默认值。
*/
@property({
tooltip: 'i18n:camera.color',
})
// @constget
get color (): Readonly<Color> {
return this._color;
}
set color (val) {
this._color.set(val);
if (this._camera) {
this._camera.clearColor.r = this._color.x;
this._camera.clearColor.g = this._color.y;
this._camera.clearColor.b = this._color.z;
this._camera.clearColor.a = this._color.w;
}
}
/**
* @en Clearing depth of the camera.
* @zh 相机的深度缓冲默认值。
*/
@property({
tooltip: 'i18n:camera.depth',
})
get depth () {
return this._depth;
}
set depth (val) {
this._depth = val;
if (this._camera) { this._camera.clearDepth = val; }
}
/**
* @en Clearing stencil of the camera.
* @zh 相机的模板缓冲默认值。
*/
@property({
tooltip: 'i18n:camera.stencil',
})
get stencil () {
return this._stencil;
}
set stencil (val) {
this._stencil = val;
if (this._camera) { this._camera.clearStencil = val; }
}
/**
* @en Clearing flags of the camera, specifies which part of the framebuffer will be actually cleared every frame.
* @zh 相机的缓冲清除标志位,指定帧缓冲的哪部分要每帧清除。
*/
@property({
type: ClearFlag,
tooltip: 'i18n:camera.clear_flags',
})
get clearFlags () {
return this._clearFlags;
}
set clearFlags (val) {
this._clearFlags = val;
if (this._camera) { this._camera.clearFlag = val; }
}
/**
* @en Screen viewport of the camera wrt. the sceen size.
* @zh 相机相对屏幕的 viewport。
*/
@property({
tooltip: 'i18n:camera.rect',
displayOrder: 12,
})
get rect () {
return this._rect;
@@ -341,6 +374,7 @@ export class CameraComponent extends Component {
@property({
type: Aperture,
tooltip: 'i18n:camera.aperture',
displayOrder: 13,
})
get aperture () {
return this._aperture;
@@ -358,6 +392,7 @@ export class CameraComponent extends Component {
@property({
type: Shutter,
tooltip: 'i18n:camera.shutter',
displayOrder: 14,
})
get shutter () {
return this._shutter;
@@ -375,6 +410,7 @@ export class CameraComponent extends Component {
@property({
type: ISO,
tooltip: 'i18n:camera.ISO',
displayOrder: 15,
})
get iso () {
return this._iso;
@@ -385,41 +421,6 @@ export class CameraComponent extends Component {
if (this._camera) { this._camera.iso = val; }
}
/**
* @en Scale of the internal buffer size,
* set to 1 to keep the same with the canvas size.
* @zh 相机内部缓冲尺寸的缩放值, 1 为与 canvas 尺寸相同。
*/
@property({ visible: false })
get screenScale () {
return this._screenScale;
}
set screenScale (val) {
this._screenScale = val;
if (this._camera) { this._camera.screenScale = val; }
}
/**
* @en Visibility mask of the camera, based on what layer the target node is in,
* to filter out the models that don't need to render for this camera.
* @zh 相机可见性掩码,对应模型所在节点的 layer 信息,用于过滤相机不需要渲染的物体。
*/
@property({
type: Layers.BitMask,
tooltip: 'i18n:camera.visibility',
})
get visibility () {
return this._visibility;
}
set visibility (val) {
this._visibility = val;
if (this._camera) {
this._camera.visibility = val;
}
}
/**
* @en Output render texture of the camera. Output directly to screen if not specified.
* @zh 相机的输出 RenderTexture,如未指定会直接输出到主屏幕。
@@ -427,6 +428,7 @@ export class CameraComponent extends Component {
@property({
type: RenderTexture,
tooltip: 'i18n:camera.target_texture',
displayOrder: 16,
})
get targetTexture () {
return this._targetTexture;
@@ -448,6 +450,20 @@ export class CameraComponent extends Component {
}
}
/**
* @en Scale of the internal buffer size,
* set to 1 to keep the same with the canvas size.
* @zh 相机内部缓冲尺寸的缩放值, 1 为与 canvas 尺寸相同。
*/
get screenScale () {
return this._screenScale;
}
set screenScale (val) {
this._screenScale = val;
if (this._camera) { this._camera.screenScale = val; }
}
get inEditorMode () {
return this._inEditorMode;
}
@@ -54,25 +54,25 @@ export class EditorCameraComponent extends CameraComponent {
}
}
set color (val) {
set clearColor (val) {
// @ts-ignore
super.color = val;
super.clearColor = val;
if (this._uiEditorCamera) {
this._uiEditorCamera.clearColor = val;
}
}
set depth (val) {
set clearDepth (val) {
// @ts-ignore
super.depth = val;
super.clearDepth = val;
if (this._uiEditorCamera) {
this._uiEditorCamera.clearDepth = val;
}
}
set stencil (val) {
set clearStencil (val) {
// @ts-ignore
super.stencil = val;
super.clearStencil = val;
if (this._uiEditorCamera) {
this._uiEditorCamera.clearStencil = val;
}
+1 -3
View File
@@ -418,9 +418,7 @@ export class ModelComponent extends RenderableComponent {
if (!subMeshMorph) {
continue;
}
const initialWeights =
subMeshMorph.weights ||
(morph.weights && morph.weights.length === subMeshMorph.targets.length, morph.weights);
const initialWeights = subMeshMorph.weights || morph.weights;
const weights = initialWeights ?
initialWeights.slice() :
new Array<number>(subMeshMorph.targets.length).fill(0);
@@ -35,6 +35,7 @@ import { BakedSkinningModel } from '../../renderer/models/baked-skinning-model';
import { SkinningModel } from '../../renderer/models/skinning-model';
import { Node } from '../../scene-graph/node';
import { ModelComponent } from './model-component';
import { SkeletalAnimationComponent } from '../../animation/skeletal-animation-component';
/**
* @en The Skinning Model Component.
@@ -87,6 +88,7 @@ export class SkinningModelComponent extends ModelComponent {
set skinningRoot (value) {
if (value === this._skinningRoot) { return; }
this._skinningRoot = value;
this._updateModelType();
this._update();
}
@@ -99,6 +101,10 @@ export class SkinningModelComponent extends ModelComponent {
this._modelType = BakedSkinningModel;
}
public __preload () {
this._updateModelType();
}
public uploadAnimation (clip: AnimationClip | null) {
this._clip = clip;
if (this.model && this.model.uploadAnimation) {
@@ -108,30 +114,34 @@ export class SkinningModelComponent extends ModelComponent {
public setUseBakedAnimation (val = true) {
const modelType = val ? BakedSkinningModel : SkinningModel;
if (this._model && modelType !== this._modelType) {
if (this._modelType === modelType) { return; }
this._modelType = modelType;
const modelCreated = !!this._model;
if (modelCreated) {
cc.director.root.destroyModel(this._model);
this._model = null;
this._models.length = 0;
this._modelType = modelType;
const meshCount = this._mesh ? this._mesh.subMeshCount : 0;
// have to instantiate materials with multiple submodel references
if (this._modelType === SkinningModel) {
let last: Material | null = null;
for (let i = 0; i < meshCount; ++i) {
const cur = this.getRenderMaterial(i);
if (cur === last) {
this.getMaterialInstance(i);
} else { last = cur; }
}
} else { // or assign the original material back if instancing is enabled
for (let i = 0; i < meshCount; ++i) {
const cur = this.getRenderMaterial(i);
if (cur && cur.parent && cur.parent.passes[0].instancedBuffer) {
this._materialInstances[i]!.destroy();
this._materialInstances[i] = null;
}
}
const meshCount = this._mesh ? this._mesh.subMeshCount : 0;
// have to instantiate materials with multiple submodel references
if (this._modelType === SkinningModel) {
let last: Material | null = null;
for (let i = 0; i < meshCount; ++i) {
const cur = this.getRenderMaterial(i);
if (cur === last) {
this.getMaterialInstance(i);
} else { last = cur; }
}
} else { // or assign the original material back if instancing is enabled
for (let i = 0; i < meshCount; ++i) {
const cur = this.getRenderMaterial(i);
if (cur && cur.parent && cur.parent.passes[0].instancedBuffer) {
this._materialInstances[i]!.destroy();
this._materialInstances[i] = null;
}
}
}
if (modelCreated) {
this._updateModels();
this._updateCastShadow();
if (this.enabledInHierarchy) {
@@ -152,6 +162,12 @@ export class SkinningModelComponent extends ModelComponent {
super._updateModelParams();
}
private _updateModelType () {
if (!this._skinningRoot) { return; }
const comp = this._skinningRoot.getComponent('cc.SkeletalAnimationComponent') as SkeletalAnimationComponent;
if (comp) { this.setUseBakedAnimation(comp.useBakedAnimation); }
}
private _update () {
if (this.model) {
this.model.bindSkeleton(this._skeleton, this._skinningRoot, this._mesh);
+1 -1
View File
@@ -115,7 +115,7 @@ export class Material extends Asset {
@property
protected _states: PassOverrides[] = [];
@property
protected _props: Array<Record<string, MaterialPropertyFull | MaterialPropertyFull[]>> = [];
protected _props: Record<string, MaterialPropertyFull | MaterialPropertyFull[]>[] = [];
protected _passes: Pass[] = [];
protected _hash = 0;
+17 -1
View File
@@ -5,6 +5,7 @@
import { replaceProperty } from './utils/deprecated';
import * as math from './math';
import { Scheduler } from './scheduler';
import { CameraComponent } from './3d';
// VMATH
@@ -174,4 +175,19 @@ replaceProperty(Scheduler.prototype, 'Scheduler.prototype', [
target: Scheduler,
targetName: 'Scheduler'
}
]);
]);
replaceProperty(CameraComponent.prototype, 'CameraComponent.prototype', [
{
name: 'color',
newName: 'clearColor',
},
{
name: 'depth',
newName: 'clearDepth',
},
{
name: 'stencil',
newName: 'clearStencil',
},
])
+33 -33
View File
@@ -68,7 +68,7 @@ export abstract class GFXDevice {
* @en The HTML canvas element.
* @zh HTML 画布。
*/
public get canvas (): HTMLCanvasElement {
get canvas (): HTMLCanvasElement {
return this._canvas as HTMLCanvasElement;
}
@@ -76,7 +76,7 @@ export abstract class GFXDevice {
* @en The HTML canvas element for 2D rendering.
* @zh 用于 2D 绘制的 HTML 画布。
*/
public get canvas2D (): HTMLCanvasElement {
get canvas2D (): HTMLCanvasElement {
return this._canvas2D as HTMLCanvasElement;
}
@@ -84,7 +84,7 @@ export abstract class GFXDevice {
* @en Current rendering API.
* @zh 当前 GFX 使用的渲染 API。
*/
public get gfxAPI (): GFXAPI {
get gfxAPI (): GFXAPI {
return this._gfxAPI;
}
@@ -92,7 +92,7 @@ export abstract class GFXDevice {
* @en GFX queue.
* @zh GFX 队列。
*/
public get queue (): GFXQueue {
get queue (): GFXQueue {
return this._queue as GFXQueue;
}
@@ -100,7 +100,7 @@ export abstract class GFXDevice {
* @en Device pixel ratio.
* @zh DPR 设备像素比。
*/
public get devicePixelRatio (): number {
get devicePixelRatio (): number {
return this._devicePixelRatio;
}
@@ -108,7 +108,7 @@ export abstract class GFXDevice {
* @en Device pixel width.
* @zh 设备像素宽度。
*/
public get width (): number {
get width (): number {
return this._width;
}
@@ -116,7 +116,7 @@ export abstract class GFXDevice {
* @en Device pixel height.
* @zh 设备像素高度。
*/
public get height (): number {
get height (): number {
return this._height;
}
@@ -124,7 +124,7 @@ export abstract class GFXDevice {
* @en Device native width.
* @zh 设备原生的像素宽度。
*/
public get nativeWidth (): number {
get nativeWidth (): number {
return this._nativeWidth;
}
@@ -132,7 +132,7 @@ export abstract class GFXDevice {
* @en Device native height.
* @zh 设备原生的像素高度。
*/
public get nativeHeight (): number {
get nativeHeight (): number {
return this._nativeHeight;
}
@@ -140,7 +140,7 @@ export abstract class GFXDevice {
* @en Device main window.
* @zh 设备主窗口。
*/
public get mainWindow (): GFXWindow {
get mainWindow (): GFXWindow {
return this._mainWindow as GFXWindow;
}
@@ -148,7 +148,7 @@ export abstract class GFXDevice {
* @en Device command allocator.
* @zh 命令分配器。
*/
public get commandAllocator (): GFXCommandAllocator {
get commandAllocator (): GFXCommandAllocator {
return this._cmdAllocator as GFXCommandAllocator;
}
@@ -156,7 +156,7 @@ export abstract class GFXDevice {
* @en Renderer description.
* @zh 渲染器描述。
*/
public get renderer (): string {
get renderer (): string {
return this._renderer;
}
@@ -164,7 +164,7 @@ export abstract class GFXDevice {
* @en Vendor description.
* @zh 厂商描述。
*/
public get vendor (): string {
get vendor (): string {
return this._vendor;
}
@@ -172,7 +172,7 @@ export abstract class GFXDevice {
* @en Max vertex attributes supported.
* @zh 最大顶点属性数量。
*/
public get maxVertexAttributes (): number {
get maxVertexAttributes (): number {
return this._maxVertexAttributes;
}
@@ -180,7 +180,7 @@ export abstract class GFXDevice {
* @en Max vertex uniform vectors supported.
* @zh 最大顶点Uniform向量数。
*/
public get maxVertexUniformVectors (): number {
get maxVertexUniformVectors (): number {
return this._maxVertexUniformVectors;
}
@@ -188,7 +188,7 @@ export abstract class GFXDevice {
* @en Max fragment uniform vectors supported.
* @zh 最大片段Uniform向量数。
*/
public get maxFragmentUniformVectors (): number {
get maxFragmentUniformVectors (): number {
return this._maxFragmentUniformVectors;
}
@@ -196,7 +196,7 @@ export abstract class GFXDevice {
* @en Max texture units supported.
* @zh 最大纹理单元数量。
*/
public get maxTextureUnits (): number {
get maxTextureUnits (): number {
return this._maxTextureUnits;
}
@@ -204,7 +204,7 @@ export abstract class GFXDevice {
* @en Max vertex texture units supported.
* @zh 最大顶点纹理单元数量。
*/
public get maxVertexTextureUnits (): number {
get maxVertexTextureUnits (): number {
return this._maxVertexTextureUnits;
}
@@ -212,7 +212,7 @@ export abstract class GFXDevice {
* @en Max uniform buffer bindings supported.
* @zh 最大 UniformBuffer 绑定数量。
*/
public get maxUniformBufferBindings (): number {
get maxUniformBufferBindings (): number {
return this._maxUniformBufferBindings;
}
@@ -220,7 +220,7 @@ export abstract class GFXDevice {
* @en Max uniform block size supported.
* @zh 最大Uniform块大小。
*/
public get maxUniformBlockSize (): number {
get maxUniformBlockSize (): number {
return this._maxUniformBlockSize;
}
@@ -228,7 +228,7 @@ export abstract class GFXDevice {
* @en Max texture size supported.
* @zh 最大贴图尺寸。
*/
public get maxTextureSize (): number {
get maxTextureSize (): number {
return this._maxTextureSize;
}
@@ -236,7 +236,7 @@ export abstract class GFXDevice {
* @en Max cube map texture size supported.
* @zh 最大立方贴图尺寸。
*/
public get maxCubeMapTextureSize (): number {
get maxCubeMapTextureSize (): number {
return this._maxCubeMapTextureSize;
}
@@ -244,7 +244,7 @@ export abstract class GFXDevice {
* @en Device depth bits.
* @zh 深度位数。
*/
public get depthBits (): number {
get depthBits (): number {
return this._depthBits;
}
@@ -252,7 +252,7 @@ export abstract class GFXDevice {
* @en Device stencil bits.
* @zh 模板位数。
*/
public get stencilBits (): number {
get stencilBits (): number {
return this._stencilBits;
}
@@ -260,7 +260,7 @@ export abstract class GFXDevice {
* @en Device color format.
* @zh 颜色格式。
*/
public get colorFormat (): GFXFormat {
get colorFormat (): GFXFormat {
return this._colorFmt;
}
@@ -268,7 +268,7 @@ export abstract class GFXDevice {
* @en Device depth stencil format.
* @zh 深度模板格式。
*/
public get depthStencilFormat (): GFXFormat {
get depthStencilFormat (): GFXFormat {
return this._depthStencilFmt;
}
@@ -276,7 +276,7 @@ export abstract class GFXDevice {
* @en Device built-in macros.
* @zh 系统宏定义。
*/
public get macros (): Map<string, string> {
get macros (): Map<string, string> {
return this._macros;
}
@@ -284,7 +284,7 @@ export abstract class GFXDevice {
* @en Number of draw calls currently recorded.
* @zh 绘制调用次数。
*/
public get numDrawCalls (): number {
get numDrawCalls (): number {
return this._numDrawCalls;
}
@@ -292,7 +292,7 @@ export abstract class GFXDevice {
* @en Number of instances currently recorded.
* @zh 绘制 Instance 数量。
*/
public get numInstances (): number {
get numInstances (): number {
return this._numInstances;
}
@@ -300,7 +300,7 @@ export abstract class GFXDevice {
* @en Number of triangles currently recorded.
* @zh 渲染三角形数量。
*/
public get numTris (): number {
get numTris (): number {
return this._numTris;
}
@@ -308,7 +308,7 @@ export abstract class GFXDevice {
* @en Total memory size currently allocated.
* @zh 内存状态。
*/
public get memoryStatus (): IGFXMemoryStatus {
get memoryStatus (): IGFXMemoryStatus {
return this._memoryStatus;
}
@@ -316,11 +316,11 @@ export abstract class GFXDevice {
* @en Is the front face winding order reversed?
* @zh 是否倒置三角面缠绕顺序?
*/
public get reverseCW (): boolean {
get reverseCW (): boolean {
return this._reverseCW;
}
public set reverseCW (val: boolean) {
set reverseCW (val: boolean) {
this._reverseCW = val;
}
+17
View File
@@ -60,4 +60,21 @@ export class BatchingUtility {
batchedModelComponent.sharedMaterials = modelComponents[0].sharedMaterials;
return true;
}
/**
* Undoes everything `batchStaticModel` did.
*
* @param staticModelRoot root of all the static models to be batched
* @param batchedRoot the target output node
*/
public static unbatchStaticModel (staticModelRoot: Node, batchedRoot: Node) {
const modelComponents = staticModelRoot.getComponentsInChildren(ModelComponent);
for (let i = 0; i < modelComponents.length; i++) {
const comp = modelComponents[i];
comp.enabled = true;
}
const batchedModelComponent = batchedRoot.getComponent(ModelComponent);
if (batchedModelComponent) { batchedModelComponent.destroy(); }
return true;
}
}
+2 -2
View File
@@ -130,11 +130,11 @@ replaceProperty = (owner: object, ownerName: string, properties: IReplacement[])
Object.defineProperty(owner, item.name, {
get (this) {
replacePropertyLog(ownerName, item.name, targetName, newName, warn, id);
return target[newName];
return this[newName];
},
set (this, v: any) {
replacePropertyLog(ownerName, item.name, targetName, newName, warn, id);
target[newName] = v;
this[newName] = v;
}
});
}