Exemple #1
0
    static void CreateMeshGrid(Vector3Int _grid, BeamInfo binfo, ref MeshStruct _meshStruct)
    {
        vIndex = tIndex = 0;
        float xMin = -binfo.length * 0.5f;
        float xMax = binfo.length * 0.5f;
        float yMin = -binfo.height * 0.5f;
        float yMax = binfo.height * 0.5f;
        float zMin = -binfo.wigth * 0.5f;
        float zMax = binfo.wigth * 0.5f;

        CreateMeshPlane(_grid.x, _grid.z,//上
                        (i, j) => { return(Mathf.Clamp(i * binfo.gridSize + xMin, xMin, xMax)); },
                        (i, j) => { return(yMax); },
                        (i, j) => { return(Mathf.Clamp(-j * binfo.gridSize + zMax, zMin, zMax)); },
                        /*new Rect(0, 0.7083f, 0.9278f, 0.2917f)*/
                        (x, y, z) => { return(0 + ((x + xMax) / binfo.length) * 0.9278f); },
                        (x, y, z) => { return(0.7083f + ((z + zMax) / binfo.wigth) * 0.2917f); },
                        Vector3.up, ref _meshStruct, true);
        CreateMeshPlane(_grid.x, _grid.z,//下
                        (i, j) => { return(Mathf.Clamp(i * binfo.gridSize + xMin, xMin, xMax)); },
                        (i, j) => { return(yMin); },
                        (i, j) => { return(Mathf.Clamp(-j * binfo.gridSize + zMax, zMin, zMax)); },
                        //new Rect(0, 0, 0.9278f, 0.2917f),
                        (x, y, z) => { return(0 + ((x + xMax) / binfo.length) * 0.9278f); },
                        (x, y, z) => { return(0 + ((z + zMax) / binfo.wigth) * 0.2917f); },
                        Vector3.down, ref _meshStruct);
        CreateMeshPlane(_grid.z, _grid.y,//左
                        (i, j) => { return(xMin); },
                        (i, j) => { return(Mathf.Clamp(j * binfo.gridSize + yMin, yMin, yMax)); },
                        (i, j) => { return(Mathf.Clamp(-i * binfo.gridSize + zMax, zMin, zMax)); },
                        //new Rect(0.9278f, 0.2917f, 0.0722f, 0.4167f),
                        (x, y, z) => { return(0.9278f + ((z + zMax) / binfo.wigth) * 0.0722f); },
                        (x, y, z) => { return(0.2917f + ((y + yMax) / binfo.height) * 0.4167f); },
                        Vector3.left, ref _meshStruct);
        CreateMeshPlane(_grid.z, _grid.y,//右
                        (i, j) => { return(xMax); },
                        (i, j) => { return(Mathf.Clamp(j * binfo.gridSize + yMin, yMin, yMax)); },
                        (i, j) => { return(Mathf.Clamp(-i * binfo.gridSize + zMax, zMin, zMax)); },
                        //new Rect(0.9278f, 0.2917f, 0.0722f, 0.4167f),
                        (x, y, z) => { return(0.9278f + ((z + zMax) / binfo.wigth) * 0.0722f); },
                        (x, y, z) => { return(0.2917f + ((y + yMax) / binfo.height) * 0.4167f); },
                        Vector3.right, ref _meshStruct, true);
        CreateMeshPlane(_grid.x, _grid.y,//前
                        (i, j) => { return(Mathf.Clamp(i * binfo.gridSize + xMin, xMin, xMax)); },
                        (i, j) => { return(Mathf.Clamp(j * binfo.gridSize + yMin, yMin, yMax)); },
                        (i, j) => { return(zMin); },
                        //new Rect(0f, 0.2917f, 0.9278f, 0.4167f),
                        (x, y, z) => { return(0 + ((x + xMax) / binfo.length) * 0.9278f); },
                        (x, y, z) => { return(0.2917f + ((y + yMax) / binfo.height) * 0.4167f); },
                        Vector3.back, ref _meshStruct);
        CreateMeshPlane(_grid.x, _grid.y,//后
                        (i, j) => { return(Mathf.Clamp(i * binfo.gridSize + xMin, xMin, xMax)); },
                        (i, j) => { return(Mathf.Clamp(j * binfo.gridSize + yMin, yMin, yMax)); },
                        (i, j) => { return(zMax); },
                        //new Rect(0f, 0.2917f, 0.9278f, 0.4167f),
                        (x, y, z) => { return(0 + ((x + xMax) / binfo.length) * 0.9278f); },
                        (x, y, z) => { return(0.2917f + ((y + yMax) / binfo.height) * 0.4167f); },
                        Vector3.forward, ref _meshStruct, true);
    }
Exemple #2
0
    /// <summary>
    /// 按要求创建网格体信息
    /// </summary>
    /// <param name="binfo"></param>
    /// <param name="size"></param>
    /// <returns></returns>
    public static MeshStruct CreateBeamMesh(BeamInfo binfo)
    {
        Vector3Int _grid = new Vector3Int();

        // 根据【单元格大小】计算【格子个数】
        _grid.x = Mathf.CeilToInt((float)binfo.length / binfo.gridSize) + 1;
        _grid.y = Mathf.CeilToInt((float)binfo.height / binfo.gridSize) + 1;
        _grid.z = Mathf.CeilToInt((float)binfo.wigth / binfo.gridSize) + 1;
        MeshStruct _meshStruct = AllocateMeshArrays(_grid);

        CreateMeshGrid(_grid, binfo, ref _meshStruct);
        return(_meshStruct);
    }
    private void RenderExplosion( ExplosionInfo exInfo, float opacity, bool isSimulatingOrReplaying )
    {
      CNExplosion exNode = eManager_.GetExplosionNode(exInfo.idEntity_);
      if (exNode == null)
      {
        return;
      }

      Vector3 center = exInfo.center_;

      List<BeamInfo> arrBeamInfo = exInfo.listBeam_;
      int nBeams = arrBeamInfo.Count;

      Color red = Color.red;
      red.a = opacity;

      Color yellow = Color.yellow;
      yellow.a = opacity;

      Color cyan = Color.cyan;
      cyan.a = opacity;

      int step = (int)Mathf.Log(nBeams);

      step = exNode.RenderStepSize;
      Quaternion rotation = Quaternion.identity;

      if ( exNode.Explosion_Transform != null &&  !isSimulatingOrReplaying )
      {
        Transform tr = exNode.Explosion_Transform;
        center   = tr.position;
        rotation = tr.rotation;
      }

      for ( int i = 0; i < nBeams; i += step )
      {
        BeamInfo beamInfo = arrBeamInfo[i];

        Vector3 beam_u         = rotation * beamInfo.beam_u_;
        Vector3 segmentLengths = beamInfo.segmentLenths_;

        if (segmentLengths.x < float.Epsilon ) continue;
        Handles.color = red;
        Vector3 pos_A = center;
        Vector3 pos_B = pos_A + (beam_u * segmentLengths.x);
        Handles.DrawLine(pos_A, pos_B);

          
        if (segmentLengths.y < float.Epsilon ) continue;
        Handles.color = yellow;
        pos_A = pos_B;
        pos_B += beam_u * segmentLengths.y;
        Handles.DrawLine(pos_A, pos_B);
          

        if (segmentLengths.z < float.Epsilon) continue;
        Handles.color = cyan;
        pos_A = pos_B;
        pos_B += beam_u * segmentLengths.z;
        Handles.DrawLine(pos_A, pos_B);
      }
    }