private static List <int> FindVerticesAttachedToBone(Geometry geometry, SkinBinding skinBinding, Bone bone)
    {
        var boneIndex = skinBinding.Bones.IndexOf(bone);

        List <int> attachedVertices = new List <int>();

        for (int vertexIdx = 0; vertexIdx < geometry.VertexCount; ++vertexIdx)
        {
            var boneWeights = skinBinding.BoneWeights.GetElements(vertexIdx);
            foreach (var boneWeight in boneWeights)
            {
                if (boneWeight.Index != boneIndex)
                {
                    continue;
                }

                if (boneWeight.Weight != 1)
                {
                    throw new Exception("must be fully attached or fully unattached");
                }

                attachedVertices.Add(vertexIdx);
            }
        }

        return(attachedVertices);
    }
    public static ImporterOcclusionSurrogate Make(Geometry geometry, SkinBinding skinBinding, Bone bone)
    {
        List <int> attachedVertices = FindVerticesAttachedToBone(geometry, skinBinding, bone);
        List <int> attachedFaces    = FindAttachedFaces(geometry, attachedVertices);

        return(new ImporterOcclusionSurrogate(bone, attachedVertices, attachedFaces));
    }
Beispiel #3
0
 public BoneAttributesCalculator(ChannelSystem channelSystem, BoneSystem boneSystem, Geometry geometry, SkinBinding skinBinding)
 {
     this.channelSystem = channelSystem;
     this.boneSystem    = boneSystem;
     this.geometry      = geometry;
     this.skinBinding   = skinBinding;
 }
    public Figure Bake(Figure parentFigure)
    {
        if (Channels == null)
        {
            Channels = new List <ChannelRecipe>();
        }
        if (Formulas == null)
        {
            Formulas = new List <FormulaRecipe>();
        }
        if (Morphs == null)
        {
            Morphs = new List <MorphRecipe>();
        }

        Geometry geometry = Geometry.Bake();

        Dictionary <string, UvSet> uvSets = new Dictionary <string, UvSet>();

        UvSets.ForEach(recipe => recipe.Bake(geometry, uvSets));
        UvSet defaultUvSet = uvSets[Geometry.DefaultUvSet];

        ChannelSystem channelSystem = new ChannelSystemRecipe(Channels, Formulas).Bake(parentFigure?.ChannelSystem);

        int graftVertexOffset = Geometry.VertexPositions.Length;

        List <MorphRecipe> rewrittenMorphRecipes = Automorpher != null?Automorpher.Rewrite(Morphs, parentFigure) : Morphs;

        List <Morph> morphs  = rewrittenMorphRecipes.Select(recipe => recipe.Bake(channelSystem.ChannelsByName)).ToList();
        Morpher      morpher = new Morpher(morphs);

        Automorpher automorpher = Automorpher?.Bake();

        BoneSystem selfBoneSystem = new BoneSystemRecipe(Bones).Bake(channelSystem.ChannelsByName);

        BoneSystem boneSystem;

        RigidTransform[] childToParentBindPoseTransforms;
        if (parentFigure != null)
        {
            boneSystem = parentFigure.BoneSystem;
            childToParentBindPoseTransforms = MakeChildToParentBindPoseTransforms(channelSystem, selfBoneSystem, boneSystem);
        }
        else
        {
            boneSystem = selfBoneSystem;
            childToParentBindPoseTransforms = null;
        }

        SkinBinding skinBinding = SkinBinding.Bake(boneSystem.BonesByName, selfBoneSystem.BonesByName);

        OcclusionBinding occlusionBinding = OcclusionBinding.MakeForFigure(Name, geometry, boneSystem, skinBinding);

        return(new Figure(Name, parentFigure, this, geometry, channelSystem, boneSystem, childToParentBindPoseTransforms, morpher, automorpher, skinBinding, uvSets, defaultUvSet, occlusionBinding));
    }
 public Figure(string name, Figure parent, FigureRecipe recipe, Geometry geometry, ChannelSystem channelSystem, BoneSystem boneSystem, RigidTransform[] childToParentBindPoseTransforms, Morpher morpher, Automorpher automorpher, SkinBinding skinBinding, Dictionary <string, UvSet> uvSets, UvSet defaultUvSet, OcclusionBinding occlusionBinding)
 {
     this.name          = name;
     this.parent        = parent;
     this.recipe        = recipe;
     this.geometry      = geometry;
     this.channelSystem = channelSystem;
     this.boneSystem    = boneSystem;
     this.childToParentBindPoseTransforms = childToParentBindPoseTransforms;
     this.morpher          = morpher;
     this.automorpher      = automorpher;
     this.skinBinding      = skinBinding;
     this.uvSets           = uvSets;
     this.defaultUvSet     = defaultUvSet;
     this.occlusionBinding = occlusionBinding;
 }
 public static List <ImporterOcclusionSurrogate> MakeForFigure(string figureName, Geometry geometry, BoneSystem boneSystem, SkinBinding skinBinding)
 {
     if (figureName == "genesis-3-female")
     {
         return(new List <ImporterOcclusionSurrogate> {
             Make(geometry, skinBinding, boneSystem.BonesByName["lEye"]),
             Make(geometry, skinBinding, boneSystem.BonesByName["rEye"])
         });
     }
     else
     {
         return(new List <ImporterOcclusionSurrogate>());
     }
 }
Beispiel #7
0
    public static OcclusionBinding MakeForFigure(string figureName, Geometry geometry, BoneSystem boneSystem, SkinBinding skinBinding)
    {
        var surrogates = ImporterOcclusionSurrogate.MakeForFigure(figureName, geometry, boneSystem, skinBinding);

        return(new OcclusionBinding(geometry.VertexCount, surrogates));
    }