• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

cocos creator创建的动态网格

武飞扬头像
cc_bbs
帮助1

 如果初次尝试cocos的动态网格创建,一定会遇到非常多的问题。

所以刚开始使用,最好用一个简单的东西来实现,逐步的复杂化。

下面代码展示了一个最基础的三角面的创建。

代码:

  1.  
    private initDyMesh() {
  2.  
    const pos = new Float32Array(9);
  3.  
    pos[0] = 0;
  4.  
    pos[1] = 0;
  5.  
    pos[2] = -2;
  6.  
    pos[3] = 0;
  7.  
    pos[4] = 2;
  8.  
    pos[5] = -2;
  9.  
    pos[6] = 3;
  10.  
    pos[7] = 0;
  11.  
    pos[8] = -2;
  12.  
    const ind = new Uint16Array(3);
  13.  
    ind[0] = 0;
  14.  
    ind[1] = 2;
  15.  
    ind[2] = 1;
  16.  
    utils.MeshUtils.createDynamicMesh(0, { positions: pos, indices16: ind }, this.dyMesh, {
  17.  
    maxSubMeshes: 1,
  18.  
    maxSubMeshIndices: 3,
  19.  
    maxSubMeshVertices: 3,
  20.  
    });
  21.  
    this.dyMesh.updateSubMesh(0, { positions: pos, indices16: ind });
  22.  
    this.dyMeshRenderer.mesh = this.dyMesh;
  23.  
    this.dyMeshRenderer.onGeometryChanged();
  24.  
    }
学新通

这里创建了一个三角面,3个点。加3个点的索引。

更详细的内容可以查阅cocos官方文档和案例
程序化创建网格 · Cocos Creator

cocos动态网格案例

效果如下:

学新通

 需要注意的是:

1. 索引需要是顺时针,不然就看不见,只能漫游到背面查看。

2. 必须要传索引,不然不会绘制。

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgghecb
系列文章
更多 icon
同类精品
更多 icon
继续加载