Example #1
0
        private void RenderTiledMesh(Camera cam)
        {
            bool isBackface = cam.transform.position.y < transform.position.y;

            if (isBackface && !ShouldRenderBackface)
            {
                return;
            }

            MaterialProperties.Clear();
            if (Profile.EnableReflection)
            {
                MaterialProperties.SetTexture(PMat.REFLECTION_TEX, GetReflectionRt(cam));
            }
            MaterialProperties.SetTexture(PMat.NOISE_TEX, PPoseidonSettings.Instance.NoiseTexture);

            Material mat = isBackface ? MaterialBackFace : MaterialToRender;

            PMat.SetActiveMaterial(mat);
            PMat.SetKeywordEnable(PMat.KW_MESH_NOISE, meshNoise != 0);
            PMat.SetFloat(PMat.MESH_NOISE, meshNoise);
            PMat.SetActiveMaterial(null);

            for (int i = 0; i < TileIndices.Count; ++i)
            {
                PIndex2D   index    = TileIndices[i];
                Vector3    pos      = transform.TransformPoint(new Vector3(index.X * TileSize.x, 0, index.Z * TileSize.y));
                Quaternion rotation = transform.rotation;
                Vector3    scale    = new Vector3(TileSize.x * transform.lossyScale.x, 1 * transform.lossyScale.y, TileSize.y * transform.lossyScale.z);

                Graphics.DrawMesh(
                    Mesh,
                    Matrix4x4.TRS(pos, rotation, scale),
                    mat,
                    gameObject.layer,
                    cam,
                    0,
                    MaterialProperties,
                    ShadowCastingMode.Off,
                    false,
                    null,
                    LightProbeUsage.BlendProbes,
                    null);
            }
        }
Example #2
0
        private void DrawExistingTiles()
        {
            for (int i = 0; i < water.TileIndices.Count; ++i)
            {
                PIndex2D index      = water.TileIndices[i];
                Vector3  rectCenter = water.transform.TransformPoint(new Vector3(
                                                                         (index.X + 0.5f) * water.TileSize.x,
                                                                         0,
                                                                         (index.Z + 0.5f) * water.TileSize.y));
                Vector3 rectSize = water.transform.TransformVector(new Vector3(
                                                                       water.TileSize.x,
                                                                       0,
                                                                       water.TileSize.y));

                Handles.color = new Color(1, 1, 1, 0.05f);
                Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                Handles.DrawWireCube(rectCenter, rectSize);

                Handles.color = new Color(1, 1, 1, 1);
                Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                Handles.DrawWireCube(rectCenter, rectSize);
            }
        }
Example #3
0
        private void HandleAddRemoveTiles()
        {
            Plane plane    = new Plane(Vector3.up, water.transform.position);
            Ray   r        = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            float distance = -1;

            if (plane.Raycast(r, out distance))
            {
                Vector3  hitWorldPos = r.origin + r.direction * distance;
                Vector3  hitLocalPos = water.transform.InverseTransformPoint(hitWorldPos);
                PIndex2D index       = new PIndex2D(
                    Mathf.FloorToInt(hitLocalPos.x / water.TileSize.x),
                    Mathf.FloorToInt(hitLocalPos.z / water.TileSize.y));

                Vector3 rectCenter = water.transform.TransformPoint(new Vector3(
                                                                        (index.X + 0.5f) * water.TileSize.x,
                                                                        hitLocalPos.y,
                                                                        (index.Z + 0.5f) * water.TileSize.y));
                Vector3 rectSize = water.transform.TransformVector(new Vector3(
                                                                       water.TileSize.x,
                                                                       0,
                                                                       water.TileSize.y));

                if (Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseUp)
                {
                    if (Event.current.button != 0)
                    {
                        return;
                    }
                    if (Event.current.control)
                    {
                        water.TileIndices.Remove(index);
                        water.ReCalculateBounds();
                    }
                    else if (Event.current.shift)
                    {
                        if (!water.TileIndices.Contains(index))
                        {
                            water.TileIndices.Add(index);
                            water.ReCalculateBounds();
                        }
                    }
                    PUtilities.MarkCurrentSceneDirty();
                    EditorUtility.SetDirty(water);
                }

                Handles.color = Handles.selectedColor;
                Handles.DrawWireCube(rectCenter, rectSize);

                string s = string.Format(
                    "{0}" +
                    "{1}" +
                    "{2}",
                    index.ToString(),
                    "\nShift+Click to pin, Ctrl+Click to unpin water planes.",
                    "\nClick End Editing Tiles when done.");

                GUIContent mouseMessage = new GUIContent(s);
                PEditorCommon.SceneViewMouseMessage(mouseMessage);
            }
        }
Example #4
0
        public void ReCalculateBounds()
        {
            if (MeshType == PWaterMeshType.Area || MeshType == PWaterMeshType.CustomMesh)
            {
                Bounds = Mesh.bounds;
            }
            else if (MeshType == PWaterMeshType.TileablePlane)
            {
                int minX = int.MaxValue;
                int minZ = int.MaxValue;
                int maxX = int.MinValue;
                int maxZ = int.MinValue;

                for (int i = 0; i < TileIndices.Count; ++i)
                {
                    PIndex2D index = TileIndices[i];
                    minX = Mathf.Min(minX, index.X);
                    minZ = Mathf.Min(minZ, index.Z);
                    maxX = Mathf.Max(maxX, index.X);
                    maxZ = Mathf.Max(maxZ, index.Z);
                }

                float width  = (maxX - minX + 1) * TileSize.x;
                float length = (maxZ - minZ + 1) * TileSize.y;
                float height = 0;

                float centerX = Mathf.Lerp(minX, maxX + 1, 0.5f) * TileSize.x;
                float centerZ = Mathf.Lerp(minZ, maxZ + 1, 0.5f) * TileSize.y;
                float centerY = 0;

                Bounds = new Bounds(
                    new Vector3(centerX, centerY, centerZ),
                    new Vector3(width, height, length));
            }
            else if (MeshType == PWaterMeshType.Spline)
            {
                List <PSplineSegment> segments = Spline.Segments;
                float minX = float.MaxValue;
                float minY = float.MaxValue;
                float minZ = float.MaxValue;
                float maxX = float.MinValue;
                float maxY = float.MinValue;
                float maxZ = float.MinValue;

                for (int i = 0; i < segments.Count; ++i)
                {
                    Bounds b = segments[i].Mesh.bounds;
                    minX = Mathf.Min(b.min.x, minX);
                    minY = Mathf.Min(b.min.y, minY);
                    minZ = Mathf.Min(b.min.z, minZ);

                    maxX = Mathf.Max(b.max.x, maxX);
                    maxY = Mathf.Max(b.max.y, maxY);
                    maxZ = Mathf.Max(b.max.z, maxZ);
                }

                bounds.SetMinMax(
                    new Vector3(minX, minY, minZ),
                    new Vector3(maxX, maxY, maxZ));
            }
        }
Example #5
0
        public bool CheckTilesContainPoint(Vector3 worldPoint)
        {
            PIndex2D index = WorldPointToTileIndex(worldPoint);

            return(TileIndices.Contains(index));
        }