From 70c8e97a69ef8806b1812b2cd0ebe831f3792cb6 Mon Sep 17 00:00:00 2001 From: "gman@google.com" Date: Tue, 1 Sep 2009 04:21:40 +0000 Subject: Update samples to use more utility functions where appropriate. A few places used pseudoRandom. That is in math.js now so they use that. Other places there is now o3djs.material.createBasicMaterial and o3djs.material.createMaterialFromFile that save 10-20 lines per sample. This CL will require new reference images. There are 2 other things I'd like to consider. #1) Changing every sample that uses shaders/texture-only.shader to use o3djs.material.createConstantMaterial or some variation. The problem with o3djs.material.createConstantMaterial is it requires you pass it a texture if you want a constant textured material. All the samples create the material first, then later add the texture. So, I could add a new o3djs.material.createTextureOnlyMaterial. At the same time that would mean changing those samples from setting stuff on 'texSampler0' to 'emissive' #2) I'd like to change the shader builder so it stops adding "Sampler" to textured materials. As it is if the material uses a color it makes the param called "diffuse" but if it's a texture it makes it "diffuseSampler". That sucks because it means the code has to do crap like var param = material.getParam('diffuse'); if (param) { // it's a color } else { param = material.getParam('diffuseSampler'); if (param) { // it's a texture. } } If we stopped that silliness we could just do var param = material.getParam('diffuse'); if (param) { if (param.isA('o3d.ParamTexture')) { // it's textured. } else { // it's not. } } Unfortunately to fix this requires changing the o3dConverter as well since it uses those conventions. Should we do this? Review URL: http://codereview.chromium.org/182024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25015 0039d316-1c4b-4281-b951-d872f2087c98 --- o3d/samples/primitives.html | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) (limited to 'o3d/samples/primitives.html') diff --git a/o3d/samples/primitives.html b/o3d/samples/primitives.html index 4cc3935..89337a9 100644 --- a/o3d/samples/primitives.html +++ b/o3d/samples/primitives.html @@ -49,7 +49,7 @@ o3djs.require('o3djs.util'); o3djs.require('o3djs.math'); o3djs.require('o3djs.rendergraph'); o3djs.require('o3djs.primitives'); -o3djs.require('o3djs.effect'); +o3djs.require('o3djs.material'); // global variables var g_o3dElement; @@ -58,8 +58,6 @@ var g_o3d; var g_math; var g_pack; var g_viewInfo; - -var g_lightPosition = [5, 5, 7]; var g_eyePosition = [3, 4, 14]; /** @@ -131,28 +129,14 @@ function initContext() { } /** - * Creates a phong material based on the given single color. + * Creates a material based on the given single color. * @param {Array} baseColor An array with 4 entries, the R,G,B, and A components * of a color. - * @return {Material} A phong material whose overall pigment is baseColor. + * @return {Material} A material whose overall pigment is baseColor. */ -function createPhongMaterial(baseColor) { +function createMaterial(baseColor) { // Create a new, empty Material object. - var material = g_pack.createObject('Material'); - - o3djs.effect.attachStandardShader( - g_pack, material, g_lightPosition, 'phong'); - - material.drawList = g_viewInfo.performanceDrawList; - - // Assign parameters to the phong material. - material.getParam('emissive').value = [0, 0, 0, 1]; - material.getParam('ambient').value = g_math.mulScalarVector(0.1, baseColor); - material.getParam('diffuse').value = g_math.mulScalarVector(0.9, baseColor); - material.getParam('specular').value = [.2, .2, .2, 1]; - material.getParam('shininess').value = 20; - - return material; + return o3djs.material.createBasicMaterial(g_pack, g_viewInfo, baseColor); } /** @@ -162,19 +146,19 @@ function createPhongMaterial(baseColor) { function createShapes() { var cube = o3djs.primitives.createCube( g_pack, - createPhongMaterial([0,1,0,1]), // A green phong-shaded material. + createMaterial([0,1,0,1]), // A green phong-shaded material. Math.sqrt(2)); // The length of each side of the cube. var sphere = o3djs.primitives.createSphere( g_pack, - createPhongMaterial([1,0,0,1]), + createMaterial([1,0,0,1]), 1.0, // Radius of the sphere. 30, // Number of meridians. 20); // Number of parallels. var cylinder = o3djs.primitives.createCylinder( g_pack, - createPhongMaterial([1,0,1,1]), + createMaterial([1,0,1,1]), 0.5, // Radius. 1.5, // Height. 20, // Number of radial subdivisions. @@ -182,7 +166,7 @@ function createShapes() { var truncatedCone = o3djs.primitives.createTruncatedCone( g_pack, - createPhongMaterial([0,0,1,1]), + createMaterial([0,0,1,1]), 0.3, // Bottom radius. 0.5, // Top radius. 1.5, // Height. @@ -191,7 +175,7 @@ function createShapes() { var cone = o3djs.primitives.createTruncatedCone( g_pack, - createPhongMaterial([0,1,0,1]), + createMaterial([0,1,0,1]), 0.5, // Bottom radius. 0.0, // Top radius. 1.5, // Height. @@ -200,7 +184,7 @@ function createShapes() { var plane = o3djs.primitives.createPlane( g_pack, - createPhongMaterial([0,1,1,1]), + createMaterial([0,1,1,1]), 1, // Width. 1.618, // Depth. 3, // Horizontal subdivisions. @@ -217,13 +201,13 @@ function createShapes() { var prism = o3djs.primitives.createPrism( g_pack, - createPhongMaterial([1,1,0,1]), + createMaterial([1,1,0,1]), polygon, // The profile polygon to be extruded. 1); // The depth of the extrusion. var disc = o3djs.primitives.createDisc( g_pack, - createPhongMaterial([1,0,0,1]), + createMaterial([1,0,0,1]), 1, // Radius. 7, // Divisions. 2, // Stacks (optional). -- cgit v1.1