public static void SaveHdMorph(FileInfo file, HdMorph hdMorph) { using (var stream = file.OpenWrite()) using (var writer = new BinaryWriter(stream)) { WriteHdMorph(writer, hdMorph); } }
public void Apply(HdMorph morph, float weight, int levelIdx, QuadTopology topology, Vector3[] positions) { var level = morph.GetLevel(levelIdx); if (level == null) { return; } foreach (var faceEdit in level.FaceEdits) { foreach (var vertexEdit in faceEdit.VertexEdits) { int pathLength = vertexEdit.PathLength; int refinedFaceIdx = faceEdit.ControlFaceIdx; for (int i = 0; i < pathLength - 1; ++i) { refinedFaceIdx = refinedFaceIdx * 4 + vertexEdit.GetPathElement(i); } int cornerIdx = vertexEdit.GetPathElement(pathLength - 1); int refinedVertexIdx = topology.Faces[refinedFaceIdx].GetCorner(cornerIdx); Vector3 tangentSpaceDelta = vertexEdit.Delta; int tangentToObjectSpaceTransformIdx = faceEdit.ControlFaceIdx * 4 + vertexEdit.GetPathElement(0); Matrix3x3 tangentToObjectSpaceTransform = tangentToObjectSpaceTransforms[tangentToObjectSpaceTransformIdx]; Vector3 objectSpaceDelta = Vector3.Transform(tangentSpaceDelta, tangentToObjectSpaceTransform); positions[refinedVertexIdx] += weight * objectSpaceDelta; } } }
private void TestHdMorph(HdMorph hdMorph, int refinedFaceIdxToCheck, int cornerToCheck, Vector3 expectedValue) { var(refinedTopology, refinedVertexPositions) = ApplyHdMorph(hdMorph, controlTopology, controlVertexPositions); Vector3 actualValue = refinedVertexPositions[refinedTopology.Faces[refinedFaceIdxToCheck].GetCorner(cornerToCheck)]; bool isOk = Vector3.Distance(actualValue, expectedValue) < 1e-2; Console.WriteLine($"{actualValue.FormatForMathematica()}: {(isOk ? "OK" : "FAIL")}"); }
public void Run() { //FileInfo file = CommonPaths.SourceAssetsDir.File("daz-assets/FWSAAdalineHDforVictoria7/Content/data/DAZ 3D/Genesis 3/Female/Morphs/FWSA/Adaline/FBM-FWSAAdaline.dhdm"); //FileInfo file = CommonPaths.SourceAssetsDir.File("daz-assets/FWSAAdalineHDforVictoria7/Content/data/DAZ 3D/Genesis 3/Female/Morphs/FWArt/FW_PBMNails.dhdm"); FileInfo file = CommonPaths.SourceAssetsDir.File("daz-assets/Rune7HDAddOn/Content/data/DAZ 3D/Genesis 3/Female/Morphs/Daz 3D/Rune 7/FBMRune7HD.dhdm"); HdMorph hdMorph = HdMorphSerialization.LoadHdMorph(file); ValidateHdMorph(hdMorph); PrintHdMorph(hdMorph); }
public static void WriteHdMorph(BinaryWriter writer, HdMorph morph) { writer.Write(Cookie); writer.Write(morph.Levels.Length); writer.Write(Unknown1); writer.Write(morph.Levels.Length); foreach (var level in morph.Levels) { WriteLevel(writer, level); } }
private void TestLevel1HdMorph() { var delta = new Vector3(10, 20, 30); var vertexEdit = new HdMorph.VertexEdit(HdMorph.VertexEdit.PackPath(0, 2), delta); var faceEdit = new HdMorph.FaceEdit(100, ImmutableArray.Create(vertexEdit)); var level1 = new HdMorph.Level(controlTopology.Faces.Length, 1, ImmutableArray.Create(faceEdit)); var levels = ImmutableArray.Create(level1); HdMorph hdMorph = new HdMorph(levels); Vector3 expectedPosition = new Vector3(29.7680817f, 183.135971f, 13.2819338f); //from Daz studio export TestHdMorph(hdMorph, 100 * 4, 2, expectedPosition); }
private void TestLevel2HdMorph() { var delta = new Vector3(10, 20, 30); var vertexEdit = new HdMorph.VertexEdit(HdMorph.VertexEdit.PackPath(0, 2, 1), delta); var faceEdit = new HdMorph.FaceEdit(200, ImmutableArray.Create(vertexEdit)); var level1 = new HdMorph.Level(controlTopology.Faces.Length, 1, ImmutableArray <HdMorph.FaceEdit> .Empty); var level2 = new HdMorph.Level(controlTopology.Faces.Length, 2, ImmutableArray.Create(faceEdit)); var levels = ImmutableArray.Create(level1, level2); HdMorph hdMorph = new HdMorph(levels); Vector3 expectedPosition = new Vector3(7.82922983f, 197.132507f, -15.0236731f); //from Daz studio export TestHdMorph(hdMorph, ((200 * 4) + 0) * 4 + 2, 1, expectedPosition); }
public void Run() { var delta = new Vector3(10, 20, 30); var vertexEdit = new HdMorph.VertexEdit(HdMorph.VertexEdit.PackPath(0, 2, 1), delta); var faceEdit = new HdMorph.FaceEdit(200, ImmutableArray.Create(vertexEdit)); var level1 = new HdMorph.Level(G3FControlFaceCount, 1, ImmutableArray <HdMorph.FaceEdit> .Empty); var level2 = new HdMorph.Level(G3FControlFaceCount, 2, ImmutableArray.Create(faceEdit)); var levels = ImmutableArray.Create(level1, level2); HdMorph hdMorph = new HdMorph(levels); var outFile = new FileInfo(@"C:\Users\Public\Documents\My DAZ 3D Library\data\DAZ 3D\Genesis 3\Female\Morphs\GregTest\FBM-GregHDTest.dhdm"); HdMorphSerialization.SaveHdMorph(outFile, hdMorph); }
private static (QuadTopology, Vector3[]) ApplyHdMorph(HdMorph hdMorph, QuadTopology controlTopology, Vector3[] controlPositions, Refinement refinement) { var applier = HdMorphApplier.Make(controlTopology, controlPositions); var topology = controlTopology; var positions = controlPositions; for (int levelIdx = 1; levelIdx <= hdMorph.MaxLevel; ++levelIdx) { topology = refinement.GetTopology(levelIdx); positions = refinement.Refine(levelIdx, positions); applier.Apply(hdMorph, 1, levelIdx, topology, positions); } return(topology, positions); }
private void ValidateHdMorph(HdMorph hdMorph) { hdMorph.Validate(G3FControlFaceCount); foreach (var level in hdMorph.Levels) { foreach (var faceEdit in level.FaceEdits) { foreach (var vertexEdit in faceEdit.VertexEdits) { float deltaLength = vertexEdit.Delta.Length(); if (deltaLength > 1 || deltaLength < 1e-5) { throw new InvalidOperationException("found unusual delta: " + deltaLength); } } } } }
private void PrintHdMorph(HdMorph hdMorph) { foreach (var level in hdMorph.Levels) { Console.WriteLine($"level {level.LevelIdx}:"); for (int faceEditIdx = 0; faceEditIdx < level.FaceEdits.Length && faceEditIdx < MaxFaceEditsToPrint; ++faceEditIdx) { var faceEdit = level.FaceEdits[faceEditIdx]; Console.WriteLine($" face edit {faceEditIdx} of {level.FaceEdits.Length}:"); Console.WriteLine($" control-face-idx = {faceEdit.ControlFaceIdx}"); foreach (var vertexEdit in faceEdit.VertexEdits) { string pathStr = string.Join(",", vertexEdit.Path); Console.WriteLine($" [{pathStr}]: {vertexEdit.Delta.Length()} {vertexEdit.Delta.FormatForMathematica()}"); } } } }
private static (QuadTopology, Vector3[]) ApplyHdMorph(HdMorph hdMorph, QuadTopology controlTopology, Vector3[] controlPositions) { using (var refinement = new Refinement(controlTopology, hdMorph.MaxLevel)) { return(ApplyHdMorph(hdMorph, controlTopology, controlPositions, refinement)); } }
public WeightedHdMorph(HdMorph morph, float weight) { Morph = morph; Weight = weight; }