private static remSKICsection ReadSkin(string sectionName, int sectionLength, int numSkins, byte[] sectionBuffer) { remSKICsection skinSec = new remSKICsection(numSkins); int secBufIdx = 0; for (int subSection = 0; subSection < numSkins; subSection++) { byte[] type = new byte[4] { sectionBuffer[secBufIdx+0], sectionBuffer[secBufIdx+1], sectionBuffer[secBufIdx+2], sectionBuffer[secBufIdx+3] }; int length = BitConverter.ToInt32(sectionBuffer, secBufIdx+4); remId mesh = GetIdentifier(sectionBuffer, secBufIdx+8); int numWeights = BitConverter.ToInt32(sectionBuffer, secBufIdx+8+256); remSkin skin = new remSkin(numWeights); Trace.Assert(TypeCheck(remSkin.ClassType, type)); skin.mesh = mesh; int weightBufIdx = secBufIdx+8+256+4; for (int weightIdx = 0; weightIdx < numWeights; weightIdx++) { remBoneWeights weights = new remBoneWeights(); weights.bone = GetIdentifier(sectionBuffer, weightBufIdx); weightBufIdx += 256; int numVertIdxWts = BitConverter.ToInt32(sectionBuffer, weightBufIdx); weightBufIdx += 4; Matrix matrix = new Matrix(); for (int i = 0; i < 4; i++) { Vector4 row = new Vector4(); for (int j = 0; j < 4; j++) { row[j] = BitConverter.ToSingle(sectionBuffer, weightBufIdx); weightBufIdx += 4; } matrix.set_Rows(i, row); } weights.matrix = matrix; weights.vertexIndices = new int[numVertIdxWts]; for (int i = 0; i < numVertIdxWts; i++) { weights.vertexIndices[i] = BitConverter.ToInt32(sectionBuffer, weightBufIdx); weightBufIdx += 4; } weights.vertexWeights = new float[weights.numVertIdxWts]; for (int i = 0; i < numVertIdxWts; i++) { weights.vertexWeights[i] = BitConverter.ToSingle(sectionBuffer, weightBufIdx); weightBufIdx += 4; } skin.AddChild(weights); } skinSec.AddChild(skin); secBufIdx += length; } if (secBufIdx != sectionLength) Report.ReportLog("Warning! SKIC section has wrong length."); return skinSec; }
public Vector2 IntersectPlane(Plane plane, Vector2 relativeMousePos) { // Relative screen position. float xRayView = relativeMousePos.X / Projection.M11; float yRayView = relativeMousePos.Y / Projection.M22; viewDirection.Normalize(); Vector3 ray = viewDirection + rightVec * xRayView - upVec * yRayView; Vector4 pointVec = new Vector4(position - plane.Origin, 0); Matrix dirMat = new Matrix(); Matrix test = Matrix.Translation(1, 1, 1); //var x = test.get_Rows(3); dirMat.set_Rows(0, new Vector4(plane.XAxis, 0)); dirMat.set_Rows(1, new Vector4(plane.YAxis, 0)); dirMat.set_Rows(2, new Vector4(-ray, 0)); dirMat.set_Rows(3, Vector4.UnitW); dirMat.Invert(); Vector4 res = Vector4.Transform(pointVec, dirMat); Vector2 xy = new Vector2(Vector4.Dot(dirMat.get_Rows(0), pointVec), Vector4.Dot(dirMat.get_Rows(1), pointVec)); return new Vector2(res.X, res.Y); }
private static remBONCsection ReadBones(string sectionName, int sectionLength, int numBones, byte[] sectionBuffer) { remBONCsection boneSec = new remBONCsection(numBones); int secBufIdx = 0; for (int subSection = 0; subSection < numBones; subSection++) { byte[] type = new byte[4] { sectionBuffer[secBufIdx+0], sectionBuffer[secBufIdx+1], sectionBuffer[secBufIdx+2], sectionBuffer[secBufIdx+3] }; int length = BitConverter.ToInt32(sectionBuffer, secBufIdx+4); remBone bone = new remBone(length > 256+16*4+4 ? (length - 256+16*4+4) / 256 : 0); Trace.Assert(TypeCheck(remBone.ClassType, type)); bone.name = GetIdentifier(sectionBuffer, secBufIdx+8); Matrix matrix = new Matrix(); for (int i = 0; i < 4; i++) { Vector4 row = new Vector4(); for (int j = 0; j < 4; j++) row[j] = BitConverter.ToSingle(sectionBuffer, secBufIdx+8+256 + (i*4 + j) * 4); matrix.set_Rows(i, row); } bone.matrix = matrix; int numChilds = BitConverter.ToInt32(sectionBuffer, secBufIdx+8+256 + 16*4); List<remId> childNames = new List<remId>(numChilds); for (int i = 0; i < numChilds; i++) childNames.Add(GetIdentifier(sectionBuffer, secBufIdx+8+256 + 16*4 + 4 + i*256)); AddParentBone(boneSec, bone, childNames); secBufIdx += length; } for (int i = 0; i < numBones; i++) { if (boneSec[i].Parent == null) { boneSec[i].Parent = boneSec.rootFrame; boneSec.rootFrame.AddChild(boneSec[i]); } } if (secBufIdx != sectionLength) Report.ReportLog("Warning! BONC section has wrong length."); return boneSec; }