diff options
Diffstat (limited to 'o3d/samples/o3djs/material.js')
-rw-r--r-- | o3d/samples/o3djs/material.js | 68 |
1 files changed, 55 insertions, 13 deletions
diff --git a/o3d/samples/o3djs/material.js b/o3d/samples/o3djs/material.js index a2aa67c..7ba3c8e 100644 --- a/o3d/samples/o3djs/material.js +++ b/o3d/samples/o3djs/material.js @@ -200,6 +200,30 @@ o3djs.material.prepareMaterials = function(pack, }; /** + * Builds a standard effect for a given material. + * If the material already has an effect, none is created. + * @param {!o3d.Pack} pack Pack to manage created objects. + * @param {!o3d.Material} material The material for which to create an + * effect. + * @param {string} effectType Type of effect to create ('phong', 'lambert', + * 'constant'). + * + * @see o3djs.effect.attachStandardShader + */ +o3djs.material.attachStandardEffectEx = function(pack, + material, + effectType) { + if (!material.effect) { + if (!o3djs.effect.attachStandardShader(pack, + material, + [0, 0, 0], + effectType)) { + throw 'Could not attach a standard effect'; + } + } +}; + +/** * Builds a standard effect for a given material. The position of the * default light is set to the view position. If the material already has * an effect, none is created. @@ -223,14 +247,13 @@ o3djs.material.attachStandardEffect = function(pack, o3djs.math.inverse(viewInfo.drawContext.view)); if (!o3djs.effect.attachStandardShader(pack, material, - lightPos, + lightPos, // TODO(gman): remove this effectType)) { throw 'Could not attach a standard effect'; } } }; - /** * Prepares all the materials in the given pack by setting their * drawList. @@ -341,21 +364,16 @@ o3djs.material.createBasicMaterial = function(pack, * useful for debugging shapes and 2d UI elements. * * @param {!o3d.Pack} pack Pack to manage created objects. - * @param {!o3djs.rendergraph.ViewInfo} viewInfo as returned from - * o3djs.rendergraph.createBasicView. + * @param {!o3d.DrawList} drawList The DrawList for the material. * @param {(!o3djs.math.Vector4|!o3d.Texture)} colorOrTexture Either a color in * the format [r, g, b, a] or an O3D texture. - * @param {boolean} opt_transparent Whether or not the material is transparent. - * Defaults to false. * @return {!o3d.Material} The created material. */ -o3djs.material.createConstantMaterial = function(pack, - viewInfo, - colorOrTexture, - opt_transparent) { +o3djs.material.createConstantMaterialEx = function(pack, + drawList, + colorOrTexture) { var material = pack.createObject('Material'); - material.drawList = opt_transparent ? viewInfo.zOrderedDrawList : - viewInfo.performanceDrawList; + material.drawList = drawList; // If it has a length assume it's a color, otherwise assume it's a texture. if (colorOrTexture.length) { @@ -367,12 +385,36 @@ o3djs.material.createConstantMaterial = function(pack, sampler.texture = colorOrTexture; } - o3djs.material.attachStandardEffect(pack, material, viewInfo, 'constant'); + o3djs.material.attachStandardEffectEx(pack, material, 'constant'); return material; }; /** + * This function creates a constant material. No lighting. It is especially + * useful for debugging shapes and 2d UI elements. + * + * @param {!o3d.Pack} pack Pack to manage created objects. + * @param {!o3djs.rendergraph.ViewInfo} viewInfo as returned from + * o3djs.rendergraph.createBasicView. + * @param {(!o3djs.math.Vector4|!o3d.Texture)} colorOrTexture Either a color in + * the format [r, g, b, a] or an O3D texture. + * @param {boolean} opt_transparent Whether or not the material is transparent. + * Defaults to false. + * @return {!o3d.Material} The created material. + */ +o3djs.material.createConstantMaterial = function(pack, + viewInfo, + colorOrTexture, + opt_transparent) { + return o3djs.material.createConstantMaterialEx( + pack, + opt_transparent ? viewInfo.zOrderedDrawList : + viewInfo.performanceDrawList, + colorOrTexture) +}; + +/** * This function creates 2 color procedureal texture material. * * @see o3djs.material.createBasicMaterial |