diff --git a/cocos/3d/assets/material.ts b/cocos/3d/assets/material.ts index 7c9ceece5f..e84b52fcee 100644 --- a/cocos/3d/assets/material.ts +++ b/cocos/3d/assets/material.ts @@ -40,7 +40,7 @@ export interface IMaterialInfo { @ccclass('cc.Material') export class Material extends Asset { - public static getInstantiatedMaterial (mat: Material, rndCom: any, inEditor: boolean) { + public static getInstantiatedMaterial (mat: Material, rndCom: RenderableComponent, inEditor: boolean) { if (mat._owner === rndCom) { return mat; } else { diff --git a/cocos/3d/builtin/effects.js b/cocos/3d/builtin/effects.js index 1e1da78f28..b8c14cddfd 100644 --- a/cocos/3d/builtin/effects.js +++ b/cocos/3d/builtin/effects.js @@ -97,35 +97,5 @@ export default [ "dependencies": {} } ] - }, - { - "name": "builtin-effect-unlit", - "techniques": [{"passes":[{"program":"builtin-effect-unlit|unlit-vs:vert|unlit-fs:frag", "properties":{"color":{"type":17, "value":[1, 1, 1, 1]}, "mainTiling":{"type":14, "value":[1, 1]}, "mainOffset":{"type":14, "value":[0, 0]}, "mainTexture":{"type":29, "value":"grey"}}}]}], - "shaders": [ - { - "name": "builtin-effect-unlit|unlit-vs:vert|unlit-fs:frag", - "vert": "\nattribute vec3 a_position;\n uniform vec4 cc_time;\n uniform vec4 cc_screenSize;\n uniform vec4 cc_screenScale;\n uniform mat4 cc_matProj;\n uniform mat4 cc_matProjInv;\n uniform mat4 cc_matView;\n uniform mat4 cc_matViewInv;\n uniform mat4 cc_matViewProj;\n uniform mat4 cc_matViewProjInv;\n uniform vec4 cc_cameraPos;\n uniform vec4 cc_dirLightDirection[4];\n uniform vec4 cc_dirLightColor[4];\n uniform vec4 cc_pointLightPositionAndRange[4];\n uniform vec4 cc_pointLightColor[4];\n uniform vec4 cc_spotLightPositionAndRange[4];\n uniform vec4 cc_spotLightDirection[4];\n uniform vec4 cc_spotLightColor[4];\n uniform mat4 cc_matViewProjLight;\n uniform vec4 cc_shadowParam1;\n uniform vec4 cc_shadowParam2;\n uniform mat4 cc_matWorld;\n uniform mat4 cc_matWorldIT;\n#if USE_TEXTURE\n attribute vec2 a_texCoord;\n uniform vec2 mainTiling;\n uniform vec2 mainOffset;\n varying vec2 uv0;\n#endif\n#if CC_USE_SKINNING\n \nattribute vec4 a_weights;\nattribute vec4 a_joints;\n uniform mat4 cc_matJoint[128];\n uniform vec4 cc_jointsTextureSize;\n#if CC_USE_JOINTS_TEXTURE\nuniform sampler2D cc_jointsTexture;\nmat4 getBoneMatrix(const in float i) {\n float size = cc_jointsTextureSize.x;\n float j = i * 4.0;\n float x = mod(j, size);\n float y = floor(j / size);\n float dx = 1.0 / size;\n float dy = 1.0 / size;\n y = dy * (y + 0.5);\n vec4 v1 = texture2D(cc_jointsTexture, vec2(dx * (x + 0.5), y));\n vec4 v2 = texture2D(cc_jointsTexture, vec2(dx * (x + 1.5), y));\n vec4 v3 = texture2D(cc_jointsTexture, vec2(dx * (x + 2.5), y));\n vec4 v4 = texture2D(cc_jointsTexture, vec2(dx * (x + 3.5), y));\n return mat4(v1, v2, v3, v4);\n}\n#else\nmat4 getBoneMatrix(const in float i) {\n return cc_matJoint[int(i)];\n}\n#endif\nmat4 skinMatrix() {\n return\n getBoneMatrix(a_joints.x) * a_weights.x +\n getBoneMatrix(a_joints.y) * a_weights.y +\n getBoneMatrix(a_joints.z) * a_weights.z +\n getBoneMatrix(a_joints.w) * a_weights.w;\n}\nvoid skinVertex(inout vec4 a1) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n}\nvoid skinVertex(inout vec4 a1, inout vec4 a2, inout vec4 a3) {\n mat4 m = skinMatrix();\n a1 = m * a1;\n a2 = m * a2;\n a3 = m * a3;\n}\n#endif\nvec4 vert () {\n vec4 pos = vec4(a_position, 1);\n #if CC_USE_SKINNING\n skinVertex(pos);\n #endif\n pos = cc_matViewProj * cc_matWorld * pos;\n #if USE_TEXTURE\n uv0 = a_texCoord * mainTiling + mainOffset;\n #endif\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n", - "frag": "\n#if USE_TEXTURE\n uniform sampler2D mainTexture;\n varying vec2 uv0;\n#endif\n#if USE_COLOR\n uniform vec4 color;\n#endif\nvec4 frag () {\n vec4 o = vec4(1, 1, 1, 1);\n #if USE_TEXTURE\n o *= texture2D(mainTexture, uv0);\n #endif\n #if USE_COLOR\n o *= color;\n #endif\n return o;\n}\nvoid main() { gl_FragColor = frag(); }\n", - "defines": [ - {"name":"USE_TEXTURE", "type":"boolean", "defines":[]}, - {"name":"CC_USE_SKINNING", "type":"boolean", "defines":[]}, - {"name":"CC_USE_JOINTS_TEXTURE", "type":"boolean", "defines":["CC_USE_SKINNING"]}, - {"name":"USE_COLOR", "type":"boolean", "defines":[]} - ], - "blocks": [ - {"name": "TexCoords", "size": 16, "defines": ["USE_TEXTURE"], "binding": 0, "members": [ - {"name":"mainTiling", "type":14, "count":1, "size":8}, - {"name":"mainOffset", "type":14, "count":1, "size":8} - ]}, - {"name": "Constant", "size": 16, "defines": ["USE_COLOR"], "binding": 1, "members": [ - {"name":"color", "type":16, "count":1, "size":16} - ]} - ], - "samplers": [ - {"name":"mainTexture", "type":29, "count":1, "defines":["USE_TEXTURE"], "binding":2} - ], - "dependencies": {} - } - ] } ]; diff --git a/cocos/3d/framework/model-component.ts b/cocos/3d/framework/model-component.ts index 3436895072..201b134e1a 100644 --- a/cocos/3d/framework/model-component.ts +++ b/cocos/3d/framework/model-component.ts @@ -283,6 +283,6 @@ export class ModelComponent extends RenderableComponent { private _getBuiltinMaterial () { // classic ugly pink indicating missing material - return builtinResMgr['default-material']; + return builtinResMgr.get('default-material'); } } diff --git a/cocos/3d/framework/particle/emitter/shape-module.js b/cocos/3d/framework/particle/emitter/shape-module.js index 2b7877a368..a5bdd4af3f 100644 --- a/cocos/3d/framework/particle/emitter/shape-module.js +++ b/cocos/3d/framework/particle/emitter/shape-module.js @@ -36,11 +36,15 @@ export default class ShapeModule { @property enable = false; - @property + @property({ + type: ShapeType + }) shapeType = ShapeType.Box; - @property - emitFrom = EmitLocation.Base; + @property({ + type: EmitLocation + }) + emitFrom = EmitLocation.Volume; @property _position = new Vec3(0, 0, 0); diff --git a/cocos/3d/framework/particle/particle-system-component.js b/cocos/3d/framework/particle/particle-system-component.js index 4e9168dc92..936c8494b5 100644 --- a/cocos/3d/framework/particle/particle-system-component.js +++ b/cocos/3d/framework/particle/particle-system-component.js @@ -179,6 +179,11 @@ export default class ParticleSystemComponent extends Component { constructor() { super(); + this.rateOverTime.constant = 10; + this.startLifetime.constant = 5; + this.startSize.constant = 1; + this.startSpeed.constant = 1; + // internal status this._isPlaying = false; this._isPaused = false; diff --git a/cocos/3d/framework/particle/renderer/particle-system-renderer.ts b/cocos/3d/framework/particle/renderer/particle-system-renderer.ts index c1354d4aac..030ff60024 100644 --- a/cocos/3d/framework/particle/renderer/particle-system-renderer.ts +++ b/cocos/3d/framework/particle/renderer/particle-system-renderer.ts @@ -145,6 +145,7 @@ export default class ParticleSystemRenderer extends RenderableComponent { this._model.setCapacity(this.particleSystem.capacity); this._model.setVertexAttributes(this._vertAttrs); this._model.node = this.node; + this._model.enabled = this.enabledInHierarchy; } } diff --git a/cocos/3d/framework/renderable-component.ts b/cocos/3d/framework/renderable-component.ts index 23e1c98c85..2389fe921a 100644 --- a/cocos/3d/framework/renderable-component.ts +++ b/cocos/3d/framework/renderable-component.ts @@ -60,15 +60,12 @@ export class RenderableComponent extends Component { * @param {Number} idx - Look for the material list number */ public getMaterial (idx: number, inEditor: boolean = false): Material | null { - if (idx < 0 || idx >= this._materials.length || this._materials[idx] == null) { - return null; - } - - const instantiated = Material.getInstantiatedMaterial(this._materials[idx]!, this, inEditor); + const mat = this._materials[idx]; + if (!mat) { return null; } + const instantiated = Material.getInstantiatedMaterial(mat, this, inEditor); if (instantiated !== this._materials[idx]) { this.setMaterial(instantiated, idx, !inEditor); } - return this._materials[idx]; } diff --git a/cocos/renderer/scene/model.ts b/cocos/renderer/scene/model.ts index af070d7b04..6dec210677 100644 --- a/cocos/renderer/scene/model.ts +++ b/cocos/renderer/scene/model.ts @@ -200,8 +200,10 @@ export class Model { return; } if (this._subModels[idx].material === mat) { - this.destroyPipelineState(mat!, this._matPSORecord.get(mat!)!); - this._matPSORecord.set(mat!, this.createPipelineState(mat!)); + if (mat) { + this.destroyPipelineState(mat!, this._matPSORecord.get(mat!)!); + this._matPSORecord.set(mat!, this.createPipelineState(mat!)); + } } else { if (this._subModels[idx].material) { this.releasePSO(this._subModels[idx].material!);