Nov
12
2012

Marching Tetrahedrons

Tried to convert this  marching tetrahedrons (by Mikola Lysenko) to Unity Javascript.. but its not working yet (^ that should be a sphere..)

Source (bugged, see the original source above and try to fix this?..Oo )

** See comments section for fixed version

//#pragma strict
import System.Collections.Generic;

var res = new Array(3);
private var  grid:float[] = new float[8];
private     var cube_vertices = [
[0,0,0]
, [1,0,0]
, [1,1,0]
, [0,1,0]
, [0,0,1]
, [1,0,1]
, [1,1,1]
, [0,1,1] ];

private var  x:int[] = new int[3];
private var vertices:List. = new List.();
private var faces:List. = new List.();

function Awake ()
{
x[0]=0;
x[1]=0;
x[2]=0;
}

function Start ()
{
var verts:Vector3[] = MarchingTetrahedra(makeVolume(),res);
var triangles : int[] = faces.ToArray();

for (var n=0;n 1e-6) {
t = g0 / t;
}
for(var i=0; i<3; ++i) { v[i] += p0[i] + t * (p1[i] - p0[i]); } vertices.Add(new Vector3(v[0],v[1],v[2])); return vertices.Count - 1; } function makeVolume() { var dims = [[-1.0, 1.0, 0.25], [-1.0, 1.0, 0.25], [-1.0, 1.0, 0.25]]; for(var i1=0; i1<3; ++i1) { res[i1] = 2 + Mathf.Ceil((dims[i1][1] - dims[i1][0]) / dims[i1][2]); } var volume = new Array(res[0] * res[1] * res[2]); var n:int = 0; var zz:float=dims[2][0]-dims[2][2]; for(var k=0; k


About the Author:

.fi

11 Comments + Add Comment

  • Bugged source added.. place it to gameobject with MeshFilter & MeshRenderer.

  • Fantastic Demonstration WebGl Thing there! the “naive surface nets” are AWESOME also.

    here is a link to some great 3d shapes “Gyroids” which i didnt understand
    http://k3dsurf.s4.bizhat.com/k3dsurf-ftopic119-15.html

    awesome website as always!

  • hello,

    I just copied this code into new scene, put it on a GameObject with mesh renderer, everything apparently runs all right but I can’t see any mesh at all. The scene is blank, the GameObject doesn’t present any mesh or texture. it’s strange!?

  • hey it’s okay, I had put mesh filter and no mesh renderer! Thanks!

  • Hello!
    I have made some progress- instead of calculating a sphere, I separately calculated XY and Z as a plane.
    http://i50.tinypic.com/2z4l73m.jpg
    [IMG]http://i50.tinypic.com/2z4l73m.jpg[/IMG]

    The X-formulas seem to have calculated okay
    The Y and Z seem to be bugged

  • instead of xx+yy+zz-1 in the last line of code

    I put x-1
    y-1
    z-1

    • Thanks!

      (didnt notice the download arrow button at first..its there at bottom right 🙂

    • Hi there,
      Iam a little bit late for this amazing party, just found your port of marching tetra. But I saw that you also have a screenshot of surface nets in unity, can you share it?
      Thanks a lot 🙂

    • Yes, can you please share your surface nets implementation? It shouldn’t be too hard to write, though.. so if you’re unwilling to share, maybe I’ll write it and share it.

  • There’s a JS implemenation of surface nets perhaps here: https://0fps.net/2012/07/12/smooth-voxel-terrain-part-2/ …. … https://github.com/mikolalysenko/mikolalysenko.github.com/blob/master/Isosurface/js/surfacenets.js github addy…
    To voxelize an ISO, i know a bunch of methods… depends if you want to solid fill with cubes or put cubes on the iso border spaces. * SurfaceNets in JavaScript
    *
    * Written by Mikola Lysenko (C) 2012 if you run it in Unity please share your conversion!

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch Instagram

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.