public void ImportFrom(DsonTypes.Node node)
    {
        BoneRecipe recipe = new BoneRecipe {
            Name          = node.name,
            Parent        = node.parent?.ReferencedObject.name,
            RotationOrder = node.rotation_order,
            InheritsScale = node.inherits_scale
        };

        boneRecipes.Add(recipe);
    }
Example #2
0
    public void ImportFrom(DsonTypes.Node node)
    {
        string label      = node.label ?? node.name;
        string pathPrefix = "/Joints/" + label;

        ImportTriplet(node.center_point, node.name + "?center_point", pathPrefix);
        ImportTriplet(node.end_point, node.name + "?end_point", pathPrefix);
        ImportTriplet(node.orientation, node.name + "?orientation", pathPrefix);
        ImportTriplet(node.rotation, node.name + "?rotation", pathPrefix);
        ImportTriplet(node.translation, node.name + "?translation", pathPrefix);
        ImportTriplet(node.scale, node.name + "?scale", pathPrefix);
        Import(node.general_scale, "general_scale", node.name + "?scale/general", pathPrefix);
    }
    public void Import(DsonTypes.SkinBinding skinBinding)
    {
        int vertexCount = skinBinding.vertex_count;

        List <List <BoneWeight> > boneWeightsByVertex = new List <List <BoneWeight> >(vertexCount);

        for (int i = 0; i < vertexCount; ++i)
        {
            boneWeightsByVertex.Add(new List <BoneWeight>());
        }

        DsonTypes.WeightedJoint[] joints = skinBinding.joints;

        string[] boneNames = new string[joints.Length];

        for (int boneIdx = 0; boneIdx < joints.Length; ++boneIdx)
        {
            DsonTypes.WeightedJoint joint = joints[boneIdx];

            if (joint.node_weights == null)
            {
                throw new InvalidOperationException("expected scale_weights to be non-null");
            }
            if (joint.scale_weights != null)
            {
                throw new InvalidOperationException("expected scale_weights to be null");
            }
            if (joint.local_weights != null)
            {
                throw new InvalidOperationException("expected local_weights to be null");
            }
            if (joint.bulge_weights != null)
            {
                throw new InvalidOperationException("expected bulge_weights to be null");
            }

            DsonTypes.Node jointNode = joint.node.ReferencedObject;
            boneNames[boneIdx] = jointNode.name;

            foreach (DsonTypes.IndexedFloat elem in joint.node_weights.values)
            {
                boneWeightsByVertex[elem.index].Add(new BoneWeight(boneIdx, (float)elem.value));
            }
        }

        Dictionary <string, string> faceGroupToNodeMap = new Dictionary <string, string>();

        if (skinBinding.selection_map.Length != 1)
        {
            throw new InvalidOperationException("expected only one face-group-to-node map");
        }
        foreach (DsonTypes.StringPair pair in skinBinding.selection_map[0].mappings)
        {
            faceGroupToNodeMap.Add(pair.from, pair.to);
        }

        SkinBindingRecipe recipe = new SkinBindingRecipe {
            BoneNames          = boneNames,
            BoneWeights        = PackedLists <BoneWeight> .Pack(boneWeightsByVertex),
            FaceGroupToNodeMap = faceGroupToNodeMap
        };

        recipes.Add(recipe);
    }