diff options
author | kbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-20 06:05:23 +0000 |
---|---|---|
committer | kbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-20 06:05:23 +0000 |
commit | e08b2652afb31bad466bc69d1f1aa3b80298361f (patch) | |
tree | 305527e71cd5d41394aab78e3607c9e8c31e7451 /o3d/samples/o3djs | |
parent | b2d346da57198822ddf59563a7c100eb6f6bc5a2 (diff) | |
download | chromium_src-e08b2652afb31bad466bc69d1f1aa3b80298361f.zip chromium_src-e08b2652afb31bad466bc69d1f1aa3b80298361f.tar.gz chromium_src-e08b2652afb31bad466bc69d1f1aa3b80298361f.tar.bz2 |
Added --convert-dds-to-png command line option to the COLLADA converter,
which causes all DDS textures to be outputted as PNGs. This required
changes to the serialization code to reconstitute cube map textures from
six separate images. Some bugs in the plugin were uncovered with this
change which have been worked around for the time being.
Pulled in libtxc_dxtn library for decompressing DXTn textures.
Tested by converting teapot with --convert-dds-to-png and running
helloworld.html and render-mode.html.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/1677002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45014 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/samples/o3djs')
-rw-r--r-- | o3d/samples/o3djs/serialization.js | 24 | ||||
-rw-r--r-- | o3d/samples/o3djs/texture.js | 60 |
2 files changed, 82 insertions, 2 deletions
diff --git a/o3d/samples/o3djs/serialization.js b/o3d/samples/o3djs/serialization.js index 619fce0..51e751d 100644 --- a/o3d/samples/o3djs/serialization.js +++ b/o3d/samples/o3djs/serialization.js @@ -198,7 +198,29 @@ o3djs.serialization.Deserializer = function(pack, json) { }, 'o3d.TextureCUBE': function(deserializer, json) { - if ('o3d.uri' in json.params) { + if ('o3d.negx_uri' in json.params) { + // Cube map comprised of six separate textures. + var param_names = [ + 'o3d.posx_uri', + 'o3d.negx_uri', + 'o3d.posy_uri', + 'o3d.negy_uri', + 'o3d.posz_uri', + 'o3d.negz_uri' + ]; + var rawDataArray = []; + for (var i = 0; i < param_names.length; i++) { + var uri = json.params[param_names[i]].value; + var rawData = deserializer.archiveInfo.getFileByURI(uri); + if (!rawData) { + throw 'Could not find texture ' + uri + ' in the archive'; + } + rawDataArray.push(rawData); + } + // Cube map faces should not be flipped. + return o3djs.texture.createTextureFromRawDataArray( + pack, rawDataArray, true, false); + } else if ('o3d.uri' in json.params) { var uri = json.params['o3d.uri'].value; var rawData = deserializer.archiveInfo.getFileByURI(uri); if (!rawData) { diff --git a/o3d/samples/o3djs/texture.js b/o3d/samples/o3djs/texture.js index 5041dde..8232d26 100644 --- a/o3d/samples/o3djs/texture.js +++ b/o3d/samples/o3djs/texture.js @@ -119,6 +119,64 @@ o3djs.texture.createTextureFromRawData = function( }; /** + * Creates a texture from an array of RawData objects. This is mainly useful for + * creating a cube map out of six separate textures. + * @param {!o3d.Pack} pack The pack to create the texture in. + * @param {!Array.<!o3d.RawData>} rawDataArray The array of raw data objects to + * create the texture from. If these represent the six faces of a cube map, + * they must be in the order FACE_POSITIVE_X, FACE_NEGATIVE_X, + * FACE_POSITIVE_Y, FACE_NEGATIVE_Y, FACE_POSITIVE_Z, FACE_NEGATIVE_Z + * @param {boolean} opt_generateMips Whether or not to generate mips. Note, mips + * can not be generated for DXT textures although they will be loaded if they + * exist in the RawData. + * @param {boolean} opt_flip Whether or not to flip the texture. Most DCC tools + * Like Maya, Max, etc expect the textures to be flipped. Note that only + * 2D (image) textures will be flipped. Cube textures will not be flipped. + * Default = true. + * @param {number} opt_maxWidth The maximum width of the texture. If the RawData + * is larger than this size it will be scaled down to this size. Note that + * DXT format textures can not be scaled. Default = 2048. + * @param {number} opt_maxHeight The maximum width of the texture. If the + * RawData is larger than this size it will be scaled down to this size. Note + * that DXT format textures can not be scaled. Default = 2048. + * @return {!o3d.Texture} The created texture. + */ +o3djs.texture.createTextureFromRawDataArray = function( + pack, + rawDataArray, + opt_generateMips, + opt_flip, + opt_maxWidth, + opt_maxHeight) { + // Make bitmaps from the raw data. + var bitmaps = []; + for (var ii = 0; ii < rawDataArray.length; ++ii) { + bitmaps = bitmaps.concat(pack.createBitmapsFromRawData(rawDataArray[ii])); + } + if (opt_flip || typeof opt_flip === 'undefined') { + for (var ii = 0; ii < bitmaps.length; ++ii) { + var bitmap = bitmaps[ii]; + if (bitmap.semantic == o3djs.base.o3d.Bitmap.IMAGE) { + bitmaps[ii].flipVertically(); + } + } + } + + // Create a texture from the bitmaps. + // TODO(kbr): use createCubeTextureFrom6Bitmaps instead; bugs in the plugin + // currently prevent this. + var texture = o3djs.texture.createTextureFromBitmaps( + pack, bitmaps, opt_generateMips); + + // Delete the bitmaps. + for (var ii = 0; ii < bitmaps.length; ++ii) { + pack.removeObject(bitmaps[ii]); + } + + return texture; +}; + +/** * Returns whether or not a given texture format can be scaled. * @param {!o3d.Texture.Format} format The format to check. * @return {boolean} True if you can scale and make mips for the given format. @@ -214,7 +272,7 @@ o3djs.texture.createTextureFromBitmaps = function( /** * Creates a TextureCUBE from 6 bitmaps. The bitmaps do not have to be the same - * size thought they do have to be the same format. + * size though they do have to be the same format. * * @param {!o3d.Pack} pack The pack to create the texture in. * @param {number} edgeLength The size of the cubemap. |