本文整理汇总了C#中UnityEngine.Mesh.MarkDynamic方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.MarkDynamic方法的具体用法?C# Mesh.MarkDynamic怎么用?C# Mesh.MarkDynamic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Mesh
的用法示例。
在下文中一共展示了Mesh.MarkDynamic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Awake
void Awake()
{
lightMesh = new Mesh();
lightMesh.name = string.Format("Light Mesh ({0})", name);
lightMesh.MarkDynamic();
meshFilter = GetComponent<MeshFilter>();
meshFilter.mesh = lightMesh;
meshRenderer = GetComponent<MeshRenderer>();
meshRenderer.sharedMaterial = lightMaterial;
var container = transform.Find("LightMesh");
if (!container)
{
container = new GameObject("LightMesh").transform;
container.SetParent(transform, true);
container.localPosition = Vector3.zero;
container.gameObject.layer = gameObject.layer;
}
lightMeshCollider = container.GetComponent<PolygonCollider2D>();
if (lightMeshCollider == null)
{
lightMeshCollider = container.gameObject.AddComponent<PolygonCollider2D>();
}
lightMeshCollider.isTrigger = true;
vertices = new List<Vertex>();
UpdateLightFX();
}
示例2: QuadRender
public QuadRender(Material pMaterial, int iQuadCount, Mesh pMesh)
{
//_IndexCache = new IndexCache();
_TotalQuadCount = iQuadCount;
_Quads = new QuadEntry[_TotalQuadCount];
_QuadCount = 0;
_UI = new QuadEntry[_TotalQuadCount];
_UIQuadCount = 0;
for(int i = 0; i < _TotalQuadCount; ++i)
{
_Quads[i] = new QuadEntry();
_UI[i] = new QuadEntry();
}
_Mesh = pMesh;
//_Mesh.bounds.SetMinMax(new Vector3(-1000.0f,-1000.0f,-1000.0f),new Vector3(1000.0f,1000.0f,1000.0f));
_Mesh.MarkDynamic();
_MeshPosition = new Vector3(0.0f,0.0f,0.0f);
_MeshRotation = new Quaternion(0.0f,0.0f,0.0f,0.0f);
_Matrix = Matrix4x4.identity;
_Vertices = new Vector3[_TotalQuadCount * 4 * 2];
_UV = new Vector2[_TotalQuadCount * 4 * 2];
_Colours = new Color32[_TotalQuadCount * 4 * 2];
_Material = pMaterial; //Resources.Load("Quads") as Material;
_LastSize = 0;
}
示例3: Start
// Use this for initialization
void Start()
{
_width = Screen.width;
_height = Screen.height;
_splats0 = new List<Splat>();
_splats1 = new List<Splat>();
_rectangle = new Mesh();
_wetMap = new WetMap(_width, _height);
_threadLock = new object();
_nWetMapUpdateWorkers = 0;
Application.targetFrameRate = 30;
GetComponent<Camera>().orthographicSize = 0.5f * _height;
var pos = GetComponent<Camera>().transform.position;
pos.x = 0.5f * _width;
pos.y = 0.5f * _height;
GetComponent<Camera>().transform.position = pos;
_rectangle.MarkDynamic();
_rectangle.vertices = new Vector3[]{
new Vector3(-1e6f, -1e6f, 0f),
new Vector3(1e6f, -1e6f, 0f),
new Vector3(-1e6f, 1e6f, 0f),
new Vector3(1e6f, 1e6f, 0f) };
var triangles = new int[6];
triangles[0] = 0;
triangles[1] = 3;
triangles[2] = 1;
triangles[3] = 0;
triangles[4] = 2;
triangles[5] = 3;
_rectangle.triangles = triangles;
_rectangle.bounds = new Bounds(Vector3.zero, float.MaxValue * Vector3.one);
}
示例4: DynamicWaterMesh
/// <summary>
/// Initializes a new instance of the <see cref="DynamicWaterMesh"/> class.
/// </summary>
/// <param name="resolution">
/// The number of grid nodes along the bigger side of the mesh.
/// </param>
/// <param name="size">The width and length of the mesh</param>
/// <param name="settings">
/// DynamicWaterSettings instance representing the public settings properties of <see cref="DynamicWater"/> class.
/// </param>
/// <param name="fieldObstruction">
/// The array of <c>byte</c> indicating whether the water is obstructed by an object. \n
/// <c>0</c> means the grid node is obstructed by an object, so the simulation is not updated;
/// <c>255</c> means the grid node is not obstructed, and the simulation can proceed freely.
/// Intermediate values represent the additional dampening value in that node.
/// </param>
public DynamicWaterMesh(int resolution,
Vector2 size,
IDynamicWaterSettings settings,
byte[] fieldObstruction = null)
{
IsReady = false;
_settings = settings;
_size = size;
GridMath.CalculateGrid(resolution, size, out _grid, out _nodeSize);
// Some failsafe
if (_size.x < Vector3.kEpsilon || _size.y < Vector3.kEpsilon) {
_grid = new Vector2Int(1, 1);
}
_mesh = new Mesh();
_mesh.name = "DynamicWaterMesh";
#if !UNITY_3_5
_mesh.MarkDynamic();
#endif
AllocateMeshArrays();
CreateMeshGrid(fieldObstruction);
AssignMesh();
_mesh.RecalculateBounds();
IsReady = true;
}
示例5: UpdateCollisionMesh
/// <summary>
/// Manually recalculates the collision mesh of the skinned mesh on this object.
/// </summary>
public void UpdateCollisionMesh()
{
Mesh mesh = new Mesh();
Vector3[] newVert = new Vector3[skinnedMeshRenderer.sharedMesh.vertices.Length];
// Now get the local positions of all weighted indices...
foreach ( CWeightList wList in nodeWeights )
{
foreach ( CVertexWeight vw in wList.weights )
{
newVert[vw.index] += wList.transform.localToWorldMatrix.MultiplyPoint3x4( vw.localPosition ) * vw.weight;
}
}
// Now convert each point into local coordinates of this object.
for ( int i = 0 ; i < newVert.Length ; i++ )
{
newVert[i] = transform.InverseTransformPoint( newVert[i] );
}
// Update the mesh ( collider) with the updated vertices
mesh.vertices = newVert;
mesh.uv = skinnedMeshRenderer.sharedMesh.uv; // is this even needed here?
mesh.triangles = skinnedMeshRenderer.sharedMesh.triangles;
mesh.RecalculateBounds();
mesh.MarkDynamic(); // says it should improve performance, but I couldn't see it happening
meshCollider.sharedMesh = mesh;
}
示例6: Start
private void Start()
{
// Create overlay container
GameObject overlayContainer = new GameObject("OverlayContainer");
overlayContainer.transform.parent = transform;
// Init overlay material
MeshRenderer meshRenderer = overlayContainer.AddComponent<MeshRenderer>();
MeshFilter meshFilter = overlayContainer.AddComponent<MeshFilter>();
material = new Material(Shader.Find("Transparent/Diffuse"));
material.mainTexture = texture;
meshRenderer.sharedMaterial = material;
overlayMesh = meshFilter.sharedMesh = new Mesh();
overlayMesh.name = "Overlay Mesh";
overlayMesh.MarkDynamic();
overlayMesh.vertices = new Vector3[4];
// Subscribe to events
OnlineMaps.instance.OnChangePosition += UpdateMesh;
OnlineMaps.instance.OnChangeZoom += UpdateMesh;
// Init mesh
UpdateMesh();
}
示例7: Awake
private void Awake()
{
template = MeshE.TetrahedronDraft(0.3f);
swarmCount = Mathf.Min(65000/template.vertices.Count, swarmCount);
simulationUpdate = Mathf.RoundToInt(swarmCount*simulationPercent);
var vertexCount = swarmCount*template.vertices.Count;
draft = new MeshDraft
{
name = "Boids",
vertices = new List<Vector3>(vertexCount),
triangles = new List<int>(vertexCount),
normals = new List<Vector3>(vertexCount),
uv = new List<Vector2>(vertexCount),
colors = new List<Color>(vertexCount)
};
for (var i = 0; i < swarmCount; i++)
{
boids.Add(new Boid());
draft.Add(template);
}
mesh = draft.ToMesh();
mesh.MarkDynamic();
GetComponent<MeshFilter>().mesh = mesh;
Generate();
StartCoroutine(Simulate());
}
示例8: NewMesh
/// <summary>Factory method for creating a new mesh for use in Spine components. This can be called in field initializers.</summary>
public static Mesh NewMesh () {
var m = new Mesh();
m.MarkDynamic();
m.name = "Skeleton Mesh";
m.hideFlags = SpineMesh.MeshHideflags;
return m;
}
示例9: generateMesh
// Generate the water Mesh
public void generateMesh()
{
if (size > 0 && meshPointDistance > 0 && size > (meshPointDistance*2)) {
int numVerticesQuart = Mathf.RoundToInt((size/meshPointDistance)/2f);
int numVerticesHalf = 2* numVerticesQuart;
m = new Mesh();
m.MarkDynamic();
int hCount2 = numVerticesHalf+1;
int vCount2 = numVerticesHalf+1;
int numTriangles = numVerticesHalf * numVerticesHalf * 6;
int numVertices = hCount2 * vCount2;
vertices = new Vector3[numVertices];
Vector2[] uvs = new Vector2[numVertices];
int[] triangles = new int[numTriangles];
int index = 0;
float uvFactorX = 1.0f/numVerticesHalf;
float uvFactorY = 1.0f/numVerticesHalf;
float scaleX = size/numVerticesHalf;
float scaleY = size/numVerticesHalf;
for (float y = 0.0f; y < vCount2; y++)
{
for (float x = 0.0f; x < hCount2; x++)
{
vertices[index] = new Vector3(x*scaleX - size/2f - anchorOffset.x, 0.0f, y*scaleY - size/2f - anchorOffset.y);
uvs[index++] = new Vector2(x*uvFactorX, y*uvFactorY);
}
}
index = 0;
for (int y = 0; y < numVerticesHalf; y++)
{
for (int x = 0; x < numVerticesHalf; x++)
{
triangles[index] = (y * hCount2) + x;
triangles[index+1] = ((y+1) * hCount2) + x;
triangles[index+2] = (y * hCount2) + x + 1;
triangles[index+3] = ((y+1) * hCount2) + x;
triangles[index+4] = ((y+1) * hCount2) + x + 1;
triangles[index+5] = (y * hCount2) + x + 1;
index += 6;
}
}
m.vertices = vertices;
m.uv = uvs;
m.triangles = triangles;
m.RecalculateNormals();
m.RecalculateBounds();
gameObject.GetComponent<MeshFilter>().mesh = m;
UpdateTextureSize();
}
}
示例10: Awake
void Awake()
{
// Initialize the mesh instance.
mesh = new Mesh ();
mesh.MarkDynamic (); //Call this when you continually update mesh vertices.
GetComponent<MeshFilter> ().sharedMesh = mesh;
// Initialize the beam array.
ResetBeams ();
}
示例11: Awake
void Awake()
{
// Initialize the mesh instance.
mesh = new Mesh ();
mesh.MarkDynamic ();
GetComponent<MeshFilter> ().sharedMesh = mesh;
// Initialize the beam array.
ResetBeams ();
}
示例12: InitMesh
void InitMesh()
{
Mesh mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;
// verts
const int numVertsPerFrame = 2;
const int numVertsTotal = numVertsPerFrame * TrailNumFrames;
// indices
const int numSegs = TrailNumFrames - 1;
const int numIndicesPerSeg = 6;
const int numIndicesTotal = numIndicesPerSeg * numSegs;
// init arrays
newVertices = new Vector3[numVertsTotal];
newUV = new Vector2[numVertsTotal];
newTriangles = new int[numIndicesTotal];
// zero out data
float deltaTexCoordU = 1.0f / (TrailNumFrames - 1);
for (int iFrame = 0; iFrame < TrailNumFrames; ++iFrame)
{
int vertIndex = iFrame * numVertsPerFrame;
newVertices[vertIndex + 0] = Vector3.zero;
newVertices[vertIndex + 1] = Vector3.zero;
// can precalc uvs?
newUV[vertIndex + 0] = new Vector2( deltaTexCoordU * iFrame, 0.0f );
newUV[vertIndex + 1] = new Vector2(deltaTexCoordU * iFrame, 1.0f);
}
// indices
for (int i = 0; i < numSegs; ++i )
{
int indexOffset = i * numIndicesPerSeg;
int vertOffset = numVertsPerFrame * i;
newTriangles[indexOffset + 0] = vertOffset+0;
newTriangles[indexOffset + 1] = vertOffset+1;
newTriangles[indexOffset + 2] = vertOffset+3;
newTriangles[indexOffset + 3] = vertOffset + 0;
newTriangles[indexOffset + 4] = vertOffset + 3;
newTriangles[indexOffset + 5] = vertOffset + 2;
}
mesh.vertices = newVertices;
mesh.uv = newUV;
mesh.triangles = newTriangles;
mesh.RecalculateNormals();
mesh.MarkDynamic();
}
示例13: Awake
//new Color(Random.value, Random.value, Random.value,1)
void Awake()
{
// Initialize the mesh instance.
mesh = new Mesh ();
mesh.MarkDynamic (); //Call this when you continually update mesh vertices.
meshfilter = GetComponent<MeshFilter> ();
meshfilter.sharedMesh = mesh;
meshcollider = GetComponent<MeshCollider> ();
//rigidb = GetComponent<Rigidbody> ();
//Application.targetFrameRate = 30;
Application.runInBackground = true;
maincam = GameObject.FindGameObjectWithTag ("MainCamera").GetComponent<Camera>();
}
示例14: QuadBatch
public QuadBatch(GameObject gameObject)
{
_alpha = 1f;
this.gameObject = gameObject;
_shader = ShaderConfig.imageShader;
meshFilter = gameObject.AddComponent<MeshFilter>();
meshRenderer = gameObject.AddComponent<MeshRenderer>();
meshRenderer.shadowCastingMode = ShadowCastingMode.Off;
meshRenderer.receiveShadows = false;
mesh = new Mesh();
mesh.hideFlags = HideFlags.DontSave;
mesh.MarkDynamic();
}
示例15: PCTrail
public PCTrail(int numPoints)
{
Mesh = new Mesh();
Mesh.MarkDynamic();
verticies = new Vector3[2 * numPoints];
normals = new Vector3[2 * numPoints];
uvs = new Vector2[2 * numPoints];
colors = new Color[2 * numPoints];
indicies = new int[2 * (numPoints) * 3];
Points = new CircularBuffer<PCTrailPoint>(numPoints);
}