Exemplo n.º 1
0
    public void Update(Vector3d camRadialPos, double camDist, ref List <NodeUpdateJob> render, bool parentdraw = false)
    {
        NodeUpdateJob.RenderFlags flags = NodeUpdateJob.RenderFlags.None;

        if (grassindices != null)
        {
            flags |= NodeUpdateJob.RenderFlags.Grass;
        }

        if (isSplit)
        {
            if (!immediateChildrenGenerated && !parentdraw)
            {
                if (generated && hasVisibleVertices)
                {
                    flags     |= NodeUpdateJob.RenderFlags.Surface;
                    parentdraw = true;
                }
            }

            children[0].Update(camRadialPos, camDist, ref render, parentdraw);
            children[1].Update(camRadialPos, camDist, ref render, parentdraw);
            children[2].Update(camRadialPos, camDist, ref render, parentdraw);
            children[3].Update(camRadialPos, camDist, ref render, parentdraw);

            if (!immediateChildrenSplit)
            {
                DynamicSplit(camRadialPos);
            }
        }
        else
        {
            DynamicSplit(camRadialPos);
            if ((parent == null || parent.immediateChildrenGenerated) && !parentdraw && generated && hasVisibleVertices)
            {
                flags |= NodeUpdateJob.RenderFlags.Surface;
            }
        }

        if (flags != NodeUpdateJob.RenderFlags.None && IsAboveHorizon(ScaleSpace.instance.cameraPosition, camDist))
        {
            render.Add(new NodeUpdateJob(this, flags));
        }
    }
Exemplo n.º 2
0
    public void Draw(NodeUpdateJob.RenderFlags flags)
    {
        if (!mesh)
        {
            SetMeshData();
        }

        if (!mesh)
        {
            return;
        }

        if (setIndex != -1)
        {
            Profiler.BeginSample("Set Indices");
            mesh.SetIndices(TriangleCache.IndexCache[setIndex], MeshTopology.Triangles, 0);
            setIndex = -1;
            Profiler.EndSample();
        }

        Profiler.BeginSample("Node Calculations");
        Vector3d pos  = planet.position + planet.rotation * meshPos;
        double   dist = Vector3d.Dot((Vector3d)ScaleSpace.instance.mainCamera.transform.forward, pos - ScaleSpace.instance.cameraPosition);

        Profiler.EndSample();

        Profiler.BeginSample("Node Collider Position");
        if (mc)
        {
            mc.transform.position = (Vector3)(pos - ScaleSpace.instance.origin);
            mc.transform.rotation = (Quaternion)planet.rotation;
        }
        Profiler.EndSample();

        Profiler.BeginSample("Node Property Set");
        planet.propertyBlock.SetMatrix("_NodeToPlanet", node2planet);
        Profiler.EndSample();

        Profiler.BeginSample("World Space Draw");
        if (dist < ScaleSpace.instance.mainCamera.farClipPlane + radius)
        {
            // world space mesh
            trs = Matrix4x4.TRS(
                (Vector3)(pos - ScaleSpace.instance.origin),
                (Quaternion)planet.rotation,
                Vector3.one * (float)size);

            if ((flags & NodeUpdateJob.RenderFlags.Surface) > 0)
            {
                Graphics.DrawMesh(mesh, trs, renderMaterial, 1, null, 0, planet.propertyBlock);
            }

            // grass
            trs = Matrix4x4.TRS(
                (Vector3)(pos - ScaleSpace.instance.origin),
                (Quaternion)planet.rotation,
                Vector3.one);
            if ((flags & NodeUpdateJob.RenderFlags.Grass) > 0 && planet.hasGrass && grassindices != null)
            {
                Graphics.DrawMesh(grassmesh, trs, planet.grassMaterial, 1, null, 0, planet.propertyBlock);
            }
        }
        Profiler.EndSample();

        if ((flags & NodeUpdateJob.RenderFlags.Surface) > 0)
        {
            Profiler.BeginSample("Scale Space Draw");
            if (dist > ScaleSpace.instance.mainCamera.farClipPlane - radius)
            {
                // scaled space mesh
                trs = Matrix4x4.TRS(
                    (Vector3)(pos * ScaleSpace.instance.scale),
                    (Quaternion)planet.rotation,
                    Vector3.one * (float)(size * ScaleSpace.instance.scale));
                Graphics.DrawMesh(mesh, trs, renderMaterial, ScaleSpace.instance.layer, null, 0, planet.propertyBlock);
            }
            Profiler.EndSample();
        }
    }