// ボーン(ノード)の属性を設定する private static void updateNodeAttrs(BoneGraph g) { foreach (Node node in g.nodes) { NodeInfo info = g.directedEdges[node].Item1; IPXBone bone = (IPXBone)node.pmxElement; if (bone.IsIK) { info.setAttr("IKボーン", ""); } if (bone.Controllable) { info.setAttr("操作可能", ""); } else { info.setAttr("操作不可能", ""); } if (bone.Visible) { info.setAttr("表示", ""); } else { info.setAttr("非表示", ""); } if (bone2bodies.ContainsKey(bone)) { string bodytext = ""; bool first = true; bool dyn = false; foreach (IPXBody body in bone2bodies[bone]) { int bodyIndex = bodyIndexDict[body]; if (!first) { bodytext += ", "; } bodytext += String.Format("{0:D}: {1}", bodyIndex, body.Name); if (BodyMode.Dynamic == body.Mode || BodyMode.DynamicWithBone == body.Mode) { dyn = true; } first = false; } if (dyn) { info.setAttr("物理演算", bodytext); } else { info.setAttr("ボーン追従", bodytext); } } } }
private static BoneGraph makeBoneGraph(IPXPmx pmx) { BoneGraph boneGraph = new BoneGraph(); foreach (IPXBone bone in pmx.Bone) { Node boneNode = makeBoneNode(bone); /////////// // 4 種類のエッジを作成する // (1) 親 -> 子 (type=親子) // (2) 付与親 -> 子 (type=付与親) // (2) IKボーン -> IKターゲットボーン (type=IKターゲット) // (3) IKボーン -> IKリンクボーン (type=IKリンク) boneGraph.addNode(boneNode); // 4種に当てはまらないボーン用 // (1) IPXBone parentBone = bone.Parent; if (null != parentBone) { Node parentNode = makeBoneNode(parentBone); EdgeInfo info = new EdgeInfo(boneNode, "親子"); boneGraph.addEdge(parentNode, info); } // (2) if (null != bone.AppendParent && (bone.IsAppendRotation || bone.IsAppendTranslation)) { Node appendNode = makeBoneNode(bone.AppendParent); EdgeInfo info = new EdgeInfo(boneNode, "付与親"); info.setAttr( "weight", string.Format("{0:F3}", bone.AppendRatio)); boneGraph.addEdge(appendNode, info); } // (3), (4) if (bone.IsIK && null != bone.IK) { if (null != bone.IK.Target) { Node targetNode = makeBoneNode(bone.IK.Target); EdgeInfo targetInfo = new EdgeInfo( targetNode, "IKターゲット"); boneGraph.addEdge(boneNode, targetInfo); } foreach (IPXIKLink ikLink in bone.IK.Links) { Node linkNode = makeBoneNode(ikLink.Bone); EdgeInfo linkInfo = new EdgeInfo( linkNode, "IKリンク"); boneGraph.addEdge(boneNode, linkInfo); } } } return(boneGraph); }
private static void plugin_main( IPXPmx pmx, IPEViewConnector view, IPEFormConnector form) { StreamWriter writer = makeWriter(); using (writer) { makeIndexDict(pmx); makeBone2BodiesDict(pmx); BoneGraph g = makeBoneGraph(pmx); updateNodeAttrs(g); toDot(g, writer); } return; }
private static void toDot(BoneGraph g, StreamWriter writer) { IEnumerable <Node> printNodes = g.nodes; writeHeader(writer); EdgeDict edges = g.directedEdges; foreach (Node node in printNodes) { writeNode(node, edges[node].Item1, writer); } foreach (Node node in printNodes) { writeEdge(node, edges[node].Item2, writer); } writeFooter(writer); }