BakeMesh() private method

private BakeMesh ( Mesh mesh ) : void
mesh Mesh
return void
コード例 #1
2
    // TODO: Put this into Misc class?
    private void CreateBlendMesh(SkinnedMeshRenderer skinnedMeshRenderer, Mesh skinnedMesh, string name, bool convex)
    {
        // Detecting how many BlendShapes we have.
        int blendShapeCount = 0;
        blendShapeCount = skinnedMesh.blendShapeCount;
        Debug.Log("BlendShape count bottom: " + blendShapeCount);

        // Applying BlendShapes.
        if (blendShapeCount != 0)
            skinnedMeshRenderer.SetBlendShapeWeight(0, size * 100);

        // Creates a snapshot of the SkinnedMeshRenderer and stores it in the mesh.
        // That skinned mesh renderer should have the shape with the BlendShapes applyied.
        Mesh bakedMesh = new Mesh();
        skinnedMeshRenderer.BakeMesh(bakedMesh);

        // Recalcultate the bounding volume of the mesh from the vertices.
        bakedMesh.RecalculateBounds();
        Debug.Log("Baked mesh bounds: " + bakedMesh.bounds.ToString());

        // Selecting part and destroying MeshCollider in case there is one.
        GameObject child = transform.FindChild(name).gameObject;
        DestroyImmediate(child.GetComponent<MeshCollider>());

        // Adding MeshCollider and assigning the bakedMesh.
        MeshCollider meshCollider = child.AddComponent<MeshCollider>();
        meshCollider.sharedMesh = bakedMesh;
        meshCollider.convex = convex;
    }
 static public int BakeMesh(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.SkinnedMeshRenderer self = (UnityEngine.SkinnedMeshRenderer)checkSelf(l);
         UnityEngine.Mesh a1;
         checkType(l, 2, out a1);
         self.BakeMesh(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
コード例 #3
0
    static int BakeMesh(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                UnityEngine.SkinnedMeshRenderer obj = (UnityEngine.SkinnedMeshRenderer)ToLua.CheckObject <UnityEngine.SkinnedMeshRenderer>(L, 1);
                UnityEngine.Mesh arg0 = (UnityEngine.Mesh)ToLua.CheckObject(L, 2, typeof(UnityEngine.Mesh));
                obj.BakeMesh(arg0);
                return(0);
            }
            else if (count == 3)
            {
                UnityEngine.SkinnedMeshRenderer obj = (UnityEngine.SkinnedMeshRenderer)ToLua.CheckObject <UnityEngine.SkinnedMeshRenderer>(L, 1);
                UnityEngine.Mesh arg0 = (UnityEngine.Mesh)ToLua.CheckObject(L, 2, typeof(UnityEngine.Mesh));
                bool             arg1 = LuaDLL.luaL_checkboolean(L, 3);
                obj.BakeMesh(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.SkinnedMeshRenderer.BakeMesh"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #4
0
ファイル: MeshExpoter.cs プロジェクト: garudaxc/UnityToFbx
    public void Export(SkinnedMeshRenderer skinRender)
    {
        Mesh mesh = skinRender.sharedMesh;
            Mesh staticMesh = new UnityEngine.Mesh();
            skinRender.BakeMesh(staticMesh);

            meshes_.Add(new ExportMesh(mesh, staticMesh));
    }
コード例 #5
0
 static public int BakeMesh(IntPtr l)
 {
     try {
         UnityEngine.SkinnedMeshRenderer self = (UnityEngine.SkinnedMeshRenderer)checkSelf(l);
         UnityEngine.Mesh a1;
         checkType(l, 2, out a1);
         self.BakeMesh(a1);
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static int QPYX_BakeMesh_YXQP(IntPtr L_YXQP)
 {
     try
     {
         ToLua.CheckArgsCount(L_YXQP, 2);
         UnityEngine.SkinnedMeshRenderer QPYX_obj_YXQP = (UnityEngine.SkinnedMeshRenderer)ToLua.CheckObject <UnityEngine.SkinnedMeshRenderer>(L_YXQP, 1);
         UnityEngine.Mesh QPYX_arg0_YXQP = (UnityEngine.Mesh)ToLua.CheckObject(L_YXQP, 2, typeof(UnityEngine.Mesh));
         QPYX_obj_YXQP.BakeMesh(QPYX_arg0_YXQP);
         return(0);
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
コード例 #7
0
 static int BakeMesh(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.SkinnedMeshRenderer obj = (UnityEngine.SkinnedMeshRenderer)ToLua.CheckObject <UnityEngine.SkinnedMeshRenderer>(L, 1);
         UnityEngine.Mesh arg0 = (UnityEngine.Mesh)ToLua.CheckObject(L, 2, typeof(UnityEngine.Mesh));
         obj.BakeMesh(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #8
0
 public static int BakeMesh_wrap(long L)
 {
     try
     {
         long nThisPtr = FCLibHelper.fc_get_inport_obj_ptr(L);
         UnityEngine.SkinnedMeshRenderer obj = get_obj(nThisPtr);
         UnityEngine.Mesh arg0 = FCGetObj.GetObj <UnityEngine.Mesh>(FCLibHelper.fc_get_wrap_objptr(L, 0));
         obj.BakeMesh(arg0);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
     return(0);
 }
コード例 #9
0
ファイル: CFlexSkinnedBody.cs プロジェクト: dvochin/Scripts
    //###LEARN: Start() too late for Flex.  Awake is a must.
    void Awake()
    {
        Color color = Color.green;      //###TODO: Colors!

        _oSMR = gameObject.GetComponent<SkinnedMeshRenderer>();
        _oMeshSkinBaked = new Mesh();
        _oSMR.BakeMesh(_oMeshSkinBaked);                  //###OPT!!! Check how expensive this is.  Is there a way for us to move verts & normals straight from skinned mesh from Flex?  (Have not found a way so far)
        _nVerts = _oMeshSkinBaked.vertexCount;

        Vector3[] vertices = _oMeshSkinBaked.vertices;
        int vertexCount = _oMeshSkinBaked.vertexCount;

        m_particlesCount = vertexCount;                         //###IMPROVE#15: Duplication of CreateFlexObjects(), because we're a subclass of FlexParticles... rethink this?
        m_particles = new uFlex.Particle[vertexCount];
        m_colours = new Color[vertexCount];
        m_velocities = new Vector3[vertexCount];
        m_densities = new float[vertexCount];
        m_particlesActivity = new bool[vertexCount];
        m_colour = color;
        m_interactionType = uFlex.FlexInteractionType.SelfCollideAll;
        m_collisionGroup = -1;

        Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
        Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
        for (int i = 0; i < vertexCount; i++) {
            m_particles[i].pos = vertices[i];
            m_particles[i].invMass = 0;        // These are pinned particles.  They never move from the simulation (we move them to repel clothing, softbody and fluids)
            m_colours[i] = color;
            m_particlesActivity[i] = true;
            min = uFlex.FlexUtils.Min(min, vertices[i]);
            max = uFlex.FlexUtils.Max(max, vertices[i]);
        }
        m_bounds.SetMinMax(min, max);       //###IMPROVE: Use bounds of skinned mesh instead?  Updates itself??

        uFlex.FlexParticlesRenderer partRend = gameObject.AddComponent<uFlex.FlexParticlesRenderer>();
        partRend.m_size = CGame.INSTANCE.particleSpacing;
        partRend.m_radius = partRend.m_size / 2.0f;
        partRend.enabled = false;

        //Material oMat = new Material(Shader.Find("Diffuse"));
        //Texture oTex = Resources.Load("Textures/Woman/A/Torso", typeof(Texture)) as Texture;
        //oMat.mainTexture = oTex;
        //_oSMR.material = oMat;

        uFlex.FlexProcessor oFlexProc = CUtility.FindOrCreateComponent(gameObject, typeof(uFlex.FlexProcessor)) as uFlex.FlexProcessor;
        oFlexProc._oFlexProcessor = this;
    }
    static int BakeMesh(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("UnityEngine.SkinnedMeshRenderer.BakeMesh");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 2);
            UnityEngine.SkinnedMeshRenderer obj = (UnityEngine.SkinnedMeshRenderer)ToLua.CheckObject <UnityEngine.SkinnedMeshRenderer>(L, 1);
            UnityEngine.Mesh arg0 = (UnityEngine.Mesh)ToLua.CheckObject(L, 2, typeof(UnityEngine.Mesh));
            obj.BakeMesh(arg0);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #11
0
ファイル: SkeletonTools.cs プロジェクト: NotYours180/UMA
		public static ValidateResult ValidateSlot(SkinnedMeshRenderer RaceSMR, SkinnedMeshRenderer SlotSMR, out string description)
		{
			var slotMesh = new Mesh();
			SlotSMR.BakeMesh(slotMesh);
			var bounds = slotMesh.bounds;
			if (bounds.max.y < 0.05f)
			{
				description = "Scale Factor on the Model Import Settings seems to be wrong!";
				return ValidateResult.InvalidScale;
			}

			int failure = 0;
			CompareSkeletonRecursive(LocateRoot(RaceSMR.transform.parent), LocateRoot(SlotSMR.transform.parent), ref failure);
			if (failure > 0)
			{
				description = "The Skeleton Hierarchy seems off, check the log for more info.";

				return ValidateResult.SkeletonProblem;
			}

			description = "Everything seems fine.";
			return ValidateResult.Ok;
		}
コード例 #12
0
 public void GetMeshSnapshot()
 {
     if (transform.parent.GetComponent<SkinnedMeshRenderer>() != null)
     {
         skin = transform.parent.GetComponent<SkinnedMeshRenderer>();
         Mesh mesh = new Mesh();
         skin.BakeMesh(mesh);
         foreach (Vector3 v in mesh.vertices)
         {
             Gizmos.DrawSphere(transform.parent.TransformPoint(v), size);
         }
     }
     getMeshSnapShot = false;
 }
コード例 #13
0
ファイル: MoBlur.cs プロジェクト: markkleeb/ArcadeCabs2016
        //public Vector3					prevMotionTranslation;
        public SkinnedData(SkinnedMeshRenderer smr)
        {
            renderer = smr;
            materialCount = renderer.sharedMaterials.Length;
            bakedMesh = new Mesh();
            bakedMesh.MarkDynamic();
            #if !USE_BAKEPOSONLY
            smr.BakeMesh(bakedMesh);
            bakedPrevPos = bakedMesh.vertices;
            #else
            smr.BakeMeshPositionsOnly(bakedMesh, true);
            Mesh.CopyChannel(bakedMesh, bakedMesh, MeshChannel.Vertex, MeshChannel.Normal);
            #endif
            props = new MaterialPropertyBlock();
            props.AddMatrix(SID_PREV_MVP, Matrix4x4.identity);
            prevWorld = renderer.transform.localToWorldMatrix;

            motionTransform = renderer.transform;
            for(var t = motionTransform.parent; t; t = t.parent) {
                var c = t.GetComponent<MoBlurSkinRigidBinding>();
                if(c) {
                    motionTransform = c.motionRoot;
                    break;
                }
            }
        }
コード例 #14
0
    void Start()
    {
        if (useSkinnedMesh)
        {
            var smr = this.GetComponent<SkinnedMeshRenderer>();
            if (smr != null)
            {
                mesh = new Mesh();
                skinnedMesh = smr;
                skinnedMesh.BakeMesh(mesh);
            }
        }
        else
        {
            var mf = this.GetComponent<MeshFilter>();
            if (mf != null)
            {
                mesh = mf.sharedMesh;
            }
        }

        localToWorldCurr = transform.localToWorldMatrix;
        localToWorldPrev = localToWorldCurr;
    }
コード例 #15
0
        private void BakeSkinnedMesh(Animation animation, SkinnedMeshRenderer skinnedMeshRenderer)
        {
            int clipIndex = 0;

            foreach (AnimationState clipState in animation)
            {
                //Prep animation clip for sampling
                var curClip = this.AnimationClipsToBake[clipIndex] = animation.GetClip(clipState.name);
                animation.Play(clipState.name, PlayMode.StopAll);
                clipState.time = 0;
                clipState.wrapMode = WrapMode.Clamp;

                //Calculate number of meshes to bake in this clip sequence based on the clip's sampling framerate
                uint numberOfFrames = (uint)Mathf.RoundToInt(curClip.frameRate * curClip.length);
                var curBakedMeshSequence = this.BakedClips[clipIndex] = new MeshSequence(numberOfFrames);

                for (uint frameIndex = 0; frameIndex < numberOfFrames; frameIndex++)
                {
                    //Bake sequence of meshes
                    var curMeshFrame = curBakedMeshSequence[frameIndex] = new Mesh();
                    curMeshFrame.name = string.Format(@"{0}_Baked_{1}_{2}", this.name, clipIndex, frameIndex);
                    animation.Sample();
                    skinnedMeshRenderer.BakeMesh(curMeshFrame);

                    clipState.time += (1.0f / curClip.frameRate);
                }

                animation.Stop();
                clipIndex++;
            }
        }