public static NativeList <Point> GetPoints(Mesh testMesh, Matrix4x4 localToWorld, out NativeList <int> triangles) { Vector3[] verticesMesh = testMesh.vertices; Vector3[] normalsMesh = testMesh.normals; Vector2[] uv = testMesh.uv; Vector4[] tangents = testMesh.tangents; int[] tri = testMesh.triangles; triangles = new NativeList <int>(tri.Length, Allocator.Temp); triangles.AddRange(tri); NativeList <Point> pointsFromMesh = new NativeList <Point>(verticesMesh.Length, verticesMesh.Length, Allocator.Temp); for (int i = 0; i < pointsFromMesh.Length; ++i) { Vector3 vertex = localToWorld.MultiplyPoint3x4(verticesMesh[i]); Vector4 tangent = localToWorld.MultiplyVector(tangents[i]); Vector3 normal = localToWorld.MultiplyVector(normalsMesh[i]); tangent.w = tangents[i].w; Point p; p.tangent = tangent; p.normal = normal; p.vertex = vertex; p.texcoord = uv[i]; p.objIndex = 0; pointsFromMesh[i] = p; } return(pointsFromMesh); }
public void GetPoints(NativeList <Point> points, NativeList <int> triangles, Mesh targetMesh, int materialIndex, Transform transform) { int originLength = points.Length; Vector3[] vertices = targetMesh.vertices; Vector2[] uv = targetMesh.uv; Vector3[] normal = targetMesh.normals; Vector4[] tangents = targetMesh.tangents; Action <Vector2[], NativeList <Point>, int, int> SetUV; if (uv.Length == vertices.Length) { SetUV = (vec, pt, i, originI) => pt[i].texcoord = vec[originI]; } else { SetUV = (vec, pt, i, originLen) => pt[i].texcoord = Vector3.zero; } Action <Vector3[], NativeList <Point>, int, int> SetNormal; if (normal.Length == vertices.Length) { SetNormal = (vec, pt, i, ori) => pt[i].normal = transform.localToWorldMatrix.MultiplyVector(vec[ori]); } else { SetNormal = (vec, pt, i, ori) => pt[i].normal = Vector3.zero; } Action <Vector4[], NativeList <Point>, int, int> SetTangent; if (tangents.Length == vertices.Length) { SetTangent = (vec, pt, i, ori) => { Vector3 worldTangent = vec[ori]; worldTangent = transform.localToWorldMatrix.MultiplyVector(worldTangent); pt[i].tangent = worldTangent; pt[i].tangent.w = vec[ori].w; }; } else { SetTangent = (vec, pt, i, ori) => pt[i].tangent = Vector4.one; } points.AddRange(vertices.Length); for (int i = originLength; i < vertices.Length + originLength; ++i) { ref Point pt = ref points[i]; int len = i - originLength; pt.vertex = transform.localToWorldMatrix.MultiplyPoint(vertices[len]); SetNormal(normal, points, i, len); SetTangent(tangents, points, i, len); SetUV(uv, points, i, len); pt.objIndex = (uint)materialIndex; }
public void GetPoints(NativeList <float3> points, NativeList <int> triangles, Mesh targetMesh, Transform transform) { int originLength = points.Length; Vector3[] vertices = targetMesh.vertices; points.AddRange(vertices.Length); for (int i = originLength; i < vertices.Length + originLength; ++i) { ref float3 pt = ref points[i]; int len = i - originLength; pt = transform.localToWorldMatrix.MultiplyPoint(vertices[len]); }
public void GetPoints(NativeList <Point> points, NativeList <int> triangles, Mesh targetMesh, int *allMaterialsIndex, Transform transform, Material[] allMats, float4 lightmapScaleOffset, int lightmapIndex) { int originLength = points.Length; Vector3[] vertices = targetMesh.vertices; Vector2[] uv = targetMesh.uv; Vector2[] uv2 = targetMesh.uv2; Vector3[] normal = targetMesh.normals; Vector4[] tangents = targetMesh.tangents; points.AddRange(vertices.Length); for (int i = originLength; i < vertices.Length + originLength; ++i) { ref Point pt = ref points[i]; int len = i - originLength; pt.vertex = transform.localToWorldMatrix.MultiplyPoint(vertices[len]); if (normal.Length == vertices.Length) { points[i].normal = transform.localToWorldMatrix.MultiplyVector(normal[len]); } else { points[i].normal = Vector3.zero; } if (tangents.Length == vertices.Length) { Vector3 worldTangent = tangents[len]; worldTangent = transform.localToWorldMatrix.MultiplyVector(worldTangent); points[i].tangent = worldTangent; points[i].tangent.w = tangents[len].w; } else { points[i].tangent = Vector4.one; } if (uv.Length == vertices.Length) { points[i].texcoord = uv[len]; } else { points[i].texcoord = Vector2.zero; } if (uv2.Length == vertices.Length) { points[i].lightmapUV = (float2)uv2[len] * lightmapScaleOffset.xy + lightmapScaleOffset.zw; } else { points[i].lightmapUV = Vector2.zero; } points[i].lightmapIndex = lightmapIndex; //TODO }
void Add(NativeList <TerrainChunkBuffer> targetBuffers) { int oldCount = loadedBufferList.Length; loadedBufferList.AddRange(targetBuffers); if (loadedBuffer.count < loadedBufferList.Length) { loadedBuffer.Dispose(); culledResultsBuffer.Dispose(); loadedBuffer = new ComputeBuffer(loadedBufferList.Length, sizeof(TerrainChunkBuffer)); culledResultsBuffer = new ComputeBuffer(loadedBufferList.Length, sizeof(int)); loadedBuffer.SetDataPtr(loadedBufferList.unsafePtr, loadedBufferList.Length); } else { loadedBuffer.SetDataPtr(targetBuffers.unsafePtr, oldCount, targetBuffers.Length); } }
private void ReadBack(AsyncGPUReadbackRequest request) { NativeArray <float3x3> values = request.GetData <float3x3>(); finalData.AddRange(values.Ptr(), values.Length); int start = finalData.Length - values.Length; finalData[start] /= values.Length; for (int i = start; i < finalData.Length; ++i) { finalData[start] += finalData[i] / values.Length; } finalData.RemoveLast(values.Length - 1); count++; if (count >= resolution.x * resolution.y * resolution.z) { DisposeBake(); } }
public void AddQuadTrees(NativeList <ulong> addList, NativeArray <float> heightMap) { TerrainQuadTree.QuadTreeNode **tree = (TerrainQuadTree.QuadTreeNode * *)addList.unsafePtr; int length = addList.Length; NativeArray <TerrainPanel> panel = new NativeArray <TerrainPanel>(length, Allocator.Temp, NativeArrayOptions.UninitializedMemory); TerrainPanel *panelPtr = panel.Ptr(); for (int i = 0; i < length; ++i) { tree[i]->listPosition = referenceBuffer.Length + i; int heightIndex = notUsedHeightmapIndices[notUsedHeightmapIndices.Length - 1]; tree[i]->panel.heightMapIndex = heightIndex; notUsedHeightmapIndices.RemoveLast(); heightMapBuffer.SetData(heightMap, 0, heightIndex * (meshSize + 1) * (meshSize + 1), heightMap.Length); panelPtr[i] = tree[i]->panel; } clusterBuffer.SetData(panel, 0, referenceBuffer.Length, length); panel.Dispose(); referenceBuffer.AddRange(addList); }
public void UnloadMaterials(NativeArray <int> indices) { indexPool.AddRange(indices.Ptr(), indices.Length); indices.Dispose(); }