当前位置: 首页>>代码示例>>C#>>正文


C# Bone.Select方法代码示例

本文整理汇总了C#中Bone.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Bone.Select方法的具体用法?C# Bone.Select怎么用?C# Bone.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bone的用法示例。


在下文中一共展示了Bone.Select方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CalculateBoneWeights

    public static Bone2DWeights CalculateBoneWeights(Transform owner, Bone[] bones, Mesh mesh)
    {
        if (bones != null) {
            Bone2DWeights boneWeights = new Bone2DWeights();
            boneWeights.weights = new Bone2DWeight[] { };

            int vIndex = 0;
            foreach (Vector3 v in mesh.vertices) {
                Bone closest = FindClosestBone(v, bones);
                if (closest != null) {
                    boneWeights.SetWeight(vIndex++, closest.name, Array.IndexOf(bones, closest), 1f);
                }
            }

            BoneWeight[] unitweights = boneWeights.GetUnityBoneWeights();
            mesh.boneWeights = unitweights;

            Transform[] bonesArr = bones.Select(b => b.transform).ToArray();
            Matrix4x4[] bindPoses = new Matrix4x4[bonesArr.Length];

            for (int i = 0; i < bonesArr.Length; i++) {
                bindPoses[i] = bonesArr[i].worldToLocalMatrix * owner.localToWorldMatrix;
            }

            mesh.bindposes = bindPoses;

            return boneWeights;
        }

        return null;
    }
开发者ID:shkilevk,项目名称:Jury-rig-a-2D-game-workshop,代码行数:31,代码来源:SpriteMesh.cs

示例2: CalculateBoneWeights

    public void CalculateBoneWeights(Bone[] bones, bool weightToParent)
    {
        if(MeshFilter.sharedMesh == null)
        {
            Debug.Log("No Shared Mesh.");
            return;
        }
        Mesh mesh = new Mesh();
        mesh.name = "Generated Mesh";
        mesh.vertices = MeshFilter.sharedMesh.vertices;
        mesh.triangles = MeshFilter.sharedMesh.triangles;
        mesh.normals = MeshFilter.sharedMesh.normals;
        mesh.uv = MeshFilter.sharedMesh.uv;
        mesh.uv2 = MeshFilter.sharedMesh.uv2;
        mesh.bounds = MeshFilter.sharedMesh.bounds;

        if (bones != null) {
            boneWeights = new Bone2DWeights();
            boneWeights.weights = new Bone2DWeight[] { };

            int index = 0;
            foreach (Bone bone in bones) {
                int i=0;

                foreach (Vector3 v in mesh.vertices) {
                    float influence;
                    if (!weightToParent || bone.transform != transform.parent)
                    {
                        influence = bone.GetInfluence(v + transform.position);
                    }
                    else
                    {
                        influence = 1.0f;
                    }

                    boneWeights.SetWeight(i, bone.name, index, influence);
                    i++;
                }

                index++;
            }

            BoneWeight[] unitweights = boneWeights.GetUnityBoneWeights();
            mesh.boneWeights = unitweights;

            Transform[] bonesArr = bones.Select(b => b.transform).ToArray();
            Matrix4x4[] bindPoses = new Matrix4x4[bonesArr.Length];

            for (int i = 0; i < bonesArr.Length; i++) {
                bindPoses[i] = bonesArr[i].worldToLocalMatrix * transform.localToWorldMatrix;
            }

            mesh.bindposes = bindPoses;

            var skinRenderer = GetComponent<SkinnedMeshRenderer>();
            if (skinRenderer.sharedMesh != null && !AssetDatabase.Contains(skinRenderer.sharedMesh.GetInstanceID()))
                Object.DestroyImmediate(skinRenderer.sharedMesh);
            skinRenderer.bones = bonesArr;
            skinRenderer.sharedMesh = mesh;
        }
    }
开发者ID:juanwinsor,项目名称:SuperDanger,代码行数:61,代码来源:Skin2D.cs

示例3: CalculateBoneWeights

    public void CalculateBoneWeights(Bone[] bones, bool weightToParent)
    {
        if (!lockBoneWeights) {
            if(meshFilter.sharedMesh == null) {
                Debug.Log("No Shared Mesh.");
                return;
            }
            Mesh mesh = new Mesh();
            mesh.name = meshFilter.sharedMesh.name;
            mesh.name = mesh.name.Replace(".Mesh", ".SkinnedMesh");
            mesh.vertices = meshFilter.sharedMesh.vertices;
            mesh.triangles = meshFilter.sharedMesh.triangles;
            mesh.normals = meshFilter.sharedMesh.normals;
            mesh.uv = meshFilter.sharedMesh.uv;
            mesh.uv2 = meshFilter.sharedMesh.uv2;
            mesh.bounds = meshFilter.sharedMesh.bounds;

            if (bones != null && mesh != null) {
                boneWeights = new Bone2DWeights();
                boneWeights.weights = new Bone2DWeight[] { };

                int index = 0;
                foreach (Bone bone in bones) {
                    int i=0;

                    bool boneActive = bone.gameObject.activeSelf;
                    bone.gameObject.SetActive(true);
                    foreach (Vector3 v in mesh.vertices) {
                        float influence;
                        if (!weightToParent || weightToParent && bone.transform != transform.parent) {
                            influence = bone.GetInfluence(v + transform.position);
                        }
                        else {
                            influence = 1.0f;
                        }

                        boneWeights.SetWeight(i, bone.name, index, influence);

                        i++;
                    }

                    index++;
                    bone.gameObject.SetActive(boneActive);
                }

                BoneWeight[] unitweights = boneWeights.GetUnityBoneWeights();
                mesh.boneWeights = unitweights;

                Transform[] bonesArr = bones.Select(b => b.transform).ToArray();
                Matrix4x4[] bindPoses = new Matrix4x4[bonesArr.Length];

                for (int i = 0; i < bonesArr.Length; i++) {
                    bindPoses[i] = bonesArr[i].worldToLocalMatrix * transform.localToWorldMatrix;
                }

                mesh.bindposes = bindPoses;

                skinnedMeshRenderer.bones = bonesArr;

                Skeleton[] skeletons = transform.root.gameObject.GetComponentsInChildren<Skeleton>(true);
                Skeleton skeleton = null;
                foreach (Skeleton s in skeletons) {
                    if (transform.IsChildOf(s.transform))
                    {
                        skeleton = s;
                    }
                }

                DirectoryInfo meshSkelDir = new DirectoryInfo("Assets/Meshes/SkinnedMeshes/" + skeleton.gameObject.name);
                if (Directory.Exists(meshSkelDir.FullName) == false) {
                    Directory.CreateDirectory(meshSkelDir.FullName);
                }

                string path = "Assets/Meshes/SkinnedMeshes/" + skeleton.gameObject.name + "/" + mesh.name + ".asset";

                CreateOrReplaceAsset (mesh, path);
                AssetDatabase.Refresh();

                Mesh generatedMesh = AssetDatabase.LoadAssetAtPath (path, typeof(Mesh)) as Mesh;

                // Ensure it has bindPoses and weights
                generatedMesh.boneWeights = unitweights;
                generatedMesh.bindposes = bindPoses;

                skinnedMeshRenderer.sharedMesh = generatedMesh;
                EditorUtility.SetDirty(skinnedMeshRenderer.gameObject);
                AssetDatabase.SaveAssets();
            }
        }
    }
开发者ID:Banbury,项目名称:UnitySpritesAndBones,代码行数:90,代码来源:Skin2D.cs


注:本文中的Bone.Select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。