Ejemplo n.º 1
0
        protected override JobHandle ScheduleMeshingJob(JobHandle dependency = default)
        {
            DetermineSplineSettings(out Space splineSpace, out Matrix4x4 localToWorldMatrix, out Matrix4x4 worldToLocalMatrix);

            var job = new BuildMeshFromSpline_Tube()
            {
                quality       = quality,
                tube_quality  = tube_quality,
                width         = scaleMult.x,
                height        = scaleMult.y,
                uv_tile_scale = uv_tile_scale,
                minimum_distance_between_points = minimum_distance_between_points,
                minimum_dot_between_forwards    = minimum_dot_between_forwards,
                max_distance_between_points     = max_distance_between_points,
                use_splinepoint_rotations       = use_splinepoint_rotations,
                use_splinepoint_scale           = use_splinepoint_scale,
                vertexOffset        = vertexOffset,
                rotationEulorOffset = rotationEulorOffset,
                normalsMode         = MeshNormalsMode,
                uvsMode             = UVsMode,

                verts    = _nativeVertices,
                normals  = _nativeNormals,
                tangents = _nativeTangents,
                uvs0     = _nativeUV0,
                uvs1     = _nativeUV1,
                tris     = _nativeTris,
                bounds   = _nativeBounds,

                Points       = SplineReference.NativePoints,
                Mode         = SplineReference.GetSplineMode(),
                ClosedSpline = SplineReference.GetSplineClosed(),

                SplineSpace        = splineSpace,
                worldToLocalMatrix = worldToLocalMatrix,
                localToWorldMatrix = localToWorldMatrix,

                built_to_t            = built_to_t,
                cover_ends_with_quads = cover_ends_with_quads,
            };

            return(job.Schedule(dependency));
        }
        protected override JobHandle ScheduleMeshingJob(JobHandle dependency = default)
        {
            if (RepeatableMesh == null)
            {
                return(dependency);
            }

            // todo: cache
            cache_tris.Clear();
            cache_verts.Clear();
            cache_normals.Clear();
            cache_tangents.Clear();
            cache_uv0.Clear();
            cache_colors.Clear();

            native_tris.Clear();
            native_verts.Clear();
            native_uv0.Clear();
            native_colors.Clear();

            // fetch the data from the repeatable mesh
            RepeatableMesh.GetTriangles(cache_tris, 0);
            RepeatableMesh.GetVertices(cache_verts);

            for (var t = 0; t < cache_tris.Count; ++t)
            {
                native_tris.Add(cache_tris[t]);
            }

            for (var v = 0; v < cache_verts.Count; ++v)
            {
                native_verts.Add(cache_verts[v]);
            }

            // check if this repeatable mesh actually has the attributes we want..
            var has_normals  = RepeatableMesh.HasVertexAttribute(UnityEngine.Rendering.VertexAttribute.Normal);
            var has_tangents = RepeatableMesh.HasVertexAttribute(UnityEngine.Rendering.VertexAttribute.Tangent);
            var has_uv0      = RepeatableMesh.HasVertexAttribute(UnityEngine.Rendering.VertexAttribute.TexCoord0);
            var has_color    = RepeatableMesh.HasVertexAttribute(UnityEngine.Rendering.VertexAttribute.Color);

            if (has_normals)
            {
                RepeatableMesh.GetNormals(cache_normals);

                for (var v = 0; v < cache_normals.Count; ++v)
                {
                    native_normals.Add(cache_normals[v]);
                }
            }
            else
            {
                for (var v = 0; v < cache_verts.Count; ++v)
                {
                    native_normals.Add(Vector3.up);
                }
            }

            if (has_tangents)
            {
                RepeatableMesh.GetTangents(cache_tangents);

                for (var v = 0; v < cache_tangents.Count; ++v)
                {
                    native_tangents.Add(cache_tangents[v]);
                }
            }
            else
            {
                for (var v = 0; v < cache_verts.Count; ++v)
                {
                    native_tangents.Add(Vector3.right);
                }
            }

            if (has_uv0)
            {
                RepeatableMesh.GetUVs(0, cache_uv0);

                for (var v = 0; v < cache_uv0.Count; ++v)
                {
                    native_uv0.Add(cache_uv0[v]);
                }
            }
            else
            {
                for (var v = 0; v < cache_verts.Count; ++v)
                {
                    native_uv0.Add(Vector4.zero);
                }
            }

            if (has_color)
            {
                RepeatableMesh.GetColors(cache_colors);

                for (var v = 0; v < cache_colors.Count; ++v)
                {
                    native_colors.Add(new Vector4(cache_colors[v].r, cache_colors[v].g, cache_colors[v].b, cache_colors[v].a));
                }
            }
            else
            {
                for (var v = 0; v < cache_verts.Count; ++v)
                {
                    native_colors.Add(Color.white);
                }
            }

            // try and find start and end z values
            var z_min = float.MaxValue;
            var z_max = float.MinValue;

            for (var v = 0; v < native_verts.Length; ++v)
            {
                var vertex = native_verts[v];
                if (vertex.z < z_min)
                {
                    z_min = vertex.z;
                }

                if (vertex.z > z_max)
                {
                    z_max = vertex.z;
                }
            }

            DetermineSplineSettings(out Space splineSpace, out Matrix4x4 localToWorldMatrix, out Matrix4x4 worldToLocalMatrix);

            var job = new BuildMeshFromSpline_RepeatingMesh()
            {
                repeatingMesh_tris     = native_tris,
                repeatingMesh_verts    = native_verts,
                repeatingMesh_normals  = native_normals,
                repeatingMesh_tangents = native_tangents,
                repeatingMesh_uv0      = native_uv0,
                repeatingMesh_colors   = native_colors,
                repeatingMesh_bounds   = RepeatableMesh.bounds,

                repeatingMesh_has_colors = native_colors.Length == native_verts.Length,
                repeatingMesh_has_uv0    = native_uv0.Length == native_verts.Length,

                MeshLocalOffsetVertices = vertexOffset,
                UseRepeatingMeshUVs     = UseRepeatingMeshUVs,

                built_to_t          = built_to_t,
                quality             = quality,
                uv_tile_scale       = uv_tile_scale,
                scale               = scaleMult,
                rotationEulorOffset = rotationEulorOffset,
                normalsMode         = MeshNormalsMode,
                uvsMode             = UVsMode,

                verts    = _nativeVertices,
                normals  = _nativeNormals,
                tangents = _nativeTangents,
                bounds   = _nativeBounds,
                colors   = _nativeColors,

                uv0s = _nativeUV0,
                uv1s = _nativeUV1,
                tris = _nativeTris,

                Points       = SplineReference.NativePoints,
                Mode         = SplineReference.GetSplineMode(),
                ClosedSpline = SplineReference.GetSplineClosed(),

                SplineSpace        = splineSpace,
                worldToLocalMatrix = worldToLocalMatrix,
                localToWorldMatrix = localToWorldMatrix,
            };

            return(job.Schedule(dependency));
        }