- Home /
Update Mesh immediately for rendering While changing blendshape
Hi guys, I change blendshape value of my fbx model at runtime, and placed a camera to render this model. For some purpose, I need capture the camera texture after changing blendshape of this model immediately.
However, The camera texture can only show the mesh before changing blendshape. I know this mesh will update in next frame, but I can't wait until that time. Is there any method to update this mesh for rendering right now?
human.GetComponentInChildren<SkinnedMeshRenderer>().SetBlendShapeWeight(0, 100);
human.GetComponentInChildren<SkinnedMeshRenderer>().SetBlendShapeWeight(1, 100);
CaptureCameraTexture();
this is my function for capture camera texture.
public Texture2D CaptureCameraTexture(string path = null)
{
Texture2D camTex = new Texture2D(cameraWidth, cameraHeight, TextureFormat.RGBAFloat, false);
RenderTexture rt = new RenderTexture(Screen.width, Screen.height, 1);
cam.targetTexture = rt;
cam.Render();
RenderTexture.active = rt;
camTex.ReadPixels(new Rect(0, 0, cameraWidth, cameraHeight), 0, 0);
Debug.Log(camTex.GetPixel(cameraWidth / 2, cameraHeight / 2));
Debug.Log(camTex.GetPixel(cameraWidth / 2+1, cameraHeight / 2));
cam.targetTexture = null;
RenderTexture.active = null;
UnityEngine.Object.Destroy(rt);
SaveImg(camTex, path);
return camTex;
}
Answer by Bunny83 · Jul 17, 2018 at 10:26 AM
Well the skinning of a SkinnedMeshRenderer takes place during the animation update. You can try using SkinnedMeshRenderer.BakeMesh and use the baked mesh for rendering. However i'm not sure if blendshapes are baked as well with this method, though logically it should.
Skinned$$anonymous$$eshRenderer.Bake$$anonymous$$esh does work to get the mesh with blendshape. However, how can I put this mesh into the scene and let the camera can render it immediately?
I find it works. However, I need all this to become really fast. Because I need to change the blendshape thousand times. It there a more efficiency way? I just find my function to CaptureCameraTexture cost the most time, any advice to acquire this render results more efficient?
Your answer
Follow this Question
Related Questions
Sun-shaft camera glitch 0 Answers
Problem of using multiple scripts attached to camera containing OnPostRender() for VR projects 0 Answers
Masking elements with non-rendered layers? Culling masks, camera, render textures 0 Answers
Can't draw renderTexture to screen 1 Answer
How can I make a quad render below absolutely everything else? 1 Answer