bool LWObject::collectWeights(const std::vector<LWBone> &bones)
{
	LWObjectInfo *objectInfo = Manager::getSingleton()->getObjectInfo();
	if(objectInfo == 0)
		return false;
			
	LWMeshInfo *meshInfo = objectInfo->meshInfo(lwId, TRUE);
	if(meshInfo == 0)
		return false;

	bool hasWeights = false;

	// Each bone has it's own weightmap
	for(unsigned int i = 0; i < bones.size(); ++i)
	{
		const std::string &weightMap = bones[i].getWeightName();

		// Select vertex map to read
		void *map = 0;
		if((map = meshInfo->pntVLookup(meshInfo, LWVMAP_WGHT, weightMap.c_str())) == 0)
			continue;

		if(meshInfo->pntVSelect(meshInfo, map) != 1)
		{
			Manager::getSingleton()->getExporter()->printWarning(name + ": weightmap has more than 1 dimension");
			continue;
		}

		// Try for each vertex
		for(unsigned int j = 0; j < vertices.size(); ++j)
		{
			float weight = 0.f;
			if(meshInfo->pntVGet(meshInfo, vertices[j].id, &weight))
			{
				// 0-weight is valid
				//if(fabs(weight) < .001f)
				//	continue;


				// Set if greater than what's already in
				for(int k = 0; k < LWVertex::MAX_WEIGHTS; ++k)
				{
					if(vertices[j].boneIndices[k] == -1 || fabs(vertices[j].boneWeights[k]) < fabsf(weight)) 
					{	
						// Store old value forward
						if(k + 1 < LWVertex::MAX_WEIGHTS)
						{
							vertices[j].boneIndices[k + 1] = vertices[j].boneIndices[k];
							vertices[j].boneWeights[k + 1] = vertices[j].boneWeights[k];
						}

						vertices[j].boneIndices[k] = i;
						vertices[j].boneWeights[k] = weight;
						break;
					}
				}

				/*
				// Set if has no weight
				bool set = false;
				for(int k = 0; k < LWVertex::MAX_WEIGHTS; ++k)
				{
					if(vertices[j].boneIndices[k] == -1) 
					{
						vertices[j].boneIndices[k] = i;
						vertices[j].boneWeights[k] = weight;
						set = true;

						hasWeights = true;
						break;
					}
				}

				if(set == true)
					continue;

				// Set if greater than what's already in
				for(k = LWVertex::MAX_WEIGHTS - 1; k >= 0; --k)
				{
					if(fabs(vertices[j].boneWeights[k]) < fabsf(weight)) 
					{	
						// Store old value forward
						if(k + 1 < LWVertex::MAX_WEIGHTS)
						{
							vertices[j].boneIndices[k + 1] = vertices[j].boneIndices[k];
							vertices[j].boneWeights[k + 1] = vertices[j].boneWeights[k];
						}

						vertices[j].boneIndices[k] = i;
						vertices[j].boneWeights[k] = weight;
						break;
					}
				}
				*/
			}

		}
	}

	if(meshInfo->destroy)
		meshInfo->destroy(meshInfo);

	return hasWeights;
}