diff --git a/cocos/3d/assets/animation-clip.ts b/cocos/3d/assets/animation-clip.ts index 19a4ce3e40..e7d7470dbe 100644 --- a/cocos/3d/assets/animation-clip.ts +++ b/cocos/3d/assets/animation-clip.ts @@ -255,9 +255,9 @@ export class AnimationSampler { propertyAnimation.values[index * 3 + 1], propertyAnimation.values[index * 3 + 2]); const getRotationAt = (index: number, out: Quat) => quat.set(out, - propertyAnimation.values[index * 4 + 0], - propertyAnimation.values[index * 4 + 1], - propertyAnimation.values[index * 4 + 2], + propertyAnimation.values[index * 4 + 0], + propertyAnimation.values[index * 4 + 1], + propertyAnimation.values[index * 4 + 2], propertyAnimation.values[index * 4 + 3]); const getScaleAt = getPositionAt; const keys = clip.keysList[propertyAnimation.indexOfKeys]; @@ -296,7 +296,6 @@ export class AnimationSampler { } } }); - }); } } diff --git a/cocos/3d/framework/particle/renderer/particle-system-renderer.ts b/cocos/3d/framework/particle/renderer/particle-system-renderer.ts index ea86be42dc..b34403c0cc 100644 --- a/cocos/3d/framework/particle/renderer/particle-system-renderer.ts +++ b/cocos/3d/framework/particle/renderer/particle-system-renderer.ts @@ -320,12 +320,7 @@ export default class ParticleSystemRenderer extends RenderableComponent { } else { console.warn(`particle system renderMode ${this._renderMode} not support.`); } - const ea = mat!.effectAsset; - mat!.destroy(); - mat!.initialize({ - defines: this._defines, - effectAsset: ea, - }); + for (const pass of mat!.passes) { pass.tryCompile(this._defines); } if (this.particleSystem.textureAnimationModule.enable) { mat!.setProperty('frameTile_velLenScale', vec2.set(this.frameTile_velLenScale, this.particleSystem.textureAnimationModule.numTilesX, this.particleSystem.textureAnimationModule.numTilesY)); diff --git a/cocos/3d/framework/skinning-model-component.ts b/cocos/3d/framework/skinning-model-component.ts index e2570c58d3..15a5e4815c 100644 --- a/cocos/3d/framework/skinning-model-component.ts +++ b/cocos/3d/framework/skinning-model-component.ts @@ -25,15 +25,17 @@ // @ts-check import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../core/data/class-decorator'; +import { Mat4 } from '../../core/value-types'; import { mat4 } from '../../core/vmath'; -import { GFXDevice, GFXFeature } from '../../gfx/device'; -import { __FORCE_USE_UNIFORM_STORAGE__, SkinningModel, useJointsTexture } from '../../renderer/models/skinning-model'; +import { GFXDevice } from '../../gfx/device'; +import { SkinningModel, useJointsTexture } from '../../renderer/models/skinning-model'; import { Node } from '../../scene-graph/node'; import { Material } from '../assets/material'; import Skeleton from '../assets/skeleton'; import { ModelComponent } from './model-component'; -const _m4_tmp = mat4.create(); +const _m4_tmp = new Mat4(); +const _m4_tmp2 = new Mat4(); type SkinningTarget = Map; @@ -110,7 +112,7 @@ export class SkinningModelComponent extends ModelComponent { const skeleton = this._skeleton; const skinningTarget = this._skinningTarget; - const cancelThisNodeTransform = this.node.getWorldMatrix(); + const cancelThisNodeTransform = this.node.getWorldMatrix(_m4_tmp2); mat4.invert(cancelThisNodeTransform, cancelThisNodeTransform); this._skeleton.joints.forEach((joint, index) => { // If target joint doesn't exists in scene graph, skip it. @@ -123,7 +125,7 @@ export class SkinningModelComponent extends ModelComponent { // 3. because it has been in world space, just cancel this mesh's original local-world transform const bindpose = skeleton.bindposes[index]; const jointMatrix = _m4_tmp; - mat4.multiply(jointMatrix, cancelThisNodeTransform, targetNode.getWorldMatrix()); + mat4.multiply(jointMatrix, cancelThisNodeTransform, targetNode.getWorldMatrix(_m4_tmp)); mat4.multiply(jointMatrix, jointMatrix, bindpose); skinningModel.updateJointMatrix(index, jointMatrix); }); @@ -142,14 +144,12 @@ export class SkinningModelComponent extends ModelComponent { } protected _onMaterialModified (index: number, material: Material) { - super._onMaterialModified(index, material); - const device = _getGlobalDevice(); const useJointTexture = device !== null && useJointsTexture(device); const mat = this.getMaterial(index, CC_EDITOR)!; - const effectAsset = mat.effectAsset; - mat.destroy(); - mat.initialize({ effectAsset, defines: { CC_USE_SKINNING: true, CC_USE_JOINTS_TEXTURE: useJointTexture } }); + const defines = { CC_USE_SKINNING: true, CC_USE_JOINTS_TEXTURE: useJointTexture }; + for (const pass of mat.passes) { pass.tryCompile(defines); } + super._onMaterialModified(index, mat); } private _bindSkeleton () { diff --git a/cocos/renderer/core/pass.ts b/cocos/renderer/core/pass.ts index e2d6f1121b..61072db082 100644 --- a/cocos/renderer/core/pass.ts +++ b/cocos/renderer/core/pass.ts @@ -17,10 +17,10 @@ import { GFXSampler } from '../../gfx/sampler'; import { GFXShader } from '../../gfx/shader'; import { GFXTextureView } from '../../gfx/texture-view'; import { RenderPassStage, RenderPriority } from '../../pipeline/define'; +import { getPhaseID } from '../../pipeline/pass-phase'; import { RenderPipeline } from '../../pipeline/render-pipeline'; import { programLib } from './program-lib'; import { samplerLib } from './sampler-lib'; -import { getPhaseID } from '../../pipeline/pass-phase'; export interface IDefineMap { [name: string]: number | boolean | string; } export interface IPassInfoFull extends IPassInfo { @@ -276,7 +276,8 @@ export class Pass { } } - public tryCompile () { + public tryCompile (defines?: IDefineMap) { + if (defines) { Object.assign(this._defines, defines); } const pipeline = cc.director.root.pipeline as RenderPipeline | null; if (!pipeline) { return false; } this._renderPass = pipeline.getRenderPass(this._stage); @@ -363,8 +364,8 @@ export class Pass { if (info.priority !== undefined) { this._priority = info.priority; } if (info.primitive !== undefined) { this._primitive = info.primitive; } if (info.stage !== undefined) { this._stage = info.stage; } - if (info.dynamics !== undefined) { this._dynamicStates = info.dynamics; } - if (info.customizations) { this._customizations = info.customizations; } + if (info.dynamics !== undefined) { this._dynamicStates = info.dynamics as GFXDynamicState[]; } + if (info.customizations) { this._customizations = info.customizations as string[]; } if (this._phase === 0) { const phaseName = info.phase || 'default'; this._phase = getPhaseID(phaseName); diff --git a/cocos/renderer/models/skinning-model.ts b/cocos/renderer/models/skinning-model.ts index cb554039d3..d60c60b40e 100644 --- a/cocos/renderer/models/skinning-model.ts +++ b/cocos/renderer/models/skinning-model.ts @@ -35,7 +35,7 @@ function isUniformStorage (storage: JointStorage): storage is IJointUniformsStor return !('texture' in storage); } -export const __FORCE_USE_UNIFORM_STORAGE__ = true; +export const __FORCE_USE_UNIFORM_STORAGE__ = false; export class SkinningModel extends Model { private _jointStorage: JointStorage | null = null; @@ -168,7 +168,7 @@ function _createJointsTexture (skinning: { joints: any[]; }) { } } if (textureExtent < 0) { - throw new Error('To many joints.'); + throw new Error('Too many joints.'); } const texture = new Texture2D();