本文整理汇总了C#中UnityEngine.SkinnedMeshRenderer.BakeMesh方法的典型用法代码示例。如果您正苦于以下问题:C# SkinnedMeshRenderer.BakeMesh方法的具体用法?C# SkinnedMeshRenderer.BakeMesh怎么用?C# SkinnedMeshRenderer.BakeMesh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.SkinnedMeshRenderer
的用法示例。
在下文中一共展示了SkinnedMeshRenderer.BakeMesh方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBlendMesh
// 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;
}
示例2: Export
public void Export(SkinnedMeshRenderer skinRender)
{
Mesh mesh = skinRender.sharedMesh;
Mesh staticMesh = new UnityEngine.Mesh();
skinRender.BakeMesh(staticMesh);
meshes_.Add(new ExportMesh(mesh, staticMesh));
}
示例3: Awake
//###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;
}
示例4: ValidateSlot
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;
}
示例5: GetMeshSnapshot
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;
}
示例6: SkinnedData
//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;
}
}
}
示例7: Start
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;
}
示例8: BakeSkinnedMesh
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++;
}
}