コード例 #1
0
ファイル: VoxImporter.cs プロジェクト: MrTP/TPSVO
        private static void SplitOctree(Vector3[,,] voxels, List <VoxelData> voxelData, int parentIndex)
        {
            VoxelData parent = voxelData[parentIndex];

            if (parent.size <= 1)
            {
                parent.isLeaf = true;
                return;
            }
            float size = parent.size / 2f;
            float x1   = parent.x;
            float y1   = parent.y;
            float z1   = parent.z;
            float x2   = parent.x + size;
            float y2   = parent.y + size;
            float z2   = parent.z + size;

            parent.c0 = AddVoxelData(voxels, voxelData, x1, y1, z1, size);
            parent.c1 = AddVoxelData(voxels, voxelData, x1 + size, y1, z1, size);
            parent.c2 = AddVoxelData(voxels, voxelData, x1 + size, y1 + size, z1, size);
            parent.c3 = AddVoxelData(voxels, voxelData, x1, y1 + size, z1, size);

            parent.c4 = AddVoxelData(voxels, voxelData, x1, y1, z1 + size, size);
            parent.c5 = AddVoxelData(voxels, voxelData, x1 + size, y1, z1 + size, size);
            parent.c6 = AddVoxelData(voxels, voxelData, x1 + size, y1 + size, z1 + size, size);
            parent.c7 = AddVoxelData(voxels, voxelData, x1, y1 + size, z1 + size, size);
            voxelData[parentIndex] = parent;
        }
コード例 #2
0
        public void GenerateTilesByGrid()
        {
            tilePositions = gridTiles.g.gridCellsPositions;
            dynamicTiles  = new DynamicTile[gridTiles.g.xDimension, gridTiles.g.yDimension, gridTiles.g.zDimension];

            Debug.Log(gridTiles.g.xDimension);
            Debug.Log(gridTiles.g.yDimension);
            Debug.Log(gridTiles.g.zDimension);
            Debug.Log("Cell Size: " + gridTiles.g.CellSize);

            for (int x = 0; x < gridTiles.g.xDimension; x++)
            {
                for (int y = 0; y < gridTiles.g.yDimension; y++)
                {
                    for (int z = 0; z < gridTiles.g.zDimension; z++)
                    {
                        Quaternion q = new Quaternion(1, 0, 0, 1);
                        GameObject h = Instantiate(tile.gameObject, tilePositions[x, y, z], q);
                        h.transform.position   = new Vector3(h.transform.position.x, TileFallHeight, h.transform.position.z);
                        h.transform.localScale = new Vector3(TileScale, TileScale, TileScale);
                        dynamicTiles[x, y, z]  = h.GetComponent <DynamicTile>();
                        Debug.Log("Writing grid:", dynamicTiles[x, y, z]);
                    }
                }
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            try
            {
                // Analyze arguments
                if (args.Length != 1)
                {
                    throw new Exception("Usage: BRDFSlices \"Path to MERL BRDF\"");
                }

                FileInfo SourceBRDF = new FileInfo(args[0]);
                if (!SourceBRDF.Exists)
                {
                    throw new Exception("Source BRDF file \"" + SourceBRDF.FullName + "\" does not exist!");
                }

                // Load the BRDF
                Vector3[,,]     BRDF = DisplayForm.LoadBRDF(SourceBRDF);


                DisplayForm F = new DisplayForm(BRDF);
                Application.Run(F);
            }
            catch (Exception _e)
            {
                MessageBox.Show("An error occurred!\r\n\r\n" + _e.Message + "\r\n\r\n" + _e.StackTrace, "BRDF Fitting", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
コード例 #4
0
    // Use this for initialization
    void Start()
    {
        hp = 100;
        ap = 100;

        cmdButtons = GameObject.FindGameObjectWithTag("CommandUI");

        camAngles = new Vector3[3, 2, 2];//x,y,z positions

        //Land angles
        camAngles[0, 0, 0] = new Vector3(-28f, 3f, -18f);
        camAngles[1, 0, 0] = new Vector3(-16f, 3f, -18f);
        camAngles[2, 0, 0] = new Vector3(-3f, 3f, -18f);

        camAngles[0, 1, 0] = new Vector3(-28f, 9f, -18f);
        camAngles[1, 1, 0] = new Vector3(-16f, 9f, -18f);
        camAngles[2, 1, 0] = new Vector3(-3f, 9f, -18f);

        //Sea angles
        camAngles[0, 0, 1] = new Vector3(-28f, 3f, -2f);
        camAngles[1, 0, 1] = new Vector3(-16f, 3f, -2f);
        camAngles[2, 0, 1] = new Vector3(-3f, 3f, -2f);

        camAngles[0, 1, 1] = new Vector3(-28f, 9f, -2f);
        camAngles[1, 1, 1] = new Vector3(-16f, 9f, -2f);
        camAngles[2, 1, 1] = new Vector3(-3f, 9f, -2f);
    }
コード例 #5
0
    // public void doubleArraySize()
    // {
    //     size = 300;
    //     Vector3[,,] newWindArray = new Vector3[size * 2, size * 2, size * 2];
    //     int halfSize = size / 2;
    //     for (int i = 0; i < size; i++)
    //     {
    //         for (int j = 0; j < size; j++)
    //         {
    //             for (int k = 0; k < size; k += 8)
    //             {
    //                 newWindArray[i + halfSize, j + halfSize, k + 0] = windArray[i, j, k + 0];
    //                 newWindArray[i + halfSize, j + halfSize, k + 1] = windArray[i, j, k + 0];
    //                 newWindArray[i + halfSize, j + halfSize, k + 2] = windArray[i, j, k + 0];
    //                 newWindArray[i + halfSize, j + halfSize, k + 3] = windArray[i, j, k + 0];
    //                 newWindArray[i + halfSize, j + halfSize, k + 4] = windArray[i, j, k + 0];
    //                 newWindArray[i + halfSize, j + halfSize, k + 5] = windArray[i, j, k + 0];
    //                 newWindArray[i + halfSize, j + halfSize, k + 6] = windArray[i, j, k + 0];
    //                 newWindArray[i + halfSize, j + halfSize, k + 7] = windArray[i, j, k + 0];
    //             }
    //         }
    //     }


    //     for (int i = 0; i < halfSize; i++)
    //     {
    //         for (int j = 0; j < halfSize; j++)
    //         {
    //             for (int k = 0; k < halfSize; k += 8)
    //             {
    //                 newWindArray[i, j, k + 0] = Vector3.zero;
    //                 newWindArray[i, j, k + 1] = Vector3.zero;
    //                 newWindArray[i, j, k + 2] = Vector3.zero;
    //                 newWindArray[i, j, k + 3] = Vector3.zero;
    //                 newWindArray[i, j, k + 4] = Vector3.zero;
    //                 newWindArray[i, j, k + 5] = Vector3.zero;
    //                 newWindArray[i, j, k + 6] = Vector3.zero;
    //                 newWindArray[i, j, k + 7] = Vector3.zero;
    //             }
    //         }
    //     }

    //     size = size * 2;
    //     for (int i = halfSize; i < size; i++)
    //     {
    //         for (int j = halfSize; j < size; j++)
    //         {
    //             for (int k = halfSize; k < size; k += 8)
    //             {
    //                 newWindArray[i, j, k + 0] = Vector3.zero;
    //                 newWindArray[i, j, k + 1] = Vector3.zero;
    //                 newWindArray[i, j, k + 2] = Vector3.zero;
    //                 newWindArray[i, j, k + 3] = Vector3.zero;
    //                 newWindArray[i, j, k + 4] = Vector3.zero;
    //                 newWindArray[i, j, k + 5] = Vector3.zero;
    //                 newWindArray[i, j, k + 6] = Vector3.zero;
    //                 newWindArray[i, j, k + 7] = Vector3.zero;
    //             }
    //         }
    //     }
    // }

    public void addObject(WindData data)
    {
        windObjectsData.Add(data.index, data);
        Vector3[ , , ] windArray = null;

        switch (data.geometryData.geometryType)
        {
        case GeometryData.GeometryType.CUBE:
            windArray = getCubeWindArray((CubeGeometryData)data.geometryData, data.intensity, data.interference);
            break;

        case GeometryData.GeometryType.SPHERE:
            windArray = getSphereWindArray((SphereGeometryData)data.geometryData, data.intensity, data.interference);
            break;

        case GeometryData.GeometryType.CYLINDER:
            windArray = getCylinderWindArray((CylinderGeometryData)data.geometryData, data.intensity, data.interference);
            break;

        default:
            break;
        }
        windArrayData.Add(data.index, windArray);

        addUpdateArray(data.index);
    }
コード例 #6
0
        public Vector3[,,] BuildGrid()
        {
            _worldSize = new GridWorldSize();

            _elementPositions = new Vector3[_gridRows, _gridColumns, _gridDepth];

            Vector3 startPosition = GetPosition();

            _worldSize.SetWorldSize(startPosition);

            for (int depth = 0; depth < _gridDepth; depth++)
            {
                float z = startPosition.z - depth * (_elementSize.z + _elementPadding.z);
                _worldSize.SetDepth(z);

                for (int row = 0; row < _gridRows; row++)
                {
                    float y = startPosition.y - row * (_elementSize.y + _elementPadding.y);
                    _worldSize.SetHeight(y);

                    for (int column = 0; column < _gridColumns; column++)
                    {
                        float x = startPosition.x - column * (_elementSize.x + _elementPadding.x);
                        _worldSize.SetWidth(x);
                        _elementPositions[row, column, depth] = new Vector3(x, y, z);
                    }
                }
            }


            OnGridCreated.Invoke(_worldSize);
            return(_elementPositions);
        }
コード例 #7
0
    // 初始化调用
    void Start()
    {
        gamedata       = GameObject.Find("Data_Source").GetComponent <GameData> ();
        operationError = PlayerPrefs.GetFloat("operationError", 0.3f);
//		targetNumber = PlayerPrefs.GetInt (PlayerPrefs.GetString ("Target") + "Num", 1);
        targetPoint = gamedata.targetTangram;
        tangram6    = GameObject.Find("Tangram_cf_06(Clone)");
        // 初始化所有七巧板的所有特征点为屏幕左下角区域,0没用
        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                vt [i, j] = gamedata.tangramPosition [0];
            }
        }

        // 初始化每个七巧板的检测距离(旋转中心到其他七巧板的顶点)
        distance [0] = 0;
        // Mathf.Sqrt (0.7 * 0.7 + 1.3 * 1.3) + 操作误差;
        distance [1] = 2.1f + operationError;
        distance [2] = 1.4f + operationError;
        distance [3] = 1.4f + operationError;
        distance [4] = 3.0f + operationError;
        distance [5] = 3.0f + operationError;
        distance [6] = 2.1f + operationError;
        distance [7] = 1.4f + operationError;
    }
コード例 #8
0
ファイル: Chunk.cs プロジェクト: elenaamanita/Ocean-Waves
    public void CalculateNormals()
    {
        //float startTime = Time.realtimeSinceStartup;

        //This calculates the normal of each voxel. If you have a 3d array of data
        //the normal is the derivitive of the x, y and z axis.
        //Normally is needed to flip the normal (*-1) but it is not needed in this case.

        int w = m_voxels.GetLength(0);
        int h = m_voxels.GetLength(1);
        int l = m_voxels.GetLength(2);

        if(m_normals == null) m_normals = new Vector3[w,h,l];

        for(int x = 2; x < w-2; x++)
        {
            for(int y = 2; y < h-2; y++)
            {
                for(int z = 2; z < l-2; z++)
                {
                    float dx = m_voxels[x+1,y,z] - m_voxels[x-1,y,z];
                    float dy = m_voxels[x,y+1,z] - m_voxels[x,y-1,z];
                    float dz = m_voxels[x,y,z+1] - m_voxels[x,y,z-1];

                    m_normals[x,y,z] = Vector3.Normalize(new Vector3(dx,dy,dz));
                }
            }
        }

        //Debug.Log("Calculate normals time = " + (Time.realtimeSinceStartup-startTime).ToString() );
    }
コード例 #9
0
    private void addUpdateArray(int index)
    {
        GeometryData geometryData = windObjectsData[index].geometryData;
        Vector3      position     = geometryData.position;

        Vector3[,,] objectArray = windArrayData[index];
        switch (geometryData.geometryType)
        {
        case GeometryData.GeometryType.CUBE: {
            CubeGeometryData cubeGeometryData = (CubeGeometryData)geometryData;
            int sizeX  = (int)(cubeGeometryData.size.x / 0.1f);
            int sizeY  = (int)(cubeGeometryData.size.y / 0.1f);
            int sizeZ  = (int)(cubeGeometryData.size.z / 0.1f);
            int beginX = (int)((position.x + 2f) / 0.1f) - sizeX / 2;
            int beginY = (int)((position.y + 2f) / 0.1f) - sizeY / 2;
            int beginZ = (int)((position.z + 2f) / 0.1f) - sizeZ / 2;
            for (int i = 0; i < sizeX; i++)
            {
                for (int j = 0; j < sizeZ; j++)
                {
                    for (int k = 0; k < sizeY; k++)
                    {
                        windArray[i + beginX, j + beginY, k + beginZ] = objectArray[i, j, k];
                    }
                }
            }
            break;
        }
        }
    }
コード例 #10
0
    void Start()
    {
        voxels   = new float [division, division, division];
        gradient = new Vector3[division, division, division];

        MarchingCubes.SetWindingOrder(2, 1, 0);
    }
コード例 #11
0
    // void OnValidate()
    // {
    //     for (int i = 0; i < transform.childCount; i++)
    //     {
    //         Destroy(transform.GetChild(i).gameObject);
    //     }
    //     Start();
    // }

    // Use this for initialization
    void Start()
    {
        var blockScale = Vector3.one * BLOCK_SCALE;

        rubikCube = new GameObject[ONE_SIDE * 2 + 1, ONE_SIDE * 2 + 1, ONE_SIDE * 2 + 1];
        initPos   = new Vector3[ONE_SIDE * 2 + 1, ONE_SIDE * 2 + 1, ONE_SIDE * 2 + 1];
        for (int i = -ONE_SIDE; i <= ONE_SIDE; i++)
        {
            for (int j = -ONE_SIDE; j <= ONE_SIDE; j++)
            {
                for (int k = -ONE_SIDE; k <= ONE_SIDE; k++)
                {
                    var cube = rubikCube[i + ONE_SIDE, j + ONE_SIDE, k + ONE_SIDE] = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    cube.transform.position   = initPos[i + ONE_SIDE, j + ONE_SIDE, k + ONE_SIDE] = new Vector3(i, j, k) * ONE_SIDE_DISTANCE;
                    cube.transform.localScale = blockScale;
                    cube.GetComponent <MeshRenderer> ().material = cubeShader;
                    cube.transform.parent = transform;
                    cube.name            += i + " " + j + " " + k;
                }
            }
        }

        _rot.Count = 0;

        StartCoroutine(Roop(blockScale));
    }
コード例 #12
0
    static public Mesh CreateMesh(float[,,] voxels, Vector3[,,] gradient)
    {
        List <Vector3> verts = new List <Vector3>();
        List <Vector3> norms = new List <Vector3>();
        List <int>     index = new List <int>();

        float[]   cube  = new float[8];
        Vector3[] cube2 = new Vector3[8];

        for (int x = 0; x < voxels.GetLength(0) - 1; x++)
        {
            for (int y = 0; y < voxels.GetLength(1) - 1; y++)
            {
                for (int z = 0; z < voxels.GetLength(2) - 1; z++)
                {
                    //Get the values in the 8 neighbours which make up a cube
                    FillCube(x, y, z, voxels, gradient, cube, cube2);
                    //Perform algorithm
                    Mode_Func(new Vector3(x, y, z), cube, cube2, verts, norms, index);
                }
            }
        }

        Mesh mesh = new Mesh();

        mesh.vertices  = verts.ToArray();
        mesh.normals   = norms.ToArray();
        mesh.triangles = index.ToArray();

        return(mesh);
    }
コード例 #13
0
ファイル: GridMapper.cs プロジェクト: KapG/RubikMapper
    private void GenerateSpawnTile(GameObject[,,] levelLayout, Vector3[,,] layoutPositions)
    {
        GameObject[] randomSpawnTiles = pathValidator.GetRandomSortedArray(spawnTiles);
        foreach (GameObject spawnTile in randomSpawnTiles)
        {
            GridLevelBlock spawn = spawnTile.GetComponentInChildren <GridLevelBlock>();
            if (!spawn.backTopLeft && !spawn.backTop && !spawn.backTopRight &&
                !spawn.backMidLeft && !spawn.backMid && !spawn.backMidRight &&
                !spawn.backBottomLeft && !spawn.backBottom && !spawn.backBottomRight)
            {
                continue;
            }
            else
            {
                levelLayout[0, 0, 0]     = spawnTile;
                layoutPositions[0, 0, 0] = new Vector3(blockSize * 0, blockSize * 0, blockSize * 0);
                break;
            }
        }

        if (levelLayout[0, 0, 0] == null)
        {
            Debug.LogError("Spawn point must have an exit on 'Back' face with rotation '0'");
        }
    }
コード例 #14
0
 void Awake()
 {
     _flowfieldDirection = new Vector3[_gridSize.x, _gridSize.y, _gridSize.z];
     _fastNoise          = new FastNoise();
     _particles          = new List <FlowFieldParticle>();
     _particleMeshRender = new List <MeshRenderer>();
     for (int i = 0; i < _amountOfParticles; i++)
     {
         int attempt = 0;
         while (attempt < 100)
         {
             Vector3 randomPos = new Vector3(Random.Range(transform.position.x, transform.position.x + _gridSize.x * _cellSize),
                                             Random.Range(transform.position.y, transform.position.y + _gridSize.y * _cellSize),
                                             Random.Range(transform.position.z, transform.position.z + _gridSize.z * _cellSize));
             bool isValid = _particleSpawnValidation(randomPos);
             if (isValid)
             {
                 GameObject particleInstance = Instantiate(_particlePrefab, transform);
                 particleInstance.transform.position   = randomPos;
                 particleInstance.transform.localScale = new Vector3(_particleScale, _particleScale, _particleScale);
                 _particles.Add(particleInstance.GetComponent <FlowFieldParticle>());
                 _particleMeshRender.Add(particleInstance.GetComponent <MeshRenderer>());
                 break;
             }
             if (!isValid)
             {
                 attempt++;
             }
         }
         //  Debug.Log(_particles.Count);
     }
 }
コード例 #15
0
    void Start()
    {
        voxels = new float [division, division, division];
        gradient = new Vector3[division, division, division];

        MarchingCubes.SetWindingOrder (2, 1, 0);
    }
コード例 #16
0
ファイル: VectorPerlin.cs プロジェクト: MarkZuber/wkndray
        private float PerlinInterpolate(Vector3[,,] c, float u, float v, float w)
        {
            float uu    = u * u * (3.0f - (2.0f * u));
            float vv    = v * v * (3.0f - (2.0f * v));
            float ww    = w * w * (3.0f - (2.0f * w));
            float accum = 0.0f;

            for (int i = 0; i < 2; i++)
            {
                float dubi = Convert.ToSingle(i);
                for (int j = 0; j < 2; j++)
                {
                    float dubj = Convert.ToSingle(j);
                    for (int k = 0; k < 2; k++)
                    {
                        float   dubk      = Convert.ToSingle(k);
                        Vector3 weightVec = new Vector3(u - dubi, v - dubj, w - dubk);
                        accum += ((dubi * uu) + ((1.0f - dubi) * (1.0f - uu))) *
                                 ((dubj * vv) + ((1.0f - dubj) * (1.0f - vv))) *
                                 ((dubk * ww) + ((1.0f - dubk) * (1.0f - ww))) *
                                 Vector3.Dot(c[i, j, k], weightVec);
                    }
                }
            }

            return(accum);
        }
コード例 #17
0
ファイル: MazeGeneralLogic.cs プロジェクト: Glycer/Bridge
    public static void GenerateSquares(Transform transform, bool useColumns, LevelPrefabs prefabs, GameObject squarePrefab,
                                       Vector3[,,] coordinates, MazeSquare[,,] squares)
    {
        for (int z = 0; z < squares.GetLength(2); z++)
        {
            GameObject layer = NewSection("Layer", z, transform);

            for (int i = 0; i < squares.GetLength(0); i++)
            {
                GameObject row = NewSection("Row", i, layer.transform);

                for (int j = 0; j < squares.GetLength(1); j++)
                {
                    if (squares[i, j, z] == null)
                    {
                        continue;
                    }

                    MazeSurveyLogic.Survey(i, j, z, squares);

                    #region Setup Square in Hierarchy
                    squares[i, j, z].layout = BuildLayout(useColumns, prefabs, squarePrefab, squares[i, j, z].adjacents);
                    GameObject sq = squares[i, j, z].layout;

                    sq.transform.parent        = transform;
                    sq.transform.localPosition = coordinates[i, j, z];
                    sq.transform.parent        = row.transform;

                    sq.name = "Sq" + (j + 1);
                    #endregion
                }
            }
        }
    }
コード例 #18
0
ファイル: DisplayForm.cs プロジェクト: vr3d/GodComplex
        public static void      LookupBRDFTrilinear(Vector3[,,] _BRDF, double _ThetaHalf, double _ThetaDiff, double _PhiDiff, ref Vector3 _Result)
        {
            // (note that PhiHalf is ignored, since isotropic BRDFs are assumed)
            Vector3 r;
            int     PhiDiffIndex0   = PhiDiff_index(_PhiDiff, out r.z);
            int     ThetaDiffIndex0 = ThetaDiff_index(_ThetaDiff, out r.y);
            int     ThetaHalfIndex0 = ThetaHalf_index(_ThetaHalf, out r.x);

            int PhiDiffIndex1   = Math.Min(BRDF_SAMPLING_RES_PHI_D / 2 - 1, PhiDiffIndex0 + 1);
            int ThetaDiffIndex1 = Math.Min(BRDF_SAMPLING_RES_THETA_D - 1, ThetaDiffIndex0 + 1);
            int ThetaHalfIndex1 = Math.Min(BRDF_SAMPLING_RES_THETA_H - 1, ThetaHalfIndex0 + 1);

            TempTrilerp[0, 0, 0] = _BRDF[ThetaHalfIndex0, ThetaDiffIndex0, PhiDiffIndex0];
            TempTrilerp[0, 0, 1] = _BRDF[ThetaHalfIndex0, ThetaDiffIndex0, PhiDiffIndex1];
            TempTrilerp[0, 1, 1] = _BRDF[ThetaHalfIndex0, ThetaDiffIndex1, PhiDiffIndex1];
            TempTrilerp[0, 1, 0] = _BRDF[ThetaHalfIndex0, ThetaDiffIndex1, PhiDiffIndex0];
            TempTrilerp[1, 0, 0] = _BRDF[ThetaHalfIndex1, ThetaDiffIndex0, PhiDiffIndex0];
            TempTrilerp[1, 0, 1] = _BRDF[ThetaHalfIndex1, ThetaDiffIndex0, PhiDiffIndex1];
            TempTrilerp[1, 1, 1] = _BRDF[ThetaHalfIndex1, ThetaDiffIndex1, PhiDiffIndex1];
            TempTrilerp[1, 1, 0] = _BRDF[ThetaHalfIndex1, ThetaDiffIndex1, PhiDiffIndex0];

            TempBilerp[0, 0] = (1.0 - r.z) * TempTrilerp[0, 0, 0] + r.z * TempTrilerp[0, 0, 1];
            TempBilerp[0, 1] = (1.0 - r.z) * TempTrilerp[0, 1, 0] + r.z * TempTrilerp[0, 1, 1];
            TempBilerp[1, 1] = (1.0 - r.z) * TempTrilerp[1, 1, 0] + r.z * TempTrilerp[1, 1, 1];
            TempBilerp[1, 0] = (1.0 - r.z) * TempTrilerp[1, 0, 0] + r.z * TempTrilerp[1, 0, 1];

            TempLerp[0] = (1.0 - r.y) * TempBilerp[0, 0] + r.y * TempBilerp[0, 1];
            TempLerp[1] = (1.0 - r.y) * TempBilerp[1, 0] + r.y * TempBilerp[1, 1];

            _Result = (1.0 - r.x) * TempLerp[0] + r.x * TempLerp[1];
        }
コード例 #19
0
    // Start is called before the first frame update
    void Start()
    {
        _flowFieldDirections = new Vector3[_gridSize.x, _gridSize.y, _gridSize.z];
        _fastNoise           = new FastNoise();

        _particles = new List <flowFieldParticle>();

        for (int i = 0; i < amountParticles; i++)
        {
            Vector3 randomPos = new Vector3(UnityEngine.Random.Range(this.transform.position.x, this.transform.position.x + _gridSize.x * _cellSize),
                                            UnityEngine.Random.Range(this.transform.position.y, this.transform.position.y + _gridSize.y * _cellSize),
                                            UnityEngine.Random.Range(this.transform.position.z, this.transform.position.z + _gridSize.z * _cellSize));

            bool isValid = _particleSpawnValidation(randomPos);

            if (isValid)
            {
                GameObject particleInstance = Instantiate(particlePrefab);
                particleInstance.transform.position   = randomPos;
                particleInstance.transform.parent     = this.transform;
                particleInstance.transform.localScale = new Vector3(_particleScale, _particleScale, _particleScale);

                _particles.Add(particleInstance.GetComponent <flowFieldParticle>());
            }
        }
    }
コード例 #20
0
    void vectorLinearSolve(Vector3[,,] x, Vector3[,,] x0, float a, float c, bool bounce)
    {
        int n, i, j, k;

        for (n = 0; n < linearSolverTimes; n++)
        {
            for (i = 1; i <= gridSizeX; i++)
            {
                for (j = 1; j <= gridSizeY; j++)
                {
                    for (k = 1; k <= gridSizeZ; k++)
                    {
                        x[i, j, k] = (x0[i, j, k] + a * (
                                          x[i - 1, j, k] +
                                          x[i + 1, j, k] +
                                          x[i, j - 1, k] +
                                          x[i, j + 1, k] +
                                          x[i, j, k - 1] +
                                          x[i, j, k + 1]
                                          )) / c;
                    }
                }
            }
            vectorSetBoundary(x, bounce);
        }
    }
コード例 #21
0
    public void CalculateNormals()
    {
        //float startTime = Time.realtimeSinceStartup;

        //This calculates the normal of each voxel. If you have a 3d array of data
        //the normal is the derivitive of the x, y and z axis.
        //Normally is needed to flip the normal (*-1) but it is not needed in this case.

        int w = m_voxels.GetLength(0);
        int h = m_voxels.GetLength(1);
        int l = m_voxels.GetLength(2);

        if (m_normals == null)
        {
            m_normals = new Vector3[w, h, l];
        }

        for (int x = 2; x < w - 2; x++)
        {
            for (int y = 2; y < h - 2; y++)
            {
                for (int z = 2; z < l - 2; z++)
                {
                    float dx = m_voxels[x + 1, y, z] - m_voxels[x - 1, y, z];
                    float dy = m_voxels[x, y + 1, z] - m_voxels[x, y - 1, z];
                    float dz = m_voxels[x, y, z + 1] - m_voxels[x, y, z - 1];

                    m_normals[x, y, z] = Vector3.Normalize(new Vector3(dx, dy, dz));
                }
            }
        }

        //Debug.Log("Calculate normals time = " + (Time.realtimeSinceStartup-startTime).ToString() );
    }
コード例 #22
0
ファイル: FlightGrid.cs プロジェクト: pasha7746/vr-proto
    public void BuildGrid(Vector3 res, bool buildObsMap)
    {
        // lock (workweLock)
        {
            scaledRes   = new Vector3();
            scaledRes.x = bounds.x / res.x;
            scaledRes.z = bounds.z / res.z;
            scaledRes.y = bounds.y / res.y;

            triDPos     = new Vector3[(int)res.x, (int)res.y, (int)res.z];
            obstacleMap = new bool[(int)res.x, (int)res.y, (int)res.z];

            for (int i = 0; i < res.y; i++)
            {
                for (int j = 0; j < res.z; j++)
                {
                    for (int k = 0; k < res.x; k++)
                    {
                        triDPos[k, i, j] = start + new Vector3(scaledRes.x * k, scaledRes.y * i, scaledRes.z * j);
                    }
                }
            }
            //if (buildObsMap)
            //{
            //    BuildObstacleMap();
            //}
        }

        // StartCoroutine(CheckGrid());
    }
コード例 #23
0
    private void Start()
    {
        flowFieldDirection = new Vector3[gridSize.x, gridSize.y, gridSize.z];
        fastNoise          = new FastNoise();
        particles          = new List <FlowFieldParticle>();

        for (int i = 0; i < particleAmount; i++)
        {
            int attempt = 0;

            while (attempt < 100)
            {
                Vector3 randomPosition = new Vector3(
                    Random.Range(transform.position.x, transform.position.x + gridSize.x * cellSize),
                    Random.Range(transform.position.y, transform.position.y + gridSize.y * cellSize),
                    Random.Range(transform.position.z, transform.position.z + gridSize.z * cellSize));

                bool isValid = particleSpawnValidation(randomPosition);

                if (isValid)
                {
                    GameObject particleInstance = (GameObject)Instantiate(particlePrefab);
                    particleInstance.transform.position   = randomPosition;
                    particleInstance.transform.parent     = transform;
                    particleInstance.transform.localScale = new Vector3(particleScale, particleScale, particleScale);
                    particles.Add(particleInstance.GetComponent <FlowFieldParticle>());
                    break;
                }
                if (!isValid)
                {
                    attempt++;
                }
            }
        }
    }
コード例 #24
0
        void ComputeVectorField()
        {
            velocityField = new Vector3[size, size, size];
            colorField    = new Color[size, size, size];
            for (int x = 0; x < size; ++x)
            {
                for (int y = 0; y < size; ++y)
                {
                    for (int z = 0; z < size; ++z)
                    {
                        // compute node position within a unit cube
                        Vector3 normalizedPosition = new Vector3(x, y, z) / (float)(size - 1);
                        Vector3 velocity           = Vector3.zero;
                        Color   color = Color.black;
                        float   mSum  = .0f;

                        for (int i = samplers.Length - 1; i > -1; --i)
                        {
                            Vector3 v;
                            Color   c;
                            samplers[i].Sample(normalizedPosition, out v, out c);
                            velocity += v;
                            float m = v.magnitude; // color weight
                            mSum  += m;
                            color += c * m;
                        }

                        velocityField[x, y, z] = velocity;
                        color              /= Mathf.Max(.0000001f, mSum); // prevent div by 0
                        color.a             = Mathf.Clamp01(color.a);
                        colorField[x, y, z] = color;
                    }
                }
            }
        }
コード例 #25
0
        void Start()
        {
            directions = new Vector3[gridSize.x, gridSize.y, gridSize.z];
            fastNoise  = new FastNoise();
            particles  = new List <FieldParticle>(amountOfParticles);
            for (var i = 0; i < amountOfParticles; i++)
            {
                var attempt = 0;
                while (attempt < 100)
                {
                    var randomPos = new Vector3(
                        Random.Range(transform.position.x, transform.position.x + gridSize.x * cellSize),
                        Random.Range(transform.position.y, transform.position.y + gridSize.y * cellSize),
                        Random.Range(transform.position.z, transform.position.z + gridSize.z * cellSize)
                        );

                    if (ValidatePosition(randomPos))
                    {
                        var particle = Instantiate(particlePrefab);
                        particle.transform.position   = randomPos;
                        particle.transform.parent     = transform;
                        particle.transform.localScale = new Vector3(particleScale, particleScale, particleScale);
                        var ffParticle = particle.GetComponent <FieldParticle>();
                        particles.Add(ffParticle);
                        ffParticle.OnSpawn();
                        break;
                    }
                    else
                    {
                        attempt++;
                    }
                }
            }
            onParticlesGenerated?.Invoke();
        }
コード例 #26
0
    void GenerateCoordinates(Inputs inputs)
    {
        x_Space = (float)(width) / (float)inputs.Width;
        y_Space = (float)(height) / (float)inputs.Height;
        z_Space = (float)(depth) / (float)inputs.Depth;

        line = GetComponent <LineRenderer>();
        line.positionCount = 8;
        arrayMap           = new Vector3[inputs.Width, inputs.Height, inputs.Depth];

        for (int depth = 0; depth < inputs.Depth; depth++)
        {
            for (int row = 0; row < inputs.Width; row++)
            {
                for (int col = 0; col < inputs.Height; col++)
                {
                    Vector3 dot = new Vector3(x_Start + (x_Space * row), y_Start + (-y_Space * col), z_Start + (z_Space * depth));
                    arrayMap[row, col, depth] = dot;

                    GameObject instantiatedObj = Instantiate(prefab, dot, Quaternion.identity);
                    instantiatedList.Add(instantiatedObj);
                }
            }
        }
    }
コード例 #27
0
    public Vector3[,,] CreateGridOnHelix(Helix h, int w = 9)
    {
        width = w;

        Vector3[] points = h.points;
        triSize = h.sideLength;

        int length = h.sideCount;               // along the line of the helix
        int height = h.rotations;               // vertically up the helix
        int center = width / 2;                 // the z coord that falls on the line

        coords = new Vector3[length, height, width];
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < length; x++)
            {
                for (int z = 0; z < width; z++)
                {
                    coords[x, y, z] = new Vector3(x, y, z);
                }
            }
        }

        positions = new Vector3[length, height, width];
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < length; x++)
            {
                // get the angle from this point on the line to the center of the helix
                Vector3 targetDir = h.center - Vector3.Normalize(new Vector3(points[x].x, 0, points[x].z));
                float   angle     = Vector3.Angle(targetDir, Vector3.back);

                // compensate for the fact that Vector3.Angle only returns acute angles
                if (x > length / 2)
                {
                    angle  = Mathf.Abs(angle - 180);
                    angle += 180;
                }
                angle *= Mathf.Deg2Rad;

                for (int z = 0; z < width; z++)
                {
                    // get the distance from the point, perpendicular to the line of the helix
                    float dis = (float)triSize * (z - center);
                    if (x % 2 == 0)
                    {
                        dis += (float)triSize * 0.5f;
                    }

                    // calculate the position
                    float xPos = points[x].x + dis * Mathf.Sin(angle);
                    float yPos = points[(y * length) + x].y;
                    float zPos = points[x].z + dis * Mathf.Cos(angle);
                    positions[x, y, z] = new Vector3(xPos, yPos, zPos);
                }
            }
        }

        return(positions);
    }
コード例 #28
0
        float Interp(Vector3[,,] c, float u, float v, float w)
        {
            float uu = u * u * (3.0f - 2.0f * u);
            float vv = v * v * (3.0f - 2.0f * v);
            float ww = w * w * (3.0f - 2.0f * w);

            float accum = 0;

            for (int i = 0; i < 2; ++i)
            {
                for (int j = 0; j < 2; ++j)
                {
                    for (int k = 0; k < 2; ++k)
                    {
                        Vector3 weightV = new Vector3(u - (float)i, v - (float)j, w - (float)k);
                        accum += ((float)i * uu + (1 - (float)i) * (1 - uu)) *
                                 ((float)j * vv + (1 - (float)j) * (1 - vv)) *
                                 ((float)k * ww + (1 - (float)k) * (1 - ww)) *
                                 Vector3.Dot(c[i, j, k], weightV);
                    }
                }
            }

            return(accum);
        }
コード例 #29
0
        public void CalculateNormals()
        {
            //float startTime = Time.realtimeSinceStartup;

            //This calculates the normal of each voxel. If you have a 3d array of data
            //the normal is the derivitive of the x, y and z axis.
            //Normally you need to flip the normal (*-1) but it is not needed in this case.
            //If you dont call this function the normals that Unity generates for a mesh are used.

            int w = GridData.GetLength(0);
            int h = GridData.GetLength(1);
            int l = GridData.GetLength(2);

            GridNormals = GridNormals ?? new Vector3[w, h, l];

            for (int x = 2; x < w - 2; x++)
            {
                for (int y = 2; y < h - 2; y++)
                {
                    for (int z = 2; z < l - 2; z++)
                    {
                        float dx = GridData[x + 1, y, z] - GridData[x - 1, y, z];
                        float dy = GridData[x, y + 1, z] - GridData[x, y - 1, z];
                        float dz = GridData[x, y, z + 1] - GridData[x, y, z - 1];

                        GridNormals[x, y, z] = Vector3.Normalize(new Vector3(dx, dy, dz));
                    }
                }
            }
        }
コード例 #30
0
 public void ResetGrid()
 {
     _currentX = 0;
     _currentY = 0;
     _currentZ = 0;
     _grid     = Get3DScatterGrid();
 }
コード例 #31
0
    private void CreateCells()
    {
        int        n             = config.size;
        float      cellsDistance = Config.cellsDistance;
        GameObject cell;

        positions = new Vector3[n, n, n];
        cells     = new Cell[n, n, n];


        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                for (int k = 0; k < n; k++)
                {
                    cell = Instantiate(_emptyCellPrefab);

                    cell.GetComponent <Cell>().cellData.i = i;
                    cell.GetComponent <Cell>().cellData.j = j;
                    cell.GetComponent <Cell>().cellData.k = k;

                    positions[i, j, k]      = new Vector3(i * cellsDistance, j * cellsDistance, k * cellsDistance);
                    cell.transform.position = positions[i, j, k];
                    cell.transform.SetParent(cellsParent);
                    cells[i, j, k] = cell.GetComponent <Cell>();
                }
            }
        }

        EventManager.NewCellsCreated();
    }
コード例 #32
0
    // Grid cube to center and verts in buffer for GPU
    private void instantiateGridCubes()
    {
        GridVerts = new Vector3[XCubes + 1, YCubes + 1, ZCubes + 1];
        Cubes     = new GridCube[XCubes * YCubes * ZCubes];

        for (int x = 0; x < XCubes; x++)
        {
            for (int y = 0; y < YCubes; y++)
            {
                for (int z = 0; z < ZCubes; z++)
                {
                    Vector3 centerPoint = cubeMap[x, y, z];
                    Cubes[x + XCubes * (y + YCubes * z)].CenterPos = centerPoint;

                    Cubes[x + XCubes * (y + YCubes * z)].V0 = centerPoint + vertMap[0];
                    Cubes[x + XCubes * (y + YCubes * z)].V1 = centerPoint + vertMap[1];
                    Cubes[x + XCubes * (y + YCubes * z)].V2 = centerPoint + vertMap[2];
                    Cubes[x + XCubes * (y + YCubes * z)].V3 = centerPoint + vertMap[3];
                    Cubes[x + XCubes * (y + YCubes * z)].V4 = centerPoint + vertMap[4];
                    Cubes[x + XCubes * (y + YCubes * z)].V5 = centerPoint + vertMap[5];
                    Cubes[x + XCubes * (y + YCubes * z)].V6 = centerPoint + vertMap[6];
                    Cubes[x + XCubes * (y + YCubes * z)].V7 = centerPoint + vertMap[7];

                    GridVerts[x, y, z]             = centerPoint + vertMap[0];
                    GridVerts[x + 1, y, z]         = centerPoint + vertMap[1];
                    GridVerts[x + 1, y + 1, z]     = centerPoint + vertMap[2];
                    GridVerts[x, y + 1, z]         = centerPoint + vertMap[3];
                    GridVerts[x, y, z + 1]         = centerPoint + vertMap[4];
                    GridVerts[x + 1, y, z + 1]     = centerPoint + vertMap[5];
                    GridVerts[x + 1, y + 1, z + 1] = centerPoint + vertMap[6];
                    GridVerts[x, y + 1, z + 1]     = centerPoint + vertMap[7];
                }
            }
        }
    }
コード例 #33
0
 void DebugVertexMatrix()
 {
     vertexMatrix = theGrid.BuildVertexMatrix(3.0f, 3.0f, 3.0f);
     theGrid.DrawVertices(vertexMatrix);
     if(printLogs){
         Gizmos.color = Color.red;
         Gizmos.DrawSphere((theGrid.ReadVertexMatrix(index[0], index[1], index[2], vertexMatrix)), 0.3f);
     }
 }
コード例 #34
0
ファイル: ChunkOld.cs プロジェクト: MarvTekko/AISG
    public static void setChunkSize ( int _sizeXZ, int _sizeY ) {

        chunkSizeXZ = _sizeXZ;
        chunkSizeY = _sizeY;

        allVertices = new Vector3[ chunkSizeXZ + 1, chunkSizeY + 1, chunkSizeXZ + 1 ];

        for ( int x = 0; x <= chunkSizeXZ; x++ ) {
            for ( int y = 0; y <= chunkSizeY; y++ ) {
                for ( int z = 0; z <= chunkSizeXZ; z++ ) {

                    allVertices[ x, y, z ] = new Vector3 ( x, y, z );
                }
            }
        }
    }
コード例 #35
0
        public LoopableNoise3D(int seed, float period, Point3 periodLoop)
        {
            this.seed = seed;
            this.period = period;
            this.periodLoop = periodLoop;

            Random rdm = new Random(seed);
            gradientVectors = new Vector3[periodLoop.X, periodLoop.Y, periodLoop.Z];

            for(int i=0;i<gradientVectors.GetLength(0);i++)
                for(int j=0;j<gradientVectors.GetLength(1);j++)
                    for (int k = 0; k < gradientVectors.GetLength(2); k++)
                    {
                        gradientVectors[i, j, k] = randVect(rdm);
                    }
        }
コード例 #36
0
 public LugusRandomGeneratorGrid( float width, float height, float depth, int rows, int cols, int stack, float spread , int seed)
 {
     _dr = new DataRange(0,cols*rows*stack);
     SetSeed(seed);
     _xDir = width / cols;
     _yDir = height / rows;
     _zDir = depth / stack;
     _width = width;
     _height = height;
     _depth = depth;
     _rows = rows;
     _cols = cols;
     _stack = stack;
     _spread = spread;
     _grid = CreateScatterGrid();
 }
コード例 #37
0
ファイル: GenChunkMesh.cs プロジェクト: MarvTekko/AISG
    public GenChunkMesh ( Chunk _myChunk ) {

        myChunk = _myChunk;
        newVertices.Clear ();
        newTriangles.Clear ();

        allVertices = new Vector3[ myChunk.getChunkSizeXZ() + 1, myChunk.getChunkSizeY () + 1, myChunk.getChunkSizeXZ () + 1 ];

        for ( int x = 0; x <= myChunk.getChunkSizeXZ (); x++ ) {
            for ( int y = 0; y <= myChunk.getChunkSizeY (); y++ ) {
                for ( int z = 0; z <= myChunk.getChunkSizeXZ (); z++ ) {

                    allVertices[ x, y, z ] = new Vector3 ( x, y, z );
                }
            }
        }
    }
コード例 #38
0
ファイル: DisplayForm.cs プロジェクト: Patapom/GodComplex
        public DisplayForm( Vector3[,,] _BRDF )
        {
            InitializeComponent();

            //			SaveAllSlices();

            BuildScaleTable();
            //			LoadScaleTable();

            m_BRDF = _BRDF;
            m_Slice = new Bitmap( 90, 90, PixelFormat.Format32bppArgb );

            m_Pen = new Pen( Color.Black, 1.0f );
            m_Pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;

            integerTrackbarControlPhiD_ValueChanged( integerTrackbarControlPhiD, 0 );
        }
コード例 #39
0
ファイル: LevelInfo.cs プロジェクト: kiniry-teaching/UCD
        /**
         * Initialise the normal map. This must be done after the height map has
         * been initialised.
         */
        private void initNormalMap()
        {
            /* each square region is made up of two triangles. */
            normals = new Vector3[width, height, 2];

            for (int x = 0; x < width; x++)
                for (int y = 0; y < height; y++)
                {
                    Vector3 p0 = getPositionAt(x, y);
                    Vector3 p1 = getPositionAt(x + 1, y);
                    Vector3 p2 = getPositionAt(x, y + 1);
                    Vector3 p3 = getPositionAt(x + 1, y + 1);

                    Vector3 v0 = p2 - p0;
                    Vector3 v1 = p3 - p2;
                    Vector3 v2 = p3 - p1;
                    Vector3 v3 = p1 - p0;

                    normals[x, y, 0] = Vector3.Cross(v1, v0);
                    normals[x, y, 1] = Vector3.Cross(v3, v2);
                }
        }
コード例 #40
0
 public void ResetGrid()
 {
     _currentX=0;
     _currentY=0;
     _currentZ=0;
     _grid = CreateScatterGrid();
 }
コード例 #41
0
        public static Vector3[] CalculateNormalsRemove(byte[,,] m_voxels ,int size,Vector3 [] verts)
        {
            Vector3[] normals = new Vector3[size];
            //float startTime = Time.realtimeSinceStartup;
            int w = m_voxels.GetLength(0);
            int h= m_voxels.GetLength(1);
            int l = m_voxels.GetLength(2);

            //This calculates the normal of each voxel. If you have a 3d array of data
            //the normal is the derivitive of the x, y and z axis.
            //Normally you need to flip the normal (*-1) but it is not needed in this case.
            //If you dont call this function the normals that Unity generates for a mesh are used.

            m_normals2 = new Vector3[w,h,l];

            for(int x = 2; x < w-2; x++)
            {
            for(int y = 2; y < h-2; y++)
            {
            for(int z = 2; z < l-2; z++)
            {
            float dx = m_voxels[x+1,y,z] - m_voxels[x-1,y,z];
            float dy = m_voxels[x,y+1,z] - m_voxels[x,y-1,z];
            float dz = m_voxels[x,y,z+1] - m_voxels[x,y,z-1];

            m_normals2[x,y,z] = Vector3.Normalize(new Vector3(dx,dy,dz));
                }
            }
            }
            for(int i = 0;i < size ;i++){
            normals[i] = MeshFactory.TriLinearInterp(verts[i]);
            }
            //Debug.Log("Calculate normals time = " + (Time.realtimeSinceStartup-startTime).ToString() );

            return normals;
        }
コード例 #42
0
 public SimpleFlowField(int x, int y, int z, Vector3 center)
 {
     _center = center;
     _field = new Vector3[x, y, z];
 }
コード例 #43
0
    public void GenerateTexture()
    {
        GenerateNoiseGenerator();
        gradient = new Vector3[Res,Res,Res];

        for (int z = 0; z < Res; ++z) {
            for (int y = 0; y < Res; ++y) {
                for (int x = 0; x < Res; ++x) {
                    gradient[x, y, z] = GetValue(x, y, z);
                }
            }
            EditorUtility.DisplayProgressBar("Generating noise", "Generating noise...",
                                             (z * Res * Res) / (float) (Res * Res * Res));
        }

        EditorUtility.ClearProgressBar();

        target.GenerateTexture(gradient, NeedsNewTexture());

        if (!EditorUtility.IsPersistent(target.forceTexture)) {
            AssetDatabase.CreateAsset(target.forceTexture, AssetDatabase.GenerateUniqueAssetPath("Assets/TC Noise Force.asset"));
            Selection.activeObject = target.forceTexture;
        }
    }
コード例 #44
0
ファイル: MeshRD.cs プロジェクト: jumpeast/UnityRD3DMesh
    void setupParameters()
    {
        isoValue = new float[resX + 2, resY + 2, resZ + 2];
        n = new Vector3[resX + 2, resY + 2, resZ + 2];
        for(int x = 0; x < resX+2; x++){
            for(int y = 0; y < resY+2; y++){
                for(int z = 0; z < resZ+2; z++){
                    isoValue[x,y,z] = 0.0f;
                    n[x,y,z] = new Vector3(0, 0, 0);
                }
            }
        }

        u = new float[resX, resY, resZ];
        v = new float[resX, resY, resZ];
        dudt = new float[resX, resY, resZ];
        dvdt = new float[resX, resY, resZ];
        for(int x = 0; x < resX; x++){
            for(int y = 0; y < resY; y++){
                for(int z = 0; z < resZ; z++){
                    u[x,y,z] = Random.value;
                    v[x,y,z] = Random.value;
                    dudt[x,y,z] = Random.value;
                    dvdt[x,y,z] = Random.value;
                }
            }
        }

        tempVert = new Vector3[12];
        tempNorm = new Vector3[12];

        vertices = new List<Vector3>();
        normals = new List<Vector3> ();
        triangles = new List<int>();
    }
コード例 #45
0
ファイル: Water.cs プロジェクト: WolfgangSt/axiom
		public WaterMesh( String meshName, float planeSize, int cmplx )
		{ // najak R-F
			// Assign Fields to the Initializer values
			this.meshName = meshName;
			this.size = planeSize;
			this.cmplx = cmplx;  // Number of Rows/Columns in the Water Grid representation
			cmplxAdj = (float)System.Math.Pow( ( cmplx / 64f ), 1.4f ) * 2;
			numFaces = 2 * (int)System.Math.Pow( cmplx, 2 );  // Each square is split into 2 triangles.
			numVertices = (int)System.Math.Pow( ( cmplx + 1 ), 2 ); // Vertex grid is (Complexity+1) squared

			// Allocate and initialize space for calculated Normals
			vNorms = new Vector3[ cmplx + 1, cmplx + 1 ]; // vertex Normals for each grid point
			fNorms = new Vector3[ cmplx, cmplx, 2 ]; // face Normals for each triangle

			// Create mesh and submesh to represent the Water
			mesh = (Mesh)MeshManager.Instance.CreateManual( meshName, ResourceGroupManager.DefaultResourceGroupName, null );
			subMesh = mesh.CreateSubMesh();
			subMesh.useSharedVertices = false;

			// Construct metadata to describe the buffers associated with the water submesh
			subMesh.vertexData = new VertexData();
			subMesh.vertexData.vertexStart = 0;
			subMesh.vertexData.vertexCount = numVertices;

			// Define local variables to point to the VertexData Properties
			VertexDeclaration vdecl = subMesh.vertexData.vertexDeclaration;  // najak: seems like metadata
			VertexBufferBinding vbind = subMesh.vertexData.vertexBufferBinding; // najak: pointer to actual buffer

			//najak: Set metadata to describe the three vertex buffers that will be accessed.
			vdecl.AddElement( 0, 0, VertexElementType.Float3, VertexElementSemantic.Position );
			vdecl.AddElement( 1, 0, VertexElementType.Float3, VertexElementSemantic.Normal );
			vdecl.AddElement( 2, 0, VertexElementType.Float2, VertexElementSemantic.TexCoords );

			// Prepare buffer for positions - todo: first attempt, slow
			// Create the Position Vertex Buffer and Bind it index 0 - Write Only
			posVBuf = HwBufMgr.CreateVertexBuffer( vdecl.Clone(0), numVertices, BufferUsage.DynamicWriteOnly );
			vbind.SetBinding( 0, posVBuf );

			// Prepare buffer for normals - write only
			// Create the Normals Buffer and Bind it to index 1 - Write only
			normVBuf = HwBufMgr.CreateVertexBuffer( vdecl.Clone(1), numVertices, BufferUsage.DynamicWriteOnly );
			vbind.SetBinding( 1, normVBuf );

			// Prepare Texture Coordinates buffer (static, written only once)
			// Creates a 2D buffer of 2D coordinates: (Complexity X Complexity), pairs.
			//    Each pair indicates the normalized coordinates of the texture to map to.
			//    (0,1.00), (0.02, 1.00), (0.04, 1.00), ... (1.00,1.00)
			//    (0,0.98), (0.02, 0.98), (0.04, 1.00), ... (1.00,0.98)
			//    ...
			//    (0,0.00), (0.02, 0.00), (0.04, 0.00), ... (1.00,0.00)
			// This construct is simple and is used to calculate the Texture map.
			// Todo: Write directly to the buffer, when Axiom supports this in safe manner
			float[ , , ] tcBufDat = new float[ cmplx + 1, cmplx + 1, 2 ];
			for ( int i = 0; i <= cmplx; i++ )
			{
				// 2D column iterator for texture map
				for ( int j = 0; j <= cmplx; j++ )
				{
					// 2D row iterator for texture map
					// Define the normalized(0..1) X/Y-coordinates for this element of the 2D grid
					tcBufDat[ i, j, 0 ] = (float)i / cmplx;
					tcBufDat[ i, j, 1 ] = 1.0f - ( (float)j / ( cmplx ) );
				}
			}

			// Now Create the actual hardware buffer to contain the Texture Coordinate 2d map.
			//   and Bind it to buffer index 2
			tcVBuf = HwBufMgr.CreateVertexBuffer( vdecl.Clone(2), numVertices, BufferUsage.StaticWriteOnly );
			tcVBuf.WriteData( 0, tcVBuf.Size, tcBufDat, true );
			vbind.SetBinding( 2, tcVBuf );

			// Create a Graphics Buffer on non-shared vertex indices (3 points for each triangle).
			//  Since the water grid consist of [Complexity x Complexity] squares, each square is
			//  split into 2 right triangles 45-90-45.  That is how the water mesh is constructed.
			//  Therefore the number of faces = 2 * Complexity * Complexity
			ushort[ , , ] idxBuf = new ushort[ cmplx, cmplx, 6 ];
			for ( int i = 0; i < cmplx; i++ )
			{ // iterate the rows
				for ( int j = 0; j < cmplx; j++ )
				{ // iterate the columns
					// Define 4 corners of each grid
					ushort p0 = (ushort)( i * ( cmplx + 1 ) + j ); // top left point on square
					ushort p1 = (ushort)( i * ( cmplx + 1 ) + j + 1 ); // top right
					ushort p2 = (ushort)( ( i + 1 ) * ( cmplx + 1 ) + j ); // bottom left
					ushort p3 = (ushort)( ( i + 1 ) * ( cmplx + 1 ) + j + 1 ); // bottom right

					// Split Square Grid element into 2 adjacent triangles.
					idxBuf[ i, j, 0 ] = p2;
					idxBuf[ i, j, 1 ] = p1;
					idxBuf[ i, j, 2 ] = p0; // top-left triangle
					idxBuf[ i, j, 3 ] = p2;
					idxBuf[ i, j, 4 ] = p3;
					idxBuf[ i, j, 5 ] = p1; // bottom-right triangle
				}
			}
			// Copy Index Buffer to the Hardware Index Buffer
			HardwareIndexBuffer hdwrIdxBuf = HwBufMgr.CreateIndexBuffer( IndexType.Size16, 3 * numFaces, BufferUsage.StaticWriteOnly, true );
			hdwrIdxBuf.WriteData( 0, numFaces * 3 * 2, idxBuf, true );

			// Set index buffer for this submesh
			subMesh.indexData.indexBuffer = hdwrIdxBuf;
			subMesh.indexData.indexStart = 0;
			subMesh.indexData.indexCount = 3 * numFaces;

			//Prepare Vertex Position Buffers (Note: make 3, since each frame is function of previous two)
			vBufs = new Vector3[ 3 ][ , ];
			for ( int b = 0; b < 3; b++ )
			{
				vBufs[ b ] = new Vector3[ cmplx + 1, cmplx + 1 ];
				for ( int y = 0; y <= cmplx; y++ )
				{
					for ( int x = 0; x <= cmplx; x++ )
					{
						vBufs[ b ][ y, x ].x = (float)( x ) / (float)( cmplx ) * (float)size;
						vBufs[ b ][ y, x ].y = 0;
						vBufs[ b ][ y, x ].z = (float)( y ) / (float)( cmplx ) * (float)size;
					}
				}
			}

			curBufNum = 0;
			vBuf = vBufs[ curBufNum ];
			posVBuf.WriteData( 0, posVBuf.Size, vBufs[ 0 ], true );

			AxisAlignedBox meshBounds = new AxisAlignedBox( new Vector3( 0, 0, 0 ), new Vector3( size, 0, size ) );
			mesh.BoundingBox = meshBounds;  //	mesh->_setBounds(meshBounds); // najak: can't find _setBounds()

			mesh.Load();
			mesh.Touch();

		} // end WaterMesh Constructor
コード例 #46
0
ファイル: SceneFilesConfig.cs プロジェクト: Wangdz/AllScene
 public SceneFilesConfig(Vector3 ARange)
 {
     files = new Vector3[ARange.x, ARange.y, ARange.z] ;
     startPos = new Vector3(0, 0, 0);
 }
コード例 #47
0
ファイル: NormalMap.cs プロジェクト: kiniry-teaching/UCD
        private void initialise(HeightMap heightMap)
        {
            width = heightMap.getMapWidth();
            height = heightMap.getMapHeight();
            normals = new Vector3[width, height, 2];

            for (int x = 0; x < width; x++)
                for (int y = 0; y < height; y++)
                {
                    Vector3 p0 = heightMap.getPositionAt(x, y);
                    Vector3 p1 = heightMap.getPositionAt(x + 1, y);
                    Vector3 p2 = heightMap.getPositionAt(x, y + 1);
                    Vector3 p3 = heightMap.getPositionAt(x + 1, y + 1);

                    Vector3 v0 = p2 - p0;
                    Vector3 v1 = p3 - p2;
                    Vector3 v2 = p3 - p1;
                    Vector3 v3 = p1 - p0;

                    normals[x, y, 0] = Vector3.Cross(v1, v0);
                    normals[x, y, 1] = Vector3.Cross(v3, v2);
                }
        }