void OnSceneGUI()
    {
        Event currentEvent = Event.current;

        if (riverScript.nodeObjects != null && riverScript.nodeObjects.Length != 0 && !riverScript.finalized)
        {
            int n = riverScript.nodeObjects.Length;
            for (int i = 0; i < n; i++)
            {
                RiverNodeObject node = riverScript.nodeObjects[i];
                node.position = Handles.PositionHandle(node.position, Quaternion.identity);
            }
        }

        if (riverScript.riverNodeMode == true)
        {
            if (currentEvent.isKey && currentEvent.character == 'r')
            {
                Vector3 riverNode = GetTerrainCollisionInEditor(currentEvent, KeyCode.R);

                TerrainCell riverNodeCell = new TerrainCell();
                riverNodeCell.position.x   = riverNode.x;
                riverNodeCell.position.y   = riverNode.z;
                riverNodeCell.heightAtCell = riverNode.y;

                riverScript.CreateRiverNode(riverNodeCell);
                riverScript.riverNodeMode = false;
            }
        }

        if (GUI.changed)
        {
            if (!riverScript.finalized)
            {
                EditorUtility.SetDirty(riverScript);
                riverScript.CreateMesh(riverScript.riverSmooth, false);
            }
        }
    }
Exemplo n.º 2
0
    void OnSceneGUI()
    {
        Event currentEvent = Event.current;

        if (riverScript.nodeObjects != null && riverScript.nodeObjects.Count != 0 && !riverScript.finalized)
        {
            int n = riverScript.nodeObjects.Count;
            for (int i = 0; i < n; i++)
            {
                RiverNodeObject node = riverScript.nodeObjects[i];
                node.position = Handles.PositionHandle(node.position, Quaternion.identity);
                Handles.Label(node.position + Vector3.up, "[" + i + "]");
            }
        }

        if (riverScript.curRiverNodeToPosite >= 0)
        {
            if (currentEvent.isKey && currentEvent.character == 'r')
            {
                /*
                 * if(riverScript.nodeObjects.Count > riverScript.curRiverNodeToPosite)
                 * {
                 *      RiverNodeObject curRiverNode = riverScript.nodeObjects[riverScript.curRiverNodeToPosite];
                 *      curRiverNode.position = GetTerrainCollisionInEditor(currentEvent, true);
                 *      curRiverNode.position.y += riverScript.defRiverDepth;
                 *      curRiverNode.width = riverScript.defRiverWidth;
                 * }
                 */
                riverScript.curRiverNodeToPosite = -1;
                EditorUtility.SetDirty(riverScript);
                riverScript.CreateMesh(riverScript.riverSmooth);
            }
        }
        else if (GUI.changed)
        {
            EditorUtility.SetDirty(riverScript);
            riverScript.CreateMesh(riverScript.riverSmooth);
        }
    }
Exemplo n.º 3
0
    public void GenRiverVoxels(AttachedRiverScript riverScript)
    {
        MeshCollider mc = riverScript.GetComponent <MeshCollider>();

        if (mc == null)
        {
            riverScript.CreateMesh(riverScript.riverSmooth);
            mc = riverScript.GetComponent <MeshCollider>();
        }
        if (mc == null || mc.sharedMesh == null)
        {
            Debug.LogError("Can not find mesh collider");
            return;
        }
        VFVoxelWater.InitSufaceChunkData();

        Bounds meshBound = mc.sharedMesh.bounds;

        #if UNITY_EDITOR
        EditorUtility.DisplayProgressBar("RiverVoxels...", "Starting gen...", 0);
        #endif
        Vector3    boundMin = meshBound.min;
        Vector3    boundMax = meshBound.max;
        IntVector4 cpos     = new IntVector4();

        if (!System.IO.Directory.Exists(outputDir))
        {
            System.IO.Directory.CreateDirectory(outputDir);
        }
        curOutputDir = outputDir + "/" + riverScript.name;
        if (!System.IO.Directory.Exists(curOutputDir))
        {
            System.IO.Directory.CreateDirectory(curOutputDir);
        }
        string filePrefix = curOutputDir + "/water";

#if false //test
        GenARiverChunk(ref boundMin, ref boundMax, mc, new IntVector4(310, 2, 221, 0), filePrefix);
#else
        //float prev = VoxelTerrainConstants._numVoxelsPrefix /(float)VoxelTerrainConstants._numVoxelsPerAxis;
        //float post = VoxelTerrainConstants._numVoxelsPostfix/(float)VoxelTerrainConstants._numVoxelsPerAxis;
        for (cpos.w = 0; cpos.w <= LODOctreeMan.MaxLod; cpos.w++)
        {
            int step       = 1 << cpos.w;
            int lodPrefix  = VoxelTerrainConstants._numVoxelsPrefix << cpos.w;
            int lodpostfix = VoxelTerrainConstants._numVoxelsPostfix << cpos.w;
            int sx         = (((int)(boundMin.x) - lodPrefix) >> (VoxelTerrainConstants._shift + cpos.w)) << cpos.w;
            int sy         = (((int)(boundMin.y) - lodPrefix) >> (VoxelTerrainConstants._shift + cpos.w)) << cpos.w;
            int sz         = (((int)(boundMin.z) - lodPrefix) >> (VoxelTerrainConstants._shift + cpos.w)) << cpos.w;
            int ex         = (((int)(boundMax.x) + lodpostfix) >> (VoxelTerrainConstants._shift + cpos.w)) << cpos.w;
            int ey         = (((int)(boundMax.y) + lodpostfix) >> (VoxelTerrainConstants._shift + cpos.w)) << cpos.w;
            int ez         = (((int)(boundMax.z) + lodpostfix) >> (VoxelTerrainConstants._shift + cpos.w)) << cpos.w;
            if (sy < 0)
            {
                sy = 0;
            }
            int   n            = (((ex - sx) >> cpos.w) + 1) * (((ey - sy) >> cpos.w) + 1) * (((ez - sz) >> cpos.w) + 1);
            float progressStep = 1.0f / n;
            float progress     = 0.0f;

            for (cpos.x = sx; cpos.x <= ex; cpos.x += step)
            {
                for (cpos.z = sz; cpos.z <= ez; cpos.z += step)
                {
                    for (cpos.y = sy; cpos.y <= ey; cpos.y += step)
                    {
                                        #if UNITY_EDITOR
                        EditorUtility.DisplayProgressBar("RiverVoxels..." + cpos.w, "Gen " + cpos + "...", progress);
                        progress += progressStep;
                                        #endif
                        GenARiverChunk(ref boundMin, ref boundMax, mc, new IntVector4(cpos), filePrefix);
                    }
                }
            }
        }
#endif
        #if UNITY_EDITOR
        EditorUtility.ClearProgressBar();
        #endif
    }