From 85c999ea0d5ff54102dbabd5b4a82b6b08deb9de Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Fri, 6 Sep 2019 19:41:31 +0800 Subject: [PATCH] fix material copy (#5350) --- cocos/core/assets/material.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cocos/core/assets/material.ts b/cocos/core/assets/material.ts index 5164ac4842..0a0df87367 100644 --- a/cocos/core/assets/material.ts +++ b/cocos/core/assets/material.ts @@ -206,7 +206,7 @@ export class Material extends Asset { */ public resetUniforms (clearPasses = true) { this._props.length = this._passes.length; - this._props.fill({}); + for (let i = 0; i < this._props.length; i++) { this._props[i] = {}; } if (!clearPasses) { return; } for (const pass of this._passes) { pass.resetUBOs(); @@ -336,16 +336,17 @@ export class Material extends Asset { public copy (mat: Material) { this._techIdx = mat._techIdx; this._props.length = mat._props.length; - this._props.fill({}); for (let i = 0; i < mat._props.length; i++) { - Object.assign(this._props[i], mat._props[i]); + this._props[i] = Object.assign({}, mat._props[i]); } this._defines.length = mat._defines.length; - this._defines.fill({}); for (let i = 0; i < mat._defines.length; i++) { - Object.assign(this._defines[i], mat._defines[i]); + this._defines[i] = Object.assign({}, mat._defines[i]); + } + this._states.length = mat._states.length; + for (let i = 0; i < mat._states.length; i++) { + this._states[i] = Object.assign({}, mat._states[i]); } - Object.assign(this._states, mat._states); this._effectAsset = mat._effectAsset; this._update(); } @@ -386,7 +387,7 @@ export class Material extends Asset { } }); } else { - this._props.fill({}); + for (let i = 0; i < this._props.length; i++) { this._props[i] = {}; } } } else { // ugly yellow indicating missing effect this._passes = builtinResMgr.get('missing-effect-material')._passes.slice();