summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Payne (Vir Linden) <vir@lindenlab.com>2011-04-06 18:20:32 -0400
committerBrad Payne (Vir Linden) <vir@lindenlab.com>2011-04-06 18:20:32 -0400
commit9e232094a91254a05b7caa74a0ccac23aa69439f (patch)
treec984f2202ef25ac4d8c71f8ce237f11d15bac913
parente4819d9b22deebf080ca262a5a110a0ddfaee672 (diff)
parent8374b50ae36e33872c93d054037a582887363df6 (diff)
merge
-rw-r--r--indra/newview/CMakeLists.txt4
-rw-r--r--indra/newview/llfloaterimportcollada.cpp1112
-rw-r--r--indra/newview/llfloaterimportcollada.h136
-rw-r--r--indra/newview/llmeshreduction.cpp272
-rw-r--r--indra/newview/llmeshreduction.h50
-rw-r--r--indra/newview/llphysicsmotion.cpp2
-rw-r--r--indra/newview/llpolymesh.cpp122
7 files changed, 49 insertions, 1649 deletions
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index 4439018456..3ed10c08ab 100644
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -191,7 +191,6 @@ set(viewer_SOURCE_FILES
llfloaterhelpbrowser.cpp
llfloaterhud.cpp
llfloaterimagepreview.cpp
- llfloaterimportcollada.cpp
llfloaterinspect.cpp
llfloaterinventory.cpp
llfloaterjoystick.cpp
@@ -308,7 +307,6 @@ set(viewer_SOURCE_FILES
llmemoryview.cpp
llmenucommands.cpp
llmeshrepository.cpp
- llmeshreduction.cpp
llmimetypes.cpp
llmorphview.cpp
llmoveview.cpp
@@ -740,7 +738,6 @@ set(viewer_HEADER_FILES
llfloaterhelpbrowser.h
llfloaterhud.h
llfloaterimagepreview.h
- llfloaterimportcollada.h
llfloaterinspect.h
llfloaterinventory.h
llfloaterjoystick.h
@@ -857,7 +854,6 @@ set(viewer_HEADER_FILES
llmemoryview.h
llmenucommands.h
llmeshrepository.h
- llmeshreduction.h
llmimetypes.h
llmorphview.h
llmoveview.h
diff --git a/indra/newview/llfloaterimportcollada.cpp b/indra/newview/llfloaterimportcollada.cpp
deleted file mode 100644
index 20907e899e..0000000000
--- a/indra/newview/llfloaterimportcollada.cpp
+++ /dev/null
@@ -1,1112 +0,0 @@
-/**
- * @file llfloaterimportcollada.cpp
- *
- * $LicenseInfo:firstyear=2001&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-
-#include "llviewerprecompiledheaders.h"
-
-#if 0 //DEPRECATED
-
-#include "llfloaterimportcollada.h"
-
-#include "dae.h"
-//#include "dom.h"
-#include "dom/domAsset.h"
-#include "dom/domBind_material.h"
-#include "dom/domConstants.h"
-#include "dom/domEffect.h"
-#include "dom/domGeometry.h"
-#include "dom/domInstance_geometry.h"
-#include "dom/domInstance_material.h"
-#include "dom/domInstance_node.h"
-#include "dom/domInstance_effect.h"
-#include "dom/domMaterial.h"
-#include "dom/domMatrix.h"
-#include "dom/domNode.h"
-#include "dom/domProfile_COMMON.h"
-#include "dom/domRotate.h"
-#include "dom/domScale.h"
-#include "dom/domTranslate.h"
-#include "dom/domVisual_scene.h"
-
-#include "llagent.h"
-#include "llassetuploadresponders.h"
-#include "lleconomy.h"
-#include "llfloaterperms.h"
-#include "llfloaterreg.h"
-#include "llsdutil.h"
-#include "llsdutil_math.h"
-#include "llselectmgr.h"
-#include "llvfile.h"
-#include "llvfs.h"
-#include "llviewermenufile.h"
-#include "llviewerregion.h"
-#include "llvolumemessage.h"
-#include "llmodel.h"
-#include "llmeshreduction.h"
-#include "material_codes.h"
-
-//
-// floater
-//
-
-LLFloaterImportCollada::LLFloaterImportCollada(const LLSD& key)
- : LLFloater(key)
-{
-}
-
-
-BOOL LLFloaterImportCollada::postBuild()
-{
- if (!LLFloater::postBuild())
- {
- return FALSE;
- }
-
- childSetCommitCallback("ok", LLImportCollada::onCommitOK, this);
- childSetCommitCallback("cancel", LLImportCollada::onCommitCancel, this);
-
- setStatusIdle();
- setAssetCount(0,0);
- enableOK(TRUE);
-
- return TRUE;
-}
-
-
-void LLFloaterImportCollada::setAssetCount(S32 mesh_count, S32 texture_count)
-{
- childSetTextArg("mesh count", "[COUNT]", llformat("%d", mesh_count));
- childSetTextArg("texture count", "[COUNT]", llformat("%d", texture_count));
-}
-
-void LLFloaterImportCollada::setStatusAssetUploading(std::string asset_name)
-{
- LLUIString uploading = getString("status_uploading");
- uploading.setArg("[NAME]", asset_name);
- childSetTextArg("status", "[STATUS]", uploading.getString());
-}
-
-void LLFloaterImportCollada::setStatusCreatingPrim(std::string prim_name)
-{
- LLUIString creating = getString("status_creating");
- creating.setArg("[NAME]", prim_name);
- childSetTextArg("status", "[STATUS]", creating.getString());
-}
-
-void LLFloaterImportCollada::setStatusIdle()
-{
- childSetTextArg("status", "[STATUS]", getString("status_idle"));
-}
-
-void LLFloaterImportCollada::enableOK(BOOL enable)
-{
- childSetEnabled("ok", enable);
-}
-
-
-//
-// misc helpers
-//
-
-
-// why oh why do forbid matrix multiplication in our llmath library?
-LLMatrix4 matrix_multiply(LLMatrix4 a, LLMatrix4 b)
-{
- a *= b;
-
- return a;
-}
-
-// why oh why does colladadom not provide such things?
-daeElement* getFirstChild(daeElement* parent)
-{
- daeTArray< daeSmartRef<daeElement> > children = parent->getChildren();
-
- if (children.getCount() > 0)
- {
- return children[0];
- }
- else
- {
- return NULL;
- }
-}
-
-// why oh why does colladadom not provide such things?
-daeElement* getNextSibling(daeElement* child)
-{
- daeElement* parent = child->getParent();
-
- if (parent == NULL)
- {
- // must be root, root has no siblings
- return NULL;
- }
-
- daeElement* sibling = NULL;
-
- daeTArray< daeSmartRef<daeElement> > children = parent->getChildren();
- for (S32 i = 0; i < children.getCount(); i++)
- {
- if (child == children[i])
- {
- if ((i+1) < children.getCount())
- {
- sibling = children[i+1];
- }
- }
- }
-
- return sibling;
-}
-
-// try to get a decent label for this element
-std::string getElementLabel(daeElement *element)
-{
- // if we have a name attribute, use it
- std::string name = element->getAttribute("name");
- if (name.length())
- {
- return name;
- }
-
- // if we have an ID attribute, use it
- if (element->getID())
- {
- return std::string(element->getID());
- }
-
- // if we have a parent, use it
- daeElement* parent = element->getParent();
- if (parent)
- {
- // if parent has a name, use it
- std::string name = parent->getAttribute("name");
- if (name.length())
- {
- return name;
- }
-
- // if parent has an ID, use it
- if (parent->getID())
- {
- return std::string(parent->getID());
- }
- }
-
- // try to use our type
- daeString element_name = element->getElementName();
- if (element_name)
- {
- return std::string(element_name);
- }
-
- // if all else fails, use "object"
- return std::string("object");
-}
-
-LLColor4 getDaeColor(daeElement* element)
-{
- LLColor4 value;
- domCommon_color_or_texture_type_complexType::domColor* color =
- daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(element->getDescendant("color"));
- if (color)
- {
- domFx_color_common domfx_color = color->getValue();
- value = LLColor4(domfx_color[0], domfx_color[1], domfx_color[2], domfx_color[3]);
- }
-
- return value;
-}
-
-LLTextureEntry profileToTextureEntry(domProfile_COMMON* material)
-{
- LLTextureEntry te;
-
- te.setID(LLUUID("5748decc-f629-461c-9a36-a35a221fe21f")); // blank texture
- daeElement* diffuse = material->getDescendant("diffuse");
- if (diffuse)
- {
- te.setColor(LLColor3(0.1f, 0.9f, 1.0f));
-
- domCommon_color_or_texture_type_complexType::domTexture* texture =
- daeSafeCast<domCommon_color_or_texture_type_complexType::domTexture>(diffuse->getDescendant("texture"));
- if (texture)
- {
- domCommon_newparam_type_Array newparams = material->getNewparam_array();
- for (S32 i = 0; i < newparams.getCount(); i++)
- {
- domFx_surface_common* surface = newparams[i]->getSurface();
- if (surface)
- {
- domFx_surface_init_common* init = surface->getFx_surface_init_common();
- if (init)
- {
- domFx_surface_init_from_common_Array init_from = init->getInit_from_array();
-
- if (init_from.getCount() > 0)
- {
- daeElement* image = init_from[0]->getValue().getElement();
- if (image)
- {
- LLUUID texture_asset = LLImportColladaAssetCache::getInstance()->getAssetForDaeElement(image);
-
- if (texture_asset.notNull())
- {
- te.setID(texture_asset);
- te.setColor(LLColor3(1,1,1));
- }
- }
- }
- }
- }
- }
- }
-
- domCommon_color_or_texture_type_complexType::domColor* color =
- daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(diffuse->getDescendant("color"));
- if (color)
- {
- domFx_color_common domfx_color = color->getValue();
- LLColor4 value = LLColor4(domfx_color[0], domfx_color[1], domfx_color[2], domfx_color[3]);
- te.setColor(value);
- }
- }
-
- daeElement* emission = material->getDescendant("emission");
- if (emission)
- {
- LLColor4 emission_color = getDaeColor(emission);
- if (((emission_color[0] + emission_color[1] + emission_color[2]) / 3.0) > 0.25)
- {
- te.setFullbright(TRUE);
- }
- }
-
- return te;
-}
-
-std::vector<LLTextureEntry> getMaterials(LLModel* model, domInstance_geometry* instance_geo)
-{
- std::vector<LLTextureEntry> texture_entries;
- for (int i = 0; i < model->mMaterialList.size(); i++)
- {
- LLTextureEntry texture_entry;
-
- domInstance_material* instance_mat = NULL;
-
- domBind_material::domTechnique_common* technique =
- daeSafeCast<domBind_material::domTechnique_common>(instance_geo->getDescendant(daeElement::matchType(domBind_material::domTechnique_common::ID())));
-
- if (technique)
- {
- daeTArray< daeSmartRef<domInstance_material> > inst_materials = technique->getChildrenByType<domInstance_material>();
- for (int j = 0; j < inst_materials.getCount(); j++)
- {
- std::string symbol(inst_materials[j]->getSymbol());
-
- if (symbol == model->mMaterialList[i]) // found the binding
- {
- instance_mat = inst_materials[j];
- }
- }
- }
-
- if (instance_mat)
- {
- domMaterial* material = daeSafeCast<domMaterial>(instance_mat->getTarget().getElement());
- if (material)
- {
- domInstance_effect* instance_effect =
- daeSafeCast<domInstance_effect>(material->getDescendant(daeElement::matchType(domInstance_effect::ID())));
- if (instance_effect)
- {
- domEffect* effect = daeSafeCast<domEffect>(instance_effect->getUrl().getElement());
- if (effect)
- {
- domProfile_COMMON* profile =
- daeSafeCast<domProfile_COMMON>(effect->getDescendant(daeElement::matchType(domProfile_COMMON::ID())));
- if (profile)
- {
- texture_entry = profileToTextureEntry(profile);
- }
- }
- }
- }
- }
-
- texture_entries.push_back(texture_entry);
- }
-
- return texture_entries;
-}
-
-LLTextureEntry instanceGeoToTextureEntry(domInstance_geometry* instance_geo)
-{
- LLTextureEntry te;
- domInstance_material* instance_mat =
- daeSafeCast<domInstance_material>(instance_geo->getDescendant(daeElement::matchType(domInstance_material::ID())));
- if (instance_mat)
- {
- }
-
- return te;
-}
-
-
-
-// responder for asset uploads
-// does all the normal stuff followed by a notification to continue importing
-// WARNING - currently unused - TODO
-class LLColladaNewAgentInventoryResponder : public LLNewAgentInventoryResponder
-{
- LLColladaNewAgentInventoryResponder(const LLSD& post_data,
- const LLUUID& vfile_id,
- LLAssetType::EType asset_type)
- : LLNewAgentInventoryResponder(post_data, vfile_id, asset_type)
- {
- }
- LLColladaNewAgentInventoryResponder(const LLSD& post_data,
- const std::string& file_name,
- LLAssetType::EType asset_type)
- : LLNewAgentInventoryResponder(post_data, file_name, asset_type)
- {
- }
-
- virtual void uploadComplete(const LLSD& content)
- {
- LLNewAgentInventoryResponder::uploadComplete(content);
- }
-
-};
-
-BOOL LLImportColladaAssetCache::uploadImageAsset(domImage* image)
-{
- // we only support init_from now - embedded data will come later
- domImage::domInit_from* init = image->getInit_from();
- if (!init)
- {
- return FALSE;
- }
-
- std::string filename = cdom::uriToNativePath(init->getValue().str());
-
- std::string name = getElementLabel(image);
-
- LLUUID transaction_id = upload_new_resource(filename, name, std::string(),
- 0, LLFolderType::FT_TEXTURE, LLInventoryType::IT_TEXTURE,
- LLFloaterPerms::getNextOwnerPerms(), LLFloaterPerms::getGroupPerms(),
- LLFloaterPerms::getEveryonePerms(),
- name, NULL,
- LLGlobalEconomy::Singleton::getInstance()->getPriceUpload(), NULL);
-
- if (transaction_id.isNull())
- {
- llwarns << "cannot upload " << filename << llendl;
-
- return FALSE;
- }
-
- mTransactionMap[transaction_id] = image;
-
- LLFloaterReg::findTypedInstance<LLFloaterImportCollada>("import_collada")->setStatusAssetUploading(name);
-
- return TRUE;
-}
-
-
-
-//
-// asset cache -
-// uploads assets and provides a map from collada element to asset
-//
-
-
-
-BOOL LLImportColladaAssetCache::uploadMeshAsset(domMesh* mesh)
-{
- LLPointer<LLModel> model = LLModel::loadModelFromDomMesh(mesh);
-
- if (model->getNumVolumeFaces() == 0)
- {
- return FALSE;
- }
-
- // generate LODs
-
-
- std::vector<LLPointer<LLModel> > lods;
- lods.push_back(model);
- S32 triangle_count = model->getNumTriangles();
-
- for (S32 i = 0; i < 4; i++)
- {
- LLPointer<LLModel> last_model = lods.back();
-
- S32 triangle_target = (S32)(triangle_count / pow(3.f, i + 1));
- if (triangle_target > 16)
- {
- LLMeshReduction reduction;
- LLPointer<LLModel> new_model = reduction.reduce(model, triangle_target, LLMeshReduction::TRIANGLE_BUDGET);
- lods.push_back(new_model);
- }
- else
- {
- lods.push_back(last_model);
- }
- }
-
- // write model to temp file
-
- std::string filename = gDirUtilp->getTempFilename();
- LLModel::writeModel(
- filename,
- lods[4],
- lods[0],
- lods[1],
- lods[2],
- lods[3],
- lods[4]->mConvexHullDecomp);
-
-
- // copy file to VFS
-
- LLTransactionID tid;
- tid.generate();
- LLAssetID uuid = tid.makeAssetID(gAgent.getSecureSessionID()); // create asset uuid
-
- S32 file_size;
- LLAPRFile infile ;
- infile.open(filename, LL_APR_RB, NULL, &file_size);
-
- if (infile.getFileHandle())
- {
- LLVFile file(gVFS, uuid, LLAssetType::AT_MESH, LLVFile::WRITE);
-
- file.setMaxSize(file_size);
-
- const S32 buf_size = 65536;
- U8 copy_buf[buf_size];
- while ((file_size = infile.read(copy_buf, buf_size)))
- {
- file.write(copy_buf, file_size);
- }
- }
-
-
- std::string name = getElementLabel(mesh);
-
- upload_new_resource(tid, LLAssetType::AT_MESH, name, std::string(), 0,LLFolderType::FT_MESH, LLInventoryType::IT_MESH,
- LLFloaterPerms::getNextOwnerPerms(), LLFloaterPerms::getGroupPerms(), LLFloaterPerms::getEveryonePerms(),
- name, NULL,
- LLGlobalEconomy::Singleton::getInstance()->getPriceUpload(), NULL);
-
- LLFile::remove(filename);
-
- mTransactionMap[uuid] = mesh;
-
- LLFloaterReg::findTypedInstance<LLFloaterImportCollada>("import_collada")->setStatusAssetUploading(name);
-
- return TRUE;
-}
-
-
-// called by the mesh asset upload responder to indicate the mesh asset has been uploaded
-void LLImportColladaAssetCache::assetUploaded(LLUUID transaction_uuid, LLUUID asset_uuid, BOOL success)
-{
- std::map<LLUUID, daeElement*>::iterator i = mTransactionMap.find(transaction_uuid);
-
- if (i != mTransactionMap.end())
- {
- daeElement* element = i->second;
-
-
- if (success)
- {
- mAssetMap[element] = asset_uuid;
- }
- else // failure
- {
- // if failed, put back on end of queue
- mUploadsPending.push_back(element);
- }
-
- mUploads--;
- uploadNextAsset();
- }
-}
-
-const S32 MAX_CONCURRENT_UPLOADS = 5;
-
-void LLImportColladaAssetCache::uploadNextAsset()
-{
- while ((mUploadsPending.size() > 0) && (mUploads < MAX_CONCURRENT_UPLOADS))
- {
- BOOL upload_started = FALSE;
-
- daeElement* element = mUploadsPending.back();
- mUploadsPending.pop_back();
-
- domImage* image = daeSafeCast<domImage>(element);
- if (image)
- {
- upload_started = uploadImageAsset(image);
- }
-
- domMesh* mesh = daeSafeCast<domMesh>(element);
- if (mesh)
- {
- upload_started = uploadMeshAsset(mesh);
- }
-
- if (upload_started)
- {
- mUploads++;
- }
-
- }
-
- if ((mUploadsPending.size() == 0) && (mUploads == 0))
- {
- // we're done! notify the importer
- LLImportCollada::getInstance()->assetsUploaded();
- }
-
- updateCount();
-}
-
-
-void LLImportColladaAssetCache::clear()
-{
- mDAE = NULL;
- mTransactionMap.clear();
- mAssetMap.clear();
- mUploadsPending.clear();
- mUploads = 0;
-}
-
-void LLImportColladaAssetCache::endImport()
-{
- clear();
-}
-
-void LLImportColladaAssetCache::updateCount()
-{
- S32 mesh_count = 0;
- S32 image_count = 0;
-
- for (S32 i = 0; i < mUploadsPending.size(); i++)
- {
- daeElement* element = mUploadsPending[i];
-
- if (daeSafeCast<domMesh>(element))
- {
- mesh_count++;
- }
-
- if (daeSafeCast<domImage>(element))
- {
- image_count++;
- }
- }
-
- LLFloaterReg::findTypedInstance<LLFloaterImportCollada>("import_collada")->setAssetCount(mesh_count, image_count);
-}
-
-void LLImportColladaAssetCache::prepareForUpload(DAE* dae)
-{
- clear();
- mDAE = dae;
-
- daeDatabase* db = mDAE->getDatabase();
-
- S32 mesh_count = db->getElementCount(NULL, COLLADA_TYPE_MESH);
- for (S32 i = 0; i < mesh_count; i++)
- {
- domMesh* mesh = NULL;
-
- db->getElement((daeElement**) &mesh, i, NULL, COLLADA_TYPE_MESH);
-
- mUploadsPending.push_back(mesh);
- }
-
-
- S32 image_count = db->getElementCount(NULL, COLLADA_TYPE_IMAGE);
- for (S32 i = 0; i < image_count; i++)
- {
- domImage* image = NULL;
- db->getElement((daeElement**) &image, i, NULL, COLLADA_TYPE_IMAGE);
-
- mUploadsPending.push_back(image);
- }
-
- updateCount();
-}
-
-
-void LLImportColladaAssetCache::uploadAssets()
-{
- uploadNextAsset();
-}
-
-
-LLUUID LLImportColladaAssetCache::getAssetForDaeElement(daeElement* element)
-{
- LLUUID id;
-
- std::map<daeElement*, LLUUID>::iterator i = mAssetMap.find(element);
- if (i != mAssetMap.end())
- {
- id = i->second;
- }
-
- return id;
-}
-
-
-//
-// importer
-//
-
-
-
-LLImportCollada::LLImportCollada()
-{
- mIsImporting = FALSE;
-}
-
-
-
-
-void LLImportCollada::appendObjectAsset(domInstance_geometry* instance_geo)
-{
- domGeometry* geo = daeSafeCast<domGeometry>(instance_geo->getUrl().getElement());
- if (!geo)
- {
- llwarns << "cannot find geometry" << llendl;
- return;
- }
-
- domMesh* mesh = daeSafeCast<domMesh>(geo->getDescendant(daeElement::matchType(domMesh::ID())));
- if (!mesh)
- {
- llwarns << "could not find mesh" << llendl;
- return;
- }
-
- LLUUID mesh_asset = LLImportColladaAssetCache::getInstance()->getAssetForDaeElement(mesh);
- if (mesh_asset.isNull())
- {
- llwarns << "no mesh asset, skipping" << llendl;
- return;
- }
-
- // load the model
- LLModel* model = LLModel::loadModelFromDomMesh(mesh);
-
-
-
-
- // get our local transformation
- LLMatrix4 transformation = mStack.front().transformation;
-
- // adjust the transformation to compensate for mesh normalization
- LLVector3 mesh_scale_vector;
- LLVector3 mesh_translation_vector;
- model->getNormalizedScaleTranslation(mesh_scale_vector, mesh_translation_vector);
- LLMatrix4 mesh_translation;
- mesh_translation.setTranslation(mesh_translation_vector);
- transformation = matrix_multiply(mesh_translation, transformation);
- LLMatrix4 mesh_scale;
- mesh_scale.initScale(mesh_scale_vector);
- transformation = matrix_multiply(mesh_scale, transformation);
-
- // check for reflection
- BOOL reflected = (transformation.determinant() < 0);
-
- // compute position
- LLVector3 position = LLVector3(0, 0, 0) * transformation;
-
- // compute scale
- LLVector3 x_transformed = LLVector3(1, 0, 0) * transformation - position;
- LLVector3 y_transformed = LLVector3(0, 1, 0) * transformation - position;
- LLVector3 z_transformed = LLVector3(0, 0, 1) * transformation - position;
- F32 x_length = x_transformed.normalize();
- F32 y_length = y_transformed.normalize();
- F32 z_length = z_transformed.normalize();
- LLVector3 scale = LLVector3(x_length, y_length, z_length);
-
- // adjust for "reflected" geometry
- LLVector3 x_transformed_reflected = x_transformed;
- if (reflected)
- {
- x_transformed_reflected *= -1.0;
- }
-
- // compute rotation
- LLMatrix3 rotation_matrix;
- rotation_matrix.setRows(x_transformed_reflected, y_transformed, z_transformed);
- LLQuaternion quat_rotation = rotation_matrix.quaternion();
- quat_rotation.normalize(); // the rotation_matrix might not have been orthoginal. make it so here.
- LLVector3 euler_rotation;
- quat_rotation.getEulerAngles(&euler_rotation.mV[VX], &euler_rotation.mV[VY], &euler_rotation.mV[VZ]);
-
-
- //
- // build parameter block to construct this prim
- //
-
- LLSD object_params;
-
- // create prim
-
- // set volume params
- LLVolumeParams volume_params;
- volume_params.setType( LL_PCODE_PROFILE_SQUARE, LL_PCODE_PATH_LINE );
- volume_params.setBeginAndEndS( 0.f, 1.f );
- volume_params.setBeginAndEndT( 0.f, 1.f );
- volume_params.setRatio ( 1, 1 );
- volume_params.setShear ( 0, 0 );
- U8 sculpt_type = LL_SCULPT_TYPE_MESH;
- if (reflected)
- {
- sculpt_type |= LL_SCULPT_FLAG_MIRROR;
- }
- volume_params.setSculptID(mesh_asset, sculpt_type);
- object_params["shape"] = volume_params.asLLSD();
-
- object_params["material"] = LL_MCODE_WOOD;
-
- object_params["group-id"] = gAgent.getGroupID();
- object_params["pos"] = ll_sd_from_vector3(position);
- object_params["rotation"] = ll_sd_from_quaternion(quat_rotation);
- object_params["scale"] = ll_sd_from_vector3(scale);
- object_params["name"] = mStack.front().name;
-
- // load material from dae file
- std::vector<LLTextureEntry> texture_entries = getMaterials(model, instance_geo);
- object_params["facelist"] = LLSD::emptyArray();
- for (int i = 0; i < texture_entries.size(); i++)
- {
- object_params["facelist"][i] = texture_entries[i].asLLSD();
- }
-
- // set extra parameters
- LLSculptParams sculpt_params;
- sculpt_params.setSculptTexture(mesh_asset);
- sculpt_params.setSculptType(sculpt_type);
- U8 buffer[MAX_OBJECT_PARAMS_SIZE+1];
- LLDataPackerBinaryBuffer dp(buffer, MAX_OBJECT_PARAMS_SIZE);
- sculpt_params.pack(dp);
- std::vector<U8> v(dp.getCurrentSize());
- memcpy(&v[0], buffer, dp.getCurrentSize());
- LLSD extra_parameter;
- extra_parameter["extra_parameter"] = sculpt_params.mType;
- extra_parameter["param_data"] = v;
- object_params["extra_parameters"].append(extra_parameter);
-
- mObjectList.append(object_params);
-
- delete model;
-
- LLFloaterReg::findTypedInstance<LLFloaterImportCollada>("import_collada")->setStatusCreatingPrim(mStack.front().name);
-
- return;
-}
-
-void LLImportCollada::uploadObjectAsset()
-{
- LLSD request;
- request["objects"] = mObjectList;
-
- std::string url = gAgent.getRegion()->getCapability("UploadObjectAsset");
- LLHTTPClient::post(url, request, new LLHTTPClient::Responder());
-}
-
-
-
-void LLImportCollada::importFile(std::string filename)
-{
- if (mIsImporting)
- {
- llwarns << "Importer already running, import command for " << filename << " ignored" << llendl;
- return;
- }
-
- LLFloaterReg::showInstance("import_collada");
- LLFloaterReg::findTypedInstance<LLFloaterImportCollada>("import_collada")->enableOK(TRUE);
-
-
- mIsImporting = TRUE;
- mDAE = new DAE;
- mImportOrigin = gAgent.getPositionAgent() + LLVector3(0, 0, 2);
- mSceneTransformation = LLMatrix4(); // identity
- mFilename = filename;
- mCreates = 0;
- mObjectList = LLSD::emptyArray();
-
- if (mDAE->open(mFilename) == NULL)
- {
- llwarns << "cannot open file " << mFilename << llendl;
- endImport();
- return;
- }
-
- LLImportColladaAssetCache::getInstance()->prepareForUpload(mDAE);
-
- return;
-}
-
-
-void LLImportCollada::assetsUploaded()
-{
- if (!mIsImporting)
- {
- // weird, we got a callback while not importing.
- return;
- }
-
- daeDocument* doc = mDAE->getDoc(mFilename);
- if (!doc)
- {
- llwarns << "can't find internal doc" << llendl;
- endImport();
- }
-
- daeElement* root = doc->getDomRoot();
- if (!root)
- {
- llwarns << "document has no root" << llendl;
- endImport();
- }
-
- domAsset::domUnit* unit = daeSafeCast<domAsset::domUnit>(root->getDescendant(daeElement::matchType(domAsset::domUnit::ID())));
- if (unit)
- {
- mSceneTransformation *= unit->getMeter();
- }
-
- domUpAxisType up = UPAXISTYPE_Y_UP; // default is Y_UP
- domAsset::domUp_axis* up_axis =
- daeSafeCast<domAsset::domUp_axis>(root->getDescendant(daeElement::matchType(domAsset::domUp_axis::ID())));
- if (up_axis)
- {
- up = up_axis->getValue();
- }
-
- if (up == UPAXISTYPE_X_UP)
- {
- LLMatrix4 rotation;
- rotation.initRotation(0.0f, 90.0f * DEG_TO_RAD, 0.0f);
-
- mSceneTransformation = matrix_multiply(rotation, mSceneTransformation);
- }
- else if (up == UPAXISTYPE_Y_UP)
- {
- LLMatrix4 rotation;
- rotation.initRotation(90.0f * DEG_TO_RAD, 0.0f, 0.0f);
-
- mSceneTransformation = matrix_multiply(rotation, mSceneTransformation);
- }
- // else Z_UP, which is our behavior
-
-
-
- daeElement* scene = root->getDescendant("visual_scene");
- if (!scene)
- {
- llwarns << "document has no visual_scene" << llendl;
- endImport();
- }
-
- processElement(scene);
- processNextElement();
-}
-
-void LLImportCollada::pushStack(daeElement* next_element, std::string name, LLMatrix4 transformation)
-{
- struct StackState new_state;
-
- new_state.next_element = next_element;
- new_state.name = name;
- new_state.transformation = transformation;
-
- mStack.push_front(new_state);
-}
-
-
-
-void LLImportCollada::popStack()
-{
- mStack.pop_front();
-}
-
-
-
-BOOL LLImportCollada::processElement(daeElement* element)
-{
- if (mStack.size() > 0)
- {
- mStack.front().next_element = getNextSibling(element);
- }
-
- domTranslate* translate = daeSafeCast<domTranslate>(element);
- if (translate)
- {
- domFloat3 dom_value = translate->getValue();
-
- LLMatrix4 translation;
- translation.setTranslation(LLVector3(dom_value[0], dom_value[1], dom_value[2]));
-
- mStack.front().transformation = matrix_multiply(translation, mStack.front().transformation);
- }
-
- domRotate* rotate = daeSafeCast<domRotate>(element);
- if (rotate)
- {
- domFloat4 dom_value = rotate->getValue();
-
- LLMatrix4 rotation;
- rotation.initRotTrans(dom_value[3] * DEG_TO_RAD, LLVector3(dom_value[0], dom_value[1], dom_value[2]), LLVector3(0, 0, 0));
-
- mStack.front().transformation = matrix_multiply(rotation, mStack.front().transformation);
- }
-
- domScale* scale = daeSafeCast<domScale>(element);
- if (scale)
- {
- domFloat3 dom_value = scale->getValue();
-
- LLMatrix4 scaling;
- scaling.initScale(LLVector3(dom_value[0], dom_value[1], dom_value[2]));
-
- mStack.front().transformation = matrix_multiply(scaling, mStack.front().transformation);
- }
-
- domMatrix* matrix = daeSafeCast<domMatrix>(element);
- if (matrix)
- {
- domFloat4x4 dom_value = matrix->getValue();
-
- LLMatrix4 matrix_transform;
-
- for (int i = 0; i < 4; i++)
- for(int j = 0; j < 4; j++)
- {
- matrix_transform.mMatrix[i][j] = dom_value[i + j*4];
- }
-
- mStack.front().transformation = matrix_multiply(matrix_transform, mStack.front().transformation);
- }
-
- domInstance_geometry* instance_geo = daeSafeCast<domInstance_geometry>(element);
- if (instance_geo)
- {
- appendObjectAsset(instance_geo);
- }
-
- domNode* node = daeSafeCast<domNode>(element);
- if (node)
- {
- pushStack(getFirstChild(element), getElementLabel(element), mStack.front().transformation);
- }
-
- domInstance_node* instance_node = daeSafeCast<domInstance_node>(element);
- if (instance_node)
- {
- daeElement* instance = instance_node->getUrl().getElement();
- if (instance)
- {
- pushStack(getFirstChild(instance), getElementLabel(instance), mStack.front().transformation);
- }
- }
-
- domVisual_scene* scene = daeSafeCast<domVisual_scene>(element);
- if (scene)
- {
- pushStack(getFirstChild(element), std::string("scene"), mSceneTransformation);
- }
-
- return FALSE;
-}
-
-
-void LLImportCollada::processNextElement()
-{
- while(1)
- {
- if (mStack.size() == 0)
- {
- uploadObjectAsset();
- endImport();
- return;
- }
-
- daeElement *element = mStack.front().next_element;
-
- if (element == NULL)
- {
- popStack();
- }
- else
- {
- processElement(element);
- }
- }
-}
-
-
-void LLImportCollada::endImport()
-{
- LLFloaterReg::hideInstance("import_collada");
-
- LLImportColladaAssetCache::getInstance()->endImport();
-
- if (mDAE)
- {
- delete mDAE;
- mDAE = NULL;
- }
-
- mIsImporting = FALSE;
-}
-
-
-/* static */
-void LLImportCollada::onCommitOK(LLUICtrl*, void*)
-{
- LLFloaterReg::findTypedInstance<LLFloaterImportCollada>("import_collada")->enableOK(FALSE);
-
- LLImportColladaAssetCache::getInstance()->uploadAssets();
-}
-
-
-/* static */
-void LLImportCollada::onCommitCancel(LLUICtrl*, void*)
-{
- getInstance()->endImport();
-}
-
-#endif
diff --git a/indra/newview/llfloaterimportcollada.h b/indra/newview/llfloaterimportcollada.h
deleted file mode 100644
index 30c4a9a7db..0000000000
--- a/indra/newview/llfloaterimportcollada.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/**
- * @file llfloaterimportcollada.h
- * @brief The about box from Help -> About
- *
- * $LicenseInfo:firstyear=2001&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#if 0 //DEPRECATED
-
-#ifndef LL_LLFLOATERIMPORTCOLLADA_H
-#define LL_LLFLOATERIMPORTCOLLADA_H
-
-#include "llfloater.h"
-
-class LLFloaterImportCollada : public LLFloater
-{
-public:
- LLFloaterImportCollada(const LLSD& key);
- /* virtual */ BOOL postBuild();
-
- void setAssetCount(S32 mesh_count, S32 texture_count);
- void setStatusAssetUploading(std::string asset_name);
- void setStatusCreatingPrim(std::string prim_name);
- void setStatusIdle();
- void enableOK(BOOL enable);
-};
-
-class LLViewerObject;
-class DAE;
-class daeElement;
-class domMesh;
-class domImage;
-class domInstance_geometry;
-class LLModel;
-class LLImportCollada;
-
-class LLImportColladaAssetCache : public LLSingleton<LLImportColladaAssetCache>
-{
-public:
- // called first to initialize
- void prepareForUpload(DAE* dae);
-
- // upload the assets in this collada file
- void uploadAssets();
-
- // get the uploaded assets which corresponds to this element
- LLUUID getAssetForDaeElement(daeElement* element);
-
- // stop the upload
- void endImport();
-
- // reset
- void clear();
-
- // callback for notification when an asset has been uploaded
- void assetUploaded(LLUUID transaction_uuid, LLUUID asset_uuid, BOOL success);
-
-private:
- void uploadNextAsset();
- BOOL uploadMeshAsset(domMesh* mesh);
- BOOL uploadImageAsset(domImage* image);
- void updateCount();
-
- std::vector<daeElement*> mUploadsPending;
- std::map<LLUUID, daeElement*> mTransactionMap;
- std::map<daeElement*, LLUUID> mAssetMap;
-
- DAE* mDAE;
- S32 mUploads;
-};
-
-
-class LLImportCollada
-: public LLSingleton<LLImportCollada>
-{
-public:
- LLImportCollada();
- void importFile(std::string filename);
-
- // callback when all assets have been uploaded
- void assetsUploaded();
-
- // callback when buttons pressed
- static void onCommitOK(LLUICtrl*, void*);
- static void onCommitCancel(LLUICtrl*, void*);
-
-
-private:
- void endImport();
- void processNextElement();
- BOOL processElement(daeElement* element);
- void pushStack(daeElement* next_element, std::string name, LLMatrix4 transformation);
- void popStack();
- void appendObjectAsset(domInstance_geometry* instance_geo);
- void uploadObjectAsset();
-
- struct StackState
- {
- daeElement* next_element;
- std::string name;
- LLMatrix4 transformation;
- };
-
- std::list<struct StackState> mStack;
- S32 mCreates;
- LLVector3 mImportOrigin;
- std::string mFilename;
- BOOL mIsImporting;
- DAE *mDAE;
- LLSD mObjectList;
-
- LLMatrix4 mSceneTransformation;
-};
-
-#endif // LL_LLFLOATERIMPORTCOLLADA_H
-
-#endif //DEPRECATED
diff --git a/indra/newview/llmeshreduction.cpp b/indra/newview/llmeshreduction.cpp
deleted file mode 100644
index 14e8dd37b4..0000000000
--- a/indra/newview/llmeshreduction.cpp
+++ /dev/null
@@ -1,272 +0,0 @@
-/**
- * @file llmeshreduction.cpp
- * @brief LLMeshReduction class implementation
- *
- * $LicenseInfo:firstyear=2004&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include "llviewerprecompiledheaders.h"
-
-#include "llmeshreduction.h"
-#include "llgl.h"
-#include "llvertexbuffer.h"
-
-#include "glod/glod.h"
-
-
-#if 0 //not used ?
-
-void create_vertex_buffers_from_model(LLModel* model, std::vector<LLPointer <LLVertexBuffer> >& vertex_buffers)
-{
-#if 0 //VECTORIZE THIS ?
- vertex_buffers.clear();
-
- for (S32 i = 0; i < model->getNumVolumeFaces(); ++i)
- {
- const LLVolumeFace &vf = model->getVolumeFace(i);
- U32 num_vertices = vf.mNumVertices;
- U32 num_indices = vf.mNumIndices;
-
- if (!num_vertices || ! num_indices)
- {
- continue;
- }
-
- LLVertexBuffer* vb =
- new LLVertexBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0, 0);
-
- vb->allocateBuffer(num_vertices, num_indices, TRUE);
-
- LLStrider<LLVector3> vertex_strider;
- LLStrider<LLVector3> normal_strider;
- LLStrider<LLVector2> tc_strider;
- LLStrider<U16> index_strider;
-
- vb->getVertexStrider(vertex_strider);
- vb->getNormalStrider(normal_strider);
- vb->getTexCoord0Strider(tc_strider);
-
- vb->getIndexStrider(index_strider);
-
- // build vertices and normals
- for (U32 i = 0; (S32)i < num_vertices; i++)
- {
- *(vertex_strider++) = vf.mVertices[i].mPosition;
- *(tc_strider++) = vf.mVertices[i].mTexCoord;
- LLVector3 normal = vf.mVertices[i].mNormal;
- normal.normalize();
- *(normal_strider++) = normal;
- }
-
- // build indices
- for (U32 i = 0; i < num_indices; i++)
- {
- *(index_strider++) = vf.mIndices[i];
- }
-
-
- vertex_buffers.push_back(vb);
- }
-#endif
-}
-
-void create_glod_object_from_vertex_buffers(S32 object, S32 group, std::vector<LLPointer <LLVertexBuffer> >& vertex_buffers)
-{
- glodNewGroup(group);
- stop_gloderror();
- glodNewObject(object, group, GLOD_DISCRETE);
- stop_gloderror();
-
- for (U32 i = 0; i < vertex_buffers.size(); ++i)
- {
- vertex_buffers[i]->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0);
-
- U32 num_indices = vertex_buffers[i]->getNumIndices();
-
- if (num_indices > 2)
- {
- glodInsertElements(object, i, GL_TRIANGLES, num_indices, GL_UNSIGNED_SHORT,
- vertex_buffers[i]->getIndicesPointer(), 0, 0.f);
- }
- stop_gloderror();
- }
-
- glodBuildObject(object);
- stop_gloderror();
-}
-
-// extract the GLOD data into vertex buffers
-void create_vertex_buffers_from_glod_object(S32 object, S32 group, std::vector<LLPointer <LLVertexBuffer> >& vertex_buffers)
-{
- vertex_buffers.clear();
-
- GLint patch_count = 0;
- glodGetObjectParameteriv(object, GLOD_NUM_PATCHES, &patch_count);
- stop_gloderror();
-
- GLint* sizes = new GLint[patch_count*2];
- glodGetObjectParameteriv(object, GLOD_PATCH_SIZES, sizes);
- stop_gloderror();
-
- GLint* names = new GLint[patch_count];
- glodGetObjectParameteriv(object, GLOD_PATCH_NAMES, names);
- stop_gloderror();
-
- for (S32 i = 0; i < patch_count; i++)
- {
- LLPointer<LLVertexBuffer> buff =
- new LLVertexBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0, 0);
-
- if (sizes[i*2+1] > 0 && sizes[i*2] > 0)
- {
- buff->allocateBuffer(sizes[i*2+1], sizes[i*2], true);
- buff->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0);
- glodFillElements(object, names[i], GL_UNSIGNED_SHORT, buff->getIndicesPointer());
- stop_gloderror();
- }
- else
- {
- // this face was eliminated, create a dummy triangle (one vertex, 3 indices, all 0)
- buff->allocateBuffer(1, 3, true);
- }
-
- vertex_buffers.push_back(buff);
- }
-
- glodDeleteObject(object);
- stop_gloderror();
- glodDeleteGroup(group);
- stop_gloderror();
-
- delete [] sizes;
- delete [] names;
-}
-
-
-LLPointer<LLModel> create_model_from_vertex_buffers(std::vector<LLPointer <LLVertexBuffer> >& vertex_buffers)
-{
- // extract the newly reduced mesh
-
- // create our output model
- LLVolumeParams volume_params;
- volume_params.setType(LL_PCODE_PROFILE_SQUARE, LL_PCODE_PATH_LINE);
- LLPointer<LLModel> out_model = new LLModel(volume_params, 0.f);
-
- out_model->setNumVolumeFaces(vertex_buffers.size());
-
- // build new faces from each vertex buffer
- for (GLint i = 0; i < vertex_buffers.size(); ++i)
- {
- LLStrider<LLVector3> pos;
- LLStrider<LLVector3> norm;
- LLStrider<LLVector2> tc;
- LLStrider<U16> index;
-
- vertex_buffers[i]->getVertexStrider(pos);
- vertex_buffers[i]->getNormalStrider(norm);
- vertex_buffers[i]->getTexCoord0Strider(tc);
- vertex_buffers[i]->getIndexStrider(index);
-
- out_model->setVolumeFaceData(i, pos, norm, tc, index,
- vertex_buffers[i]->getNumVerts(), vertex_buffers[i]->getNumIndices());
- }
-
- return out_model;
-}
-
-
-
-LLMeshReduction::LLMeshReduction()
-{
- mCounter = 1;
-
- glodInit();
-}
-
-LLMeshReduction::~LLMeshReduction()
-{
- glodShutdown();
-}
-
-
-LLPointer<LLModel> LLMeshReduction::reduce(LLModel* in_model, F32 limit, S32 mode)
-{
- LLVertexBuffer::unbind();
-
- // create vertex buffers from model
- std::vector<LLPointer<LLVertexBuffer> > in_vertex_buffers;
- create_vertex_buffers_from_model(in_model, in_vertex_buffers);
-
- // create glod object from vertex buffers
- stop_gloderror();
- S32 glod_group = mCounter++;
- S32 glod_object = mCounter++;
- create_glod_object_from_vertex_buffers(glod_object, glod_group, in_vertex_buffers);
-
-
- // set reduction parameters
- stop_gloderror();
-
- if (mode == TRIANGLE_BUDGET)
- {
- // triangle budget mode
- glodGroupParameteri(glod_group, GLOD_ADAPT_MODE, GLOD_TRIANGLE_BUDGET);
- stop_gloderror();
- glodGroupParameteri(glod_group, GLOD_ERROR_MODE, GLOD_OBJECT_SPACE_ERROR);
- stop_gloderror();
- S32 triangle_count = (S32)limit;
- glodGroupParameteri(glod_group, GLOD_MAX_TRIANGLES, triangle_count);
- stop_gloderror();
- }
- else if (mode == ERROR_THRESHOLD)
- {
- // error threshold mode
- glodGroupParameteri(glod_group, GLOD_ADAPT_MODE, GLOD_ERROR_THRESHOLD);
- glodGroupParameteri(glod_group, GLOD_ERROR_MODE, GLOD_OBJECT_SPACE_ERROR);
- F32 error_threshold = limit;
- glodGroupParameterf(glod_group, GLOD_OBJECT_SPACE_ERROR_THRESHOLD, error_threshold);
- stop_gloderror();
- }
-
- else
- {
- // not a legal mode
- return NULL;
- }
-
-
- // do the reduction
- glodAdaptGroup(glod_group);
- stop_gloderror();
-
- // convert glod object into vertex buffers
- std::vector<LLPointer<LLVertexBuffer> > out_vertex_buffers;
- create_vertex_buffers_from_glod_object(glod_object, glod_group, out_vertex_buffers);
-
- // convert vertex buffers into a model
- LLPointer<LLModel> out_model = create_model_from_vertex_buffers(out_vertex_buffers);
-
-
- return out_model;
-}
-
-#endif
diff --git a/indra/newview/llmeshreduction.h b/indra/newview/llmeshreduction.h
deleted file mode 100644
index b518f6a650..0000000000
--- a/indra/newview/llmeshreduction.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * @file llmeshreduction.h
- * @brief LLMeshReduction class definition
- *
- * $LicenseInfo:firstyear=2004&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#ifndef LL_LLMESHREDUCTION_H
-#define LL_LLMESHREDUCTION_H
-
-#include "llmodel.h"
-
-class LLMeshReduction
-{
- public:
- enum EReductionMode
- {
- TRIANGLE_BUDGET,
- ERROR_THRESHOLD
- };
-
- LLMeshReduction();
- ~LLMeshReduction();
-
- LLPointer<LLModel> reduce(LLModel* in_model, F32 limit, S32 mode);
-
-private:
- U32 mCounter;
-};
-
-#endif // LL_LLMESHREDUCTION_H
diff --git a/indra/newview/llphysicsmotion.cpp b/indra/newview/llphysicsmotion.cpp
index acf8973f03..c15e72744f 100644
--- a/indra/newview/llphysicsmotion.cpp
+++ b/indra/newview/llphysicsmotion.cpp
@@ -628,7 +628,7 @@ BOOL LLPhysicsMotion::onUpdate(F32 time)
const F32 area_for_max_settings = 0.0;
const F32 area_for_min_settings = 1400.0;
const F32 area_for_this_setting = area_for_max_settings + (area_for_min_settings-area_for_max_settings)*(1.0-lod_factor);
- const F32 pixel_area = fsqrtf(mCharacter->getPixelArea());
+ const F32 pixel_area = sqrtf(mCharacter->getPixelArea());
const BOOL is_self = (dynamic_cast<LLVOAvatarSelf *>(mCharacter) != NULL);
if ((pixel_area > area_for_this_setting) || is_self)
diff --git a/indra/newview/llpolymesh.cpp b/indra/newview/llpolymesh.cpp
index b512a867ba..90e835cda8 100644
--- a/indra/newview/llpolymesh.cpp
+++ b/indra/newview/llpolymesh.cpp
@@ -738,43 +738,40 @@ const LLVector2 &LLPolyMeshSharedData::getUVs(U32 index)
//-----------------------------------------------------------------------------
LLPolyMesh::LLPolyMesh(LLPolyMeshSharedData *shared_data, LLPolyMesh *reference_mesh)
{
- LLMemType mt(LLMemType::MTYPE_AVATAR_MESH);
-
- llassert(shared_data);
-
- mSharedData = shared_data;
- mReferenceMesh = reference_mesh;
- mAvatarp = NULL;
- mVertexData = NULL;
-
- mCurVertexCount = 0;
- mFaceIndexCount = 0;
- mFaceIndexOffset = 0;
- mFaceVertexCount = 0;
- mFaceVertexOffset = 0;
-
- if (shared_data->isLOD() && reference_mesh)
- {
- mCoords = reference_mesh->mCoords;
- mNormals = reference_mesh->mNormals;
- mScaledNormals = reference_mesh->mScaledNormals;
- mBinormals = reference_mesh->mBinormals;
- mScaledBinormals = reference_mesh->mScaledBinormals;
- mTexCoords = reference_mesh->mTexCoords;
- mClothingWeights = reference_mesh->mClothingWeights;
- }
- else
- {
-#if 1 // Allocate memory without initializing every vector
- // NOTE: This makes asusmptions about the size of LLVector[234]
- int nverts = mSharedData->mNumVertices;
- int nfloats = nverts * (3*5 + 2 + 4);
- mVertexData = new F32[nfloats];
+ LLMemType mt(LLMemType::MTYPE_AVATAR_MESH);
+
+ llassert(shared_data);
+
+ mSharedData = shared_data;
+ mReferenceMesh = reference_mesh;
+ mAvatarp = NULL;
+ mVertexData = NULL;
+
+ mCurVertexCount = 0;
+ mFaceIndexCount = 0;
+ mFaceIndexOffset = 0;
+ mFaceVertexCount = 0;
+ mFaceVertexOffset = 0;
+
+ if (shared_data->isLOD() && reference_mesh)
+ {
+ mCoords = reference_mesh->mCoords;
+ mNormals = reference_mesh->mNormals;
+ mScaledNormals = reference_mesh->mScaledNormals;
+ mBinormals = reference_mesh->mBinormals;
+ mScaledBinormals = reference_mesh->mScaledBinormals;
+ mTexCoords = reference_mesh->mTexCoords;
+ mClothingWeights = reference_mesh->mClothingWeights;
+ }
+ else
+ {
+ // Allocate memory without initializing every vector
+ // NOTE: This makes asusmptions about the size of LLVector[234]
+ int nverts = mSharedData->mNumVertices;
+ int nfloats = nverts * (3*5 + 2 + 4);
//use 16 byte aligned vertex data to make LLPolyMesh SSE friendly
- mVertexData = (F32*) malloc(nfloats*4);
- int offset = 0;
- mCoords = (LLVector3*)(mVertexData + offset); offset += 3*nverts;
- mNormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts;
+ mVertexData = new F32[nfloats];
+ int offset = 0;
mCoords = (LLVector4*)(mVertexData + offset); offset += 4*nverts;
mNormals = (LLVector4*)(mVertexData + offset); offset += 4*nverts;
mClothingWeights = (LLVector4*)(mVertexData + offset); offset += 4*nverts;
@@ -782,23 +779,11 @@ LLPolyMesh::LLPolyMesh(LLPolyMeshSharedData *shared_data, LLPolyMesh *reference_
// these members don't need to be 16-byte aligned, but the first one might be
// read during an aligned memcpy of mTexCoords
- mScaledNormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts;
- mBinormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts;
- mScaledBinormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts;
- mTexCoords = (LLVector2*)(mVertexData + offset); offset += 2*nverts;
- mClothingWeights = (LLVector4*)(mVertexData + offset); offset += 4*nverts;
-#else
- mCoords = new LLVector3[mSharedData->mNumVertices];
- mNormals = new LLVector3[mSharedData->mNumVertices];
- mScaledNormals = new LLVector3[mSharedData->mNumVertices];
- mBinormals = new LLVector3[mSharedData->mNumVertices];
- mScaledBinormals = new LLVector3[mSharedData->mNumVertices];
- mTexCoords = new LLVector2[mSharedData->mNumVertices];
- mClothingWeights = new LLVector4[mSharedData->mNumVertices];
- memset(mClothingWeights, 0, sizeof(LLVector4) * mSharedData->mNumVertices);
-#endif
- initializeForMorph();
- }
+ mScaledNormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts;
+ mBinormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts;
+ mScaledBinormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts;
+ initializeForMorph();
+ }
}
@@ -813,17 +798,9 @@ LLPolyMesh::~LLPolyMesh()
delete mJointRenderData[i];
mJointRenderData[i] = NULL;
}
-#if 0 // These are now allocated as one big uninitialized chunk
- delete [] mCoords;
- delete [] mNormals;
- delete [] mScaledNormals;
- delete [] mBinormals;
- delete [] mScaledBinormals;
- delete [] mClothingWeights;
- delete [] mTexCoords;
-#else
- delete [] mVertexData;
-#endif
+
+ delete [] mVertexData;
+
}
@@ -989,20 +966,17 @@ LLVector3 *LLPolyMesh::getScaledBinormals()
//-----------------------------------------------------------------------------
void LLPolyMesh::initializeForMorph()
{
- if (!mSharedData)
- return;
-
- memcpy(mCoords, mSharedData->mBaseCoords, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/
- memcpy(mNormals, mSharedData->mBaseNormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/
+ for (U32 i = 0; i < mSharedData->mNumVertices; ++i)
+ {
mCoords[i] = LLVector4(mSharedData->mBaseCoords[i]);
mNormals[i] = LLVector4(mSharedData->mBaseNormals[i]);
}
- memcpy(mScaledNormals, mSharedData->mBaseNormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/
- memcpy(mBinormals, mSharedData->mBaseBinormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/
- memcpy(mScaledBinormals, mSharedData->mBaseBinormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/
- memcpy(mTexCoords, mSharedData->mTexCoords, sizeof(LLVector2) * mSharedData->mNumVertices); /*Flawfinder: ignore*/
- memset(mClothingWeights, 0, sizeof(LLVector4) * mSharedData->mNumVertices);
+ memcpy(mScaledNormals, mSharedData->mBaseNormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/
+ memcpy(mBinormals, mSharedData->mBaseBinormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/
+ memcpy(mScaledBinormals, mSharedData->mBaseBinormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/
+ memcpy(mTexCoords, mSharedData->mTexCoords, sizeof(LLVector2) * mSharedData->mNumVertices); /*Flawfinder: ignore*/
+ memset(mClothingWeights, 0, sizeof(LLVector4) * mSharedData->mNumVertices);
}
//-----------------------------------------------------------------------------