Horde3Dhttp://horde3d.org/forums/ Animation Layer remaningWeight computationhttp://horde3d.org/forums/viewtopic.php?f=3&t=1597 Page 1 of 1

 Author: Johnny [ 23.11.2011, 10:51 ] Post subject: Animation Layer remaningWeight computation Hello, I found a Bug in the animation system, more precisely in the computation for the remainingWeight for animation layersNow, the Horde3D goes through all stages, stating at the highest layer and going down to the lowest. While doing this the remainingWeight gets computed.The way I see it, the remainingWeight should work like this: The highest Layer has priority so it takes as much weight as it needs from the remainingWeight Bucket. The second highest layer check if there is still something left and if so, has its pick. And so on.If I understood this correctly, the remainingWeight should start at 1.0 and should steadily empty till reaching 0.The thing is that this is not case with the current implementation (file egAnimation.cpp):The BugCode:remainingWeight *= 1.0f - minf( layerWeightSum, 1.0f );//layerWeightSum = total weight of previous layerThis looks like the remainingWeight is indented to be used as a weight for layers weights. However, even if this is the case, there is a bug with the computation of the final weight:Code:weight = (curStage.weight / layerWeightSum) * remainingWeight;//curStage.weight = weight of current stage/layerWeightSum = total weight of current LayerThis calculation causes that each layer will render with the whole remaining weight, no matter how much weight it actually needs.This means that the remainingWeight isn't used as a weight of the layer.ExampleCode:Layer 3remainingWeight = 1.0 * (1.0 - 0.0) = 1.0curStage.weight = layerWeightSum = 0.5-------------------------------------------------render weight = 1 * remainingWeight = 1.0Layer 2remainingWeight = 1.0 * (1.0 - 0.5) = 0.5curStage.weight = layerWeightSum = 0.6-------------------------------------------------render weight = 1 * remainingWeight = 0.5Layer 1remainingWeight = 0.5 * (1.0 - 0.6) = 0.2curStage.weight = layerWeightSum = 0.3-------------------------------------------------render weight = 1 * remainingWeight = 0.2Solution 1To fix this bug we must alter the render weight computation:Code:weight = curStage.weight * (curStage.weight / layerWeightSum) * remainingWeight;Now the System uses the remainingWeight as a weight for each layer.Example:Code:Layer 3remainingWeight = 1.0 * (1.0 - 0.0) = 1.0curStage.weight = layerWeightSum = 0.5-------------------------------------------------render weight = 0.5 * 1 * remainingWeight = 0.5Layer 2remainingWeight = 1.0 * (1.0 - 0.5) = 0.5curStage.weight = layerWeightSum = 0.6-------------------------------------------------render weight = 0.6 * 1 * remainingWeight = 0.3Layer 1remainingWeight = 0.5 * (1.0 - 0.6) = 0.2curStage.weight = layerWeightSum = 0.3-------------------------------------------------render weight = 0.3 * 1 * remainingWeight = 0.06Solution 2However, I still find this wrong because it doesn't implement the remaining weight behavior as one would assume. Much better would be to implement the remainingWeight as some sorts of bucket from which the layers can take out weight in order of their priority (ids)To achieve this I would change the calculations for the remainingWeight and weight:Code:remainingWeight = maxf(remainingWeight - minf( layerWeightSum, 1.0f ), 0.0f);Code://render weightif(layerWeightSum >= remainingWeight) //this layer will use all of the remaining weight   weight = (curStage.weight / layerWeightSum) * remainingWeight;else //weight will still be available for lower layer   weight = curStage.weight; And here is the example now with the proposed changes:Code:Layer 3remainingWeight = 1.0 - 0.0 = 1.0curStage.weight = layerWeightSum = 0.5-------------------------------------------------render weight = 0.5Layer 2remainingWeight = 1.0 - 0.5 = 0.5curStage.weight = layerWeightSum = 0.6-------------------------------------------------render weight = 1 * remainingWeight = 0.5Layer 1remainingWeight = maxf(0.5 - 0.6) = 0curStage.weight = layerWeightSum = 0.3-------------------------------------------------render weight = 1 * remainingWeight = 0

 Page 1 of 1 All times are UTC + 1 hour Powered by phpBB® Forum Software © phpBB Grouphttps://www.phpbb.com/