mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
@@ -25,7 +25,7 @@
|
||||
// @ts-check
|
||||
import { ccclass, property } from "../../core/data/class-decorator";
|
||||
import Asset from "../../assets/CCAsset";
|
||||
import Texture from '../../assets/CCTexture2D';
|
||||
import TextureBase from '../../assets/texture-base';
|
||||
import Effect from '../../renderer/core/effect';
|
||||
import EffectAsset from './effect-asset';
|
||||
|
||||
@@ -83,7 +83,10 @@ class Material extends Asset {
|
||||
* @param {Material} mat
|
||||
*/
|
||||
copy(mat) {
|
||||
Object.assign(this._props, mat._props);
|
||||
Object.assign(this._defines, mat._defines);
|
||||
this._setEffect(mat.effectAsset);
|
||||
this._uuid = mat._uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +97,7 @@ class Material extends Asset {
|
||||
setProperty(name, val) {
|
||||
this._props[name] = val;
|
||||
if (this._effect) {
|
||||
if (val instanceof Texture) this._effect.setProperty(name, val._texture);
|
||||
if (val instanceof TextureBase) this._effect.setProperty(name, val._texture);
|
||||
else this._effect.setProperty(name, val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,6 +216,7 @@ export default class ModelComponent extends RenderableComponent {
|
||||
}
|
||||
|
||||
_updateModelParams() {
|
||||
this.node._hasChanged = true;
|
||||
for (let i = 0; i < this._models.length; ++i) {
|
||||
let model = this._models[i];
|
||||
let material = this.getSharedMaterial(i);
|
||||
@@ -268,7 +269,7 @@ export default class ModelComponent extends RenderableComponent {
|
||||
for (let i = 0; i < this._models.length; ++i) {
|
||||
let model = this._models[i];
|
||||
if (model._defines['USE_SHADOW_MAP'] != undefined) {
|
||||
model._effect.define('USE_SHADOW_MAP', this._receiveShadows);
|
||||
this.getMaterial(i).define('USE_SHADOW_MAP', this._receiveShadows);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ export default function (radiusTop = 0.5, radiusBottom = 0.5, height = 2, opts =
|
||||
normals.push(temp1.z);
|
||||
|
||||
// uv
|
||||
uvs.push(-u,v);
|
||||
uvs.push(u,v);
|
||||
// save index of vertex in respective row
|
||||
indexRow.push(index);
|
||||
|
||||
@@ -148,7 +148,7 @@ export default function (radiusTop = 0.5, radiusBottom = 0.5, height = 2, opts =
|
||||
|
||||
positions.push(x * radiusBottom, y * radiusBottom + bottomOffset, z * radiusBottom);
|
||||
normals.push(x, y, z);
|
||||
uvs.push(-u, v);
|
||||
uvs.push(u, v);
|
||||
|
||||
if ((lat < bottomSegments) && (lon < sides)) {
|
||||
let seg1 = sides + 1;
|
||||
@@ -185,7 +185,7 @@ export default function (radiusTop = 0.5, radiusBottom = 0.5, height = 2, opts =
|
||||
|
||||
positions.push(x * radiusTop, y * radiusTop + topOffset, z * radiusTop);
|
||||
normals.push(x, y, z);
|
||||
uvs.push(-u, v);
|
||||
uvs.push(u, v);
|
||||
|
||||
if ((lat < topSegments) && (lon < sides)) {
|
||||
let seg1 = sides + 1;
|
||||
|
||||
@@ -48,7 +48,7 @@ export default function (width = 10, length = 10, opts = {}) {
|
||||
|
||||
positions.push(r.x, r.y, r.z);
|
||||
normals.push(0, 1, 0);
|
||||
uvs.push(-u, -v);
|
||||
uvs.push(u, v);
|
||||
|
||||
if ((x < uSegments) && (y < vSegments)) {
|
||||
let useg1 = uSegments + 1;
|
||||
|
||||
@@ -5,8 +5,8 @@ import Pass from './pass';
|
||||
import Technique from './technique';
|
||||
import { Vec2, Vec3, Vec4, Color, Mat4 } from '../../core/value-types';
|
||||
import { CCObject } from '../../core/data';
|
||||
import Texture2D from '../../assets/CCTexture2D';
|
||||
import TextureCube from '../../3d/assets/texture-cube';
|
||||
import Texture2D from '../gfx/texture-2d';
|
||||
import TextureCube from '../gfx/texture-cube';
|
||||
|
||||
let _typeMap = {
|
||||
[enums.PARAM_INT]: Number,
|
||||
@@ -87,23 +87,22 @@ class Effect {
|
||||
console.warn(`Failed to set property ${name}, property not found.`);
|
||||
return;
|
||||
}
|
||||
// else if (!typeCheck(value, prop.type)) { // re-enable this after 3.x migration
|
||||
// console.warn(`Failed to set property ${name}, property type mismatch.`);
|
||||
// return;
|
||||
// }
|
||||
else if (!typeCheck(value, prop.type)) {
|
||||
console.warn(`Failed to set property ${name}, property type mismatch.`);
|
||||
return;
|
||||
}
|
||||
this._properties[name].value = value;
|
||||
}
|
||||
|
||||
getDefine(name) {
|
||||
let def = this._defines[name];
|
||||
if (def !== undefined) return def.value;
|
||||
if (def !== undefined) return def;
|
||||
console.warn(`Failed to get define ${name}, define not found.`);
|
||||
return null;
|
||||
}
|
||||
|
||||
define(name, value) {
|
||||
let def = this._defines[name];
|
||||
if (def !== undefined) def.value = value;
|
||||
if (this._defines[name] !== undefined) this._defines[name] = value;
|
||||
else console.warn(`Failed to set define ${name}, define not found.`);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ let _shdID = 0;
|
||||
function _generateDefines(device, defs, deps) {
|
||||
let defines = [];
|
||||
for (let def in defs) {
|
||||
let d = defs[def].value;
|
||||
let d = defs[def];
|
||||
let result = typeof d === 'number' ? d : d ? 1 : 0;
|
||||
// fallback if extension dependency not supported
|
||||
if (result && deps[def] && !device.ext(deps[def])) {
|
||||
|
||||
Reference in New Issue
Block a user