bpmw bpmw - 2 months ago 13x
C# Question

Translating Javascript to C# Issues

I've been attempting to convert this Javascript code into a C# (Unity3d) script. It is an implementation of Naive Surface Nets explained here if that helps.

My translated C# script does compile without errors/warnings but the result is a broken (but recognizable) mesh:
C# Script in Unity3D

I've also noticed that the vertices look reasonably correct:
enter image description here

(If you can't already tell, the input voxels are just simplex noise.)

I'd really like to get this working, but I am not well versed with Javascript.
Can someone who knows both languages well tell me what I've missed? Thank you.

EDIT: Here's the project.


Solved. I simply mistranslated line 87 of the Javascript code.


for(x[2]=0; x[2]<dims[2]-1; ++x[2], n+=dims[0], buf_no ^= 1, R[2]=-R[2]) {

My incorrect translation:

for (pos[2] = 0; pos[2] < depth - 1; pos[2]++, bufferNumber ^= 1, R[2] = -R[2] )

Corrected to:

for (pos[2] = 0; pos[2] < depth - 1; n += width, bufferNumber ^= 1, R[2] = -R[2] )

Basically a typo. Sorry about that.