예제 #1
0
        public override NativeList <Point> GetPointsResult(out Material[] targetMaterials)
        {
            targetMaterials = new Material[] { targetMats[(int)(matIndex % (uint)targetMats.Count)] };
            NativeList <Point> allPoints = new NativeList <Point>(triangleBuffer.count * allMatrices.Length, Allocator.Temp);

            Vector3[] vertices, normals;
            Vector2[] uvs;
            Vector4[] tangents;
            PCGLibrary.GetTransformedMeshData(mesh, Matrix4x4.identity, out vertices, out tangents, out uvs, out normals);
            int[] triangles = mesh.triangles;
            for (int i = 0; i < allMatrices.Length; ++i)
            {
                float4x4 mat        = allMatrices[i];
                float4   tileOffset = tileOffsets[i];
                foreach (var t in triangles)
                {
                    float4 tan = tangents[t];
                    allPoints.Add(new Point
                    {
                        normal  = mul(mat, float4(normals[t], 0)).xyz,
                        tangent = float4(mul(mat, float4(tan.xyz, 0)).xyz, tan.w),
                        uv0     = (float2)uvs[t] * tileOffset.xy + tileOffset.zw
                    });
                }
            }
            return(allPoints);
        }
예제 #2
0
        public override void Init(PCGResources res)
        {
            allMatrices = new NativeList <float4x4>(20, Allocator.Persistent);
            tileOffsets = new NativeList <float4>(20, Allocator.Persistent);
            if (!mesh || targetMats.Count <= 0)
            {
                enabled = false;
                return;
            }
            NativeArray <MeshAppdata> meshData;

            int[] tri;
            int   vertLen = PCGLibrary.GetAppDataFromMesh(mesh, out meshData, out tri);

            meshBuffer = new ComputeBuffer(vertLen, sizeof(MeshAppdata));
            meshBuffer.SetData(meshData);
            instanceBuffer = new ComputeBuffer(20, sizeof(PerObjectDatas));
            triangleBuffer = new ComputeBuffer(tri.Length, sizeof(int));
            triangleBuffer.SetData(tri);
        }
예제 #3
0
        public override NativeList <Point> GetPointsResult(out Material[] targetMaterials)
        {
            targetMaterials = new Material[] { mr.sharedMaterial };
            Mesh targetMesh = GetComponent <MeshFilter>().sharedMesh;

            Vector3[] vertices, normals;
            Vector2[] uvs;
            Vector4[] tangents;
            PCGLibrary.GetTransformedMeshData(targetMesh, transform.localToWorldMatrix, out vertices, out tangents, out uvs, out normals);
            NativeList <Point> points = new NativeList <Point>(targetMesh.vertexCount * 2, Unity.Collections.Allocator.Temp);

            for (int i = 0; i < targetMesh.subMeshCount; ++i)
            {
                int[] triangles = targetMesh.GetTriangles(i);
                PCGLibrary.GetPointsWithArrays(points, vertices, normals, uvs, tangents, triangles, i);
                //TODO
                //Material Count
            }
            return(points);
        }