1
myMesh = {}
myMesh[0].x = 30

Nope... doesn't work.

myMesh = Mesh.new{}
myMesh[0].x = 30

Nope... no go.

An array of meshes should be possible, but I don't know how. Can someone help? Thanks

Edit: Thanks for your responses. Pardon me for this stupid mistake. I just realized, "What nonsense are you doing J?" I really wanted an array of vertices of the mesh, so that I can use loops to manipulate them. Sorry about that... although it didn't hurt to learn how to get an array of meshes.

So I figured it out, because I was sure I did this before, when I used gml.

ptx = {}; pty = {}; ptz = {} 
ptx[1] = myMesh.x; pty[1] = myMesh.y; ptz[1] = myMesh.z; 

Thanks for the help though. I also learned that lua doesn't use index 0

Edit: Wait. That doesn't work either does it?

Well for now this gives no error, so I'll see if it does what I want.

pMesh = {}
 for m=1, 6 do
    pMesh[m] = Mesh.new()
 end

pMesh[1].x = 0; pMesh[1].y = 0; pMesh[1].z = 0

Thanks guys. If you have any other suggestions, I'm all ears.

4

3 回答 3

1
myMesh = {}
myMesh[0].x = 30

nil将导致索引值错误。

myMesh = {}创建一个空的 Lua 表。

不允许做myMesh[0].x,因为没有myMesh[0]. 首先,您必须在索引 0 处插入一个表格元素。

myMesh = {}
myMesh[0] = Mesh.new(true)
myMesh[0].x = 30

myMesh 是一组网格的愚蠢名称,因为它表明它只是一个网格。同样在 Lua 中,我们通常从索引 1 开始,这将使使用 Lua 的标准表格工具变得更容易一些。我不确定是否

mesh = Mesh.new()
mesh.x = 30

其实没问题。为什么网格会有 x 坐标?这在手册中的 Mesh 属性中没有列出。

通常你会创建一个具有多个点的网格如果你想要一个包含多个网格的数组,你只需将这些网格放入一个表中,除非有特定的用户数据类型。

于 2018-04-10T14:39:22.483 回答
0

您需要初始化为表以及列和行:

myMesh = {}
myMesh[0] = {}
myMesh[0].x=30

或者

myMesh = { [0]={} }
myMesh[0].x=30
于 2018-04-10T14:23:48.883 回答
0

尝试这个:

myMesh = {}
myMesh[0]= Mesh.new{}
myMesh[0].x = 30
于 2018-04-10T13:32:00.323 回答