void AddEnvelopes(GmdcGroup g, Ambertation.Scenes.Mesh m, GmdcElement bonee, GmdcElement bonewighte, Hashtable jointmap) { if (bonee != null && true) { int pos = 0; foreach (SimPe.Plugin.Gmdc.GmdcElementValueOneInt vi in bonee.Values) { byte[] data = vi.Bytes; IntArrayList used = new IntArrayList(); for (int datapos = 0; datapos < 3; datapos++) //we can only store 3 bone weights { byte b = data[datapos]; if (b != 0xff && b < g.UsedJoints.Count) { int bnr = g.UsedJoints[b]; if (used.Contains(bnr)) { continue; } used.Add(bnr); Ambertation.Scenes.Joint nj = jointmap[bnr] as Ambertation.Scenes.Joint; if (nj != null) { double w = 1; if (bonewighte != null) { if (bonewighte.Values.Count > pos) { SimPe.Plugin.Gmdc.GmdcElementValueBase v = bonewighte.Values[pos]; if (datapos < v.Data.Length) { w = v.Data[datapos]; } } } //if there is no envelope for nj, make sure we get a new one //with pos 0-Weights inserted Ambertation.Scenes.Envelope e = m.GetJointEnvelope(nj, pos); e.Weights.Add(w); //added = true; } } } pos++; m.SyncEnvelopeLenghts(pos); //fill all unset EnvelopeWeights with 0 } // bonee.Values } }
void AddJoint(Ambertation.Scenes.Joint parent, int index, Hashtable jointmap, ElementOrder component) { if (!joints) { return; } if (index < 0 || index >= gmdc.Joints.Count) { return; } GmdcJoint j = gmdc.Joints[index]; Ambertation.Scenes.Joint nj = parent.CreateChild(j.Name); jointmap[index] = nj; if (j.AssignedTransformNode != null) { Vector3f tmp = j.AssignedTransformNode.Transformation.Translation; tmp = component.TransformScaled(tmp); //tmp = component.ScaleMatrix * tmp; nj.Translation.X = tmp.X; nj.Translation.Y = tmp.Y; nj.Translation.Z = tmp.Z; Quaternion q = component.TransformRotation(j.AssignedTransformNode.Transformation.Rotation); tmp = q.GetEulerAngles(); //Console.WriteLine(" "+q.ToLinedString()); nj.Rotation.X = tmp.X; nj.Rotation.Y = tmp.Y; nj.Rotation.Z = tmp.Z; IntArrayList li = j.AssignedTransformNode.ChildBlocks; foreach (int i in li) { SimPe.Interfaces.Scenegraph.ICresChildren cld = j.AssignedTransformNode.GetBlock(i); if (cld is TransformNode) { TransformNode tn = cld as TransformNode; if (tn.JointReference != TransformNode.NO_JOINT) { AddJoint(nj, tn.JointReference, jointmap, component); } } } } }