fix model bug

This commit is contained in:
zhuxuguang
2019-01-10 14:32:10 +08:00
parent 7c6d60c60c
commit 324914df02
8 changed files with 95 additions and 119 deletions
+3 -3
View File
@@ -2,18 +2,18 @@ export default [
{
"name": "test",
"techniques": [{"queue": 0, "lod": 500, "passes": [{"stage": 100, "program": "f4c45e6cc7794309d86202e6ec9036a3871fd1ec167a9e02eb1e1574"}], "priority": 0}],
"properties": {"u_color": {"type": 17, "value": [1, 1, 1, 1]}, "u_sampler": {"type": 29, "value": null}},
"properties": {"u_color": {"type": 16, "value": [1, 1, 1, 1]}, "u_sampler": {"type": 29, "value": null}},
"shaders": [
{
"name": "f4c45e6cc7794309d86202e6ec9036a3871fd1ec167a9e02eb1e1574",
"vert": `
attribute vec3 a_position;
attribute vec2 a_texCoord;
attribute vec2 a_uv0;
uniform mat4 cc_matWorld;
varying vec2 v_texCoord;
void main() {
gl_Position = cc_matWorld*vec4(a_position, 1.0);
v_texCoord = a_texCoord;
v_texCoord = a_uv0;
}
`,
"frag": `
+29 -18
View File
@@ -134,7 +134,8 @@ export default class CameraComponent extends Component {
if (this._projection === CameraProjection.Ortho) {
type = renderer.PROJ_ORTHO;
}
this._camera.setType(type);
if (this.enabled)
this._camera.setType(type);
}
/**
@@ -150,7 +151,8 @@ export default class CameraComponent extends Component {
set priority(val) {
this._priority = val;
this._camera.setPriority(val);
if (this.enabled)
this._camera.setPriority(val);
}
/**
@@ -166,7 +168,8 @@ export default class CameraComponent extends Component {
set fov(val) {
this._fov = val;
this._camera.setFov(toRadian(val));
if (this.enabled)
this._camera.setFov(toRadian(val));
}
/**
@@ -182,7 +185,8 @@ export default class CameraComponent extends Component {
set orthoHeight(val) {
this._orthoHeight = val;
this._camera.setOrthoHeight(val);
if (this.enabled)
this._camera.setOrthoHeight(val);
}
/**
@@ -198,7 +202,8 @@ export default class CameraComponent extends Component {
set near(val) {
this._near = val;
this._camera.setNear(val);
if (this.enabled)
this._camera.setNear(val);
}
/**
@@ -214,7 +219,8 @@ export default class CameraComponent extends Component {
set far(val) {
this._far = val;
this._camera.setFar(val);
if (this.enabled)
this._camera.setFar(val);
}
/**
@@ -230,7 +236,8 @@ export default class CameraComponent extends Component {
set color(val) {
this._color = val;
this._camera.setColor(val.r / 255, val.g / 255, val.b / 255, val.a / 255);
if (this.enabled)
this._camera.setColor(val.r / 255, val.g / 255, val.b / 255, val.a / 255);
}
/**
@@ -246,7 +253,8 @@ export default class CameraComponent extends Component {
set depth(val) {
this._depth = val;
this._camera.setDepth(val);
if (this.enabled)
this._camera.setDepth(val);
}
/**
@@ -262,7 +270,8 @@ export default class CameraComponent extends Component {
set stencil(val) {
this._stencil = val;
this._camera.setStencil(val);
if (this.enabled)
this._camera.setStencil(val);
}
/**
@@ -280,7 +289,8 @@ export default class CameraComponent extends Component {
set clearFlags(val) {
this._clearFlags = val;
this._camera.setClearFlags(val);
if (this.enabled)
this._camera.setClearFlags(val);
}
/**
@@ -296,7 +306,8 @@ export default class CameraComponent extends Component {
set rect(val) {
this._rect = val;
this._camera.setRect(val.x, val.y, val.width, val.height);
if (this.enabled)
this._camera.setRect(val.x, val.y, val.width, val.height);
}
static Projection = CameraProjection;
@@ -306,7 +317,11 @@ export default class CameraComponent extends Component {
}
onLoad() {
this._camera = this.getRenderScene().createCamera(this.name);
}
onEnable() {
this._camera = this._getRenderScene().createCamera(this.name);
this.projection = this._projection;
this.priority = this._priority;
this.fov = this._fov;
@@ -322,16 +337,12 @@ export default class CameraComponent extends Component {
this._camera.setNode(this.node);
}
onEnable() {
this._camera._enable = this.enabled;
}
onDisable() {
this._camera._enable = this.enabled;
this._getRenderScene().destroyCamera(this._camera);
}
onDestroy() {
this.getRenderScene().destroyCamera(this._camera);
}
/**
+35 -21
View File
@@ -180,7 +180,8 @@ export default class LightComponent extends Component {
} else if (this._type === LightType.Spot) {
type = renderer.LIGHT_SPOT;
}
this._light.setType(type);
if (this.enabled)
this._light.setType(type);
}
/**
@@ -196,7 +197,8 @@ export default class LightComponent extends Component {
set color(val) {
this._color = val;
this._light.setColor(val.r / 255, val.g / 255, val.b / 255);
if (this.enabled)
this._light.setColor(val.r / 255, val.g / 255, val.b / 255);
}
/**
@@ -212,7 +214,8 @@ export default class LightComponent extends Component {
set intensity(val) {
this._intensity = val;
this._light.setIntensity(val);
if (this.enabled)
this._light.setIntensity(val);
}
/**
@@ -228,7 +231,8 @@ export default class LightComponent extends Component {
set range(val) {
this._range = val;
this._light.setRange(val);
if (this.enabled)
this._light.setRange(val);
}
/**
@@ -244,7 +248,8 @@ export default class LightComponent extends Component {
set spotAngle(val) {
this._spotAngle = val;
this._light.setSpotAngle(toRadian(val));
if (this.enabled)
this._light.setSpotAngle(toRadian(val));
}
/**
@@ -260,7 +265,8 @@ export default class LightComponent extends Component {
set spotExp(val) {
this._spotExp = val;
this._light.setSpotExp(val);
if (this.enabled)
this._light.setSpotExp(val);
}
/**
@@ -285,7 +291,8 @@ export default class LightComponent extends Component {
} else if (val === LightShadowType.Soft) {
type = renderer.SHADOW_SOFT;
}
this._light.setShadowType(type);
if (this.enabled)
this._light.setShadowType(type);
}
/**
@@ -302,7 +309,8 @@ export default class LightComponent extends Component {
set shadowResolution(val) {
this._shadowResolution = val;
this._light.setShadowResolution(val);
if (this.enabled)
this._light.setShadowResolution(val);
}
/**
@@ -319,7 +327,8 @@ export default class LightComponent extends Component {
set shadowDarkness(val) {
this._shadowDarkness = val;
this._light.setShadowDarkness(val);
if (this.enabled)
this._light.setShadowDarkness(val);
}
/**
@@ -336,7 +345,8 @@ export default class LightComponent extends Component {
set shadowMinDepth(val) {
this._shadowMinDepth = val;
this._light.setShadowMinDepth(val);
if (this.enabled)
this._light.setShadowMinDepth(val);
}
/**
@@ -353,7 +363,8 @@ export default class LightComponent extends Component {
set shadowMaxDepth(val) {
this._shadowMaxDepth = val;
this._light.setShadowMaxDepth(val);
if (this.enabled)
this._light.setShadowMaxDepth(val);
}
/**
@@ -370,7 +381,8 @@ export default class LightComponent extends Component {
set shadowDepthScale(val) {
this._shadowDepthScale = val;
this._light.setShadowDepthScale(val);
if (this.enabled)
this._light.setShadowDepthScale(val);
}
/**
@@ -387,7 +399,8 @@ export default class LightComponent extends Component {
set shadowFrustumSize(val) {
this._shadowFrustumSize = val;
this._light.setShadowFrustumSize(val);
if (this.enabled)
this._light.setShadowFrustumSize(val);
}
/**
@@ -404,7 +417,8 @@ export default class LightComponent extends Component {
set shadowBias(val) {
this._shadowBias = val;
this._light.setShadowBias(val);
if (this.enabled)
this._light.setShadowBias(val);
}
static Type = LightType;
@@ -416,7 +430,11 @@ export default class LightComponent extends Component {
}
onLoad() {
this._light = this.getRenderScene().createLight(this.name);
}
onEnable() {
this._light = this._getRenderScene().createLight(this.name);
this._light.setNode(this.node);
this.type = this._type;
this.color = this._color;
@@ -433,15 +451,11 @@ export default class LightComponent extends Component {
this.shadowBias = this._shadowBias;
}
onEnable() {
this._light._enable = this.enabled;
}
onDisable() {
this._light._enable = this.enabled;
this._getRenderScene().destroyLight(this._light);
}
onDestroy() {
this.getRenderScene().destroyLight(this._light);
}
}
+17 -18
View File
@@ -171,49 +171,42 @@ export default class ModelComponent extends RenderableComponent {
}
onLoad() {
}
onEnable() {
this._updateModels();
this._updateCastShadow();
this._updateReceiveShadow();
}
onEnable() {
for (let i = 0; i < this._models.length; ++i) {
this._models[i]._enable = this.enabled;
}
}
onDisable() {
for (let i = 0; i < this._models.length; ++i) {
this._models[i]._enable = this.enabled;
this._getRenderScene().destroyModel(this._models[i]);
}
this._models.splice(0);
}
onDestroy() {
for (let i = 0; i < this._models.length; ++i) {
this.getRenderScene().destroyModel(this._models[i]);
}
}
_updateModels() {
if (!this.enabled)
return;
let meshCount = this._mesh ? this._mesh.subMeshCount : 0;
let oldModels = this._models;
this._models = new Array(meshCount);
for (let i = 0; i < meshCount; ++i) {
let model = this._createModel();
model.createBoundingShape(this._mesh.minPosition, this._mesh.maxPosition);
this._models[i] = model;
this._models.push(model);
}
this._updateModelParams();
for (let i = 0; i < oldModels.length; ++i) {
this.getRenderScene().destroyModel(oldModels[i]);
}
}
_createModel() {
return this.getRenderScene().createModel(Model);
return this._getRenderScene().createModel(Model);
}
_updateModelParams() {
@@ -247,10 +240,14 @@ export default class ModelComponent extends RenderableComponent {
* @param {Material} material
*/
_updateModelMaterial(model, material) {
if (!this.enabled)
return;
model.material = material ? material : this._getBuiltinMaterial();
}
_updateCastShadow() {
if (!this.enabled)
return;
if (this._shadowCastingMode === ModelShadowCastingMode.Off) {
for (let i = 0; i < this._models.length; ++i) {
let model = this._models[i];
@@ -267,6 +264,8 @@ export default class ModelComponent extends RenderableComponent {
}
_updateReceiveShadow() {
if (!this.enabled)
return;
for (let i = 0; i < this._models.length; ++i) {
let model = this._models[i];
if (model._defines['_USE_SHADOW_MAP'] != undefined) {
+2 -2
View File
@@ -195,8 +195,8 @@ class Component extends CCObject {
static system = null;
getRenderScene(index = 0) {
return this.node._scene._renderScenes[index];
_getRenderScene() {
return this.node._scene._renderScene;
}
constructor () {
+2 -1
View File
@@ -87,8 +87,9 @@ export class TestModelStage extends RenderStage {
this._material.effectName = 'test'; // parsed-effect file is embedded in cocos/3d/builtin/effects.js
this._material.setProperty('u_sampler', this._textureAsset);
this._material.setProperty('u_color', cc.color('#ff0000'));
this._material.setProperty('u_color', cc.color('#ff1234'));
this._material.inited = true;
this._material.passes[0].update();
this._scene = new Scene();
this._scene._scene = this._scene;
+5 -53
View File
@@ -32,15 +32,15 @@ export function createIA(device, data) {
}
let vfmt = [];
vfmt.push({ name: gfx.ATTR_POSITION, type: gfx.ATTR_TYPE_FLOAT32, num: 3 });
vfmt.push({ name: gfx.ATTR_POSITION, format: GFXFormat.RGB32F });
if (data.normals) {
vfmt.push({ name: gfx.ATTR_NORMAL, type: gfx.ATTR_TYPE_FLOAT32, num: 3 });
vfmt.push({ name: gfx.ATTR_NORMAL, format: GFXFormat.RGB32F });
}
if (data.uvs) {
vfmt.push({ name: gfx.ATTR_UV0, type: gfx.ATTR_TYPE_FLOAT32, num: 2 });
vfmt.push({ name: gfx.ATTR_UV0, format: GFXFormat.RG32F });
}
if (data.colors) {
vfmt.push({ name: gfx.ATTR_COLOR, type: gfx.ATTR_TYPE_FLOAT32, num: 3 });
vfmt.push({ name: gfx.ATTR_COLOR, format: GFXFormat.RGB32F });
}
let vb = cc.director.root.device.createBuffer({
@@ -61,56 +61,8 @@ export function createIA(device, data) {
ib.update(new Uint16Array(data.indices));
let attributes = [];
for (let i = 0; i < vfmt.length; i++) {
let gfxAttr = {};
gfxAttr.name = vfmt[i].name;
let gfxFormat;
switch (vfmt[i].num) {
case 1:
gfxFormat = 'R';
break;
case 2:
gfxFormat = 'RG';
break;
case 3:
gfxFormat = 'RGB';
break;
case 4:
gfxFormat = 'RGBA';
break;
}
switch (vfmt[i].type) {
case gfx.ATTR_TYPE_INT8:
gfxFormat += '8I';
break;
case gfx.ATTR_TYPE_UINT8:
gfxFormat += '8UI';
break;
case gfx.ATTR_TYPE_INT16:
gfxFormat += '16I';
break;
case gfx.ATTR_TYPE_UINT16:
gfxFormat += '16UI';
break;
case gfx.ATTR_TYPE_INT32:
gfxFormat += '32I';
break;
case gfx.ATTR_TYPE_UINT32:
gfxFormat += '32UI';
break;
case gfx.ATTR_TYPE_FLOAT32:
gfxFormat += '32F';
break;
}
gfxAttr.format = GFXFormat[gfxFormat];
gfxAttr.normalize = vfmt[i].normalize;
attributes.push(gfxAttr);
}
return cc.director.root.device.createInputAssembler({
attributes,
attributes: vfmt,
vertexBuffers: [vb],
indexBuffer: ib,
});
+2 -3
View File
@@ -41,8 +41,6 @@ import { RenderScene } from '../renderer/scene/render-scene';
@ccclass("cc.Scene")
export default class Scene extends Node {
_renderScenes = new Array();
constructor(name) {
super(name);
@@ -56,7 +54,7 @@ export default class Scene extends Node {
// cache all depend assets for auto release
this.dependAssets = null;
this._renderScenes.push(new RenderScene());
this._renderScene = cc.director.root.createScene({});
}
/**
@@ -72,6 +70,7 @@ export default class Scene extends Node {
destroy () {
super.destroy();
cc.director.root.destroyScene(this._renderScene);
this._activeInHierarchy = false;
}