mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
@@ -123,14 +123,14 @@ export class Material extends Asset {
|
||||
* pass.setUniform should be used instead
|
||||
* if you need to do per-frame property update.
|
||||
*/
|
||||
public setProperty (name: string, val: any, passIdx?: number, arrayIdx?: number) {
|
||||
public setProperty (name: string, val: any, passIdx?: number) {
|
||||
let success = false;
|
||||
if (passIdx === undefined) { // set property for all applicable passes
|
||||
const passes = this._passes;
|
||||
const len = passes.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const pass = passes[i];
|
||||
if (this._uploadProperty(pass, name, val, arrayIdx)) {
|
||||
if (this._uploadProperty(pass, name, val)) {
|
||||
this._props[i][name] = val;
|
||||
success = true;
|
||||
}
|
||||
@@ -138,7 +138,7 @@ export class Material extends Asset {
|
||||
} else {
|
||||
if (passIdx >= this._passes.length) { console.warn(`illegal pass index: ${passIdx}.`); return; }
|
||||
const pass = this._passes[passIdx];
|
||||
if (this._uploadProperty(pass, name, val, arrayIdx)) {
|
||||
if (this._uploadProperty(pass, name, val)) {
|
||||
this._props[passIdx][name] = val;
|
||||
success = true;
|
||||
}
|
||||
@@ -210,17 +210,21 @@ export class Material extends Asset {
|
||||
this.onPassChange();
|
||||
}
|
||||
|
||||
protected _uploadProperty (pass: Pass, name: string, val: any, arrayIdx?: number) {
|
||||
protected _uploadProperty (pass: Pass, name: string, val: any) {
|
||||
const handle = pass.getHandle(name);
|
||||
if (handle === undefined) { return false; }
|
||||
const bindingType = Pass.getBindingTypeFromHandle(handle);
|
||||
if (bindingType === GFXBindingType.UNIFORM_BUFFER) {
|
||||
pass.setUniform(handle, val, arrayIdx);
|
||||
if (Array.isArray(val)) {
|
||||
pass.setUniformArray(handle, val);
|
||||
} else {
|
||||
pass.setUniform(handle, val);
|
||||
}
|
||||
} else if (bindingType === GFXBindingType.SAMPLER) {
|
||||
const textureView = val instanceof GFXTextureView ? val : val.getGFXTextureView();
|
||||
if (!textureView) { console.warn('texture asset incomplete!'); return false; }
|
||||
const binding = Pass.getBindingFromHandle(handle);
|
||||
pass.bindTextureView(binding, textureView, arrayIdx);
|
||||
pass.bindTextureView(binding, textureView);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -169,6 +169,9 @@ export class ModelComponent extends RenderableComponent {
|
||||
this._updateModels();
|
||||
this._updateCastShadow();
|
||||
this._updateReceiveShadow();
|
||||
if (this._model) {
|
||||
this._model.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public onDisable () {
|
||||
@@ -279,6 +282,6 @@ export class ModelComponent extends RenderableComponent {
|
||||
|
||||
private _getBuiltinMaterial () {
|
||||
// classic ugly pink indicating missing material
|
||||
return cc.BuiltinResMgr['default-material'];
|
||||
return builtinResMgr['default-material'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,12 +206,23 @@ export class Pass {
|
||||
return Pass.getBindingFromHandle(this.getHandle(name));
|
||||
}
|
||||
|
||||
public setUniform (handle: number, value: any, arrayIdx?: number) {
|
||||
public setUniform (handle: number, value: any) {
|
||||
const binding = Pass.getBindingFromHandle(handle);
|
||||
const type = Pass.getTypeFromHandle(handle);
|
||||
const idx = Pass.getIndexFromHandle(handle);
|
||||
const block = this._blocks[binding];
|
||||
_type2fn[type](block.views[idx], value, arrayIdx);
|
||||
_type2fn[type](block.views[idx], value);
|
||||
block.dirty = true;
|
||||
}
|
||||
|
||||
public setUniformArray (handle: number, value: any[]) {
|
||||
const binding = Pass.getBindingFromHandle(handle);
|
||||
const type = Pass.getTypeFromHandle(handle);
|
||||
const idx = Pass.getIndexFromHandle(handle);
|
||||
const block = this._blocks[binding];
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
_type2fn[type](block.views[idx], value[i], i);
|
||||
}
|
||||
block.dirty = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,8 +64,7 @@
|
||||
material.setDefines({ USE_COLOR: true });
|
||||
// parsed effect file is embedded in cocos/3d/builtin/effects.js
|
||||
material.effectName = 'builtin-effect-unlit';
|
||||
material.setProperty('color', cc.Color.RED, 0, 0);
|
||||
material.setProperty('color', cc.Color.BLUE, 0, 1);
|
||||
material.setProperty('color', [ cc.Color.RED, cc.Color.BLUE ]);
|
||||
|
||||
const len = 50;
|
||||
const models = [], passes = [];
|
||||
|
||||
Reference in New Issue
Block a user