This post has been de-listed (Author was flagged for spam)
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
1
whats the simplest marching cubes example with a sparse voxel octree?
Post Body
i made a sparse voxel octree but i cant find any marching cubes examples that use a sparse voxel octree anywhere on the internet
edit: octree code if needed idk
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace ChickenVoxel.Util
{
public class Octree<TType>
{
OctreeNode<TType> node;
int depth;
public Octree(Vector3 position,float size,int depth)
{
node = new OctreeNode<TType>(position, size,depth);
this.depth = depth;
}
public OctreeNode<TType> GetRoot()
{
return node;
}
public void Insert(TType type,Vector3 position)
{
var leafnode = node.Subdivide(position, type,depth - 1);
leafnode.Data = type;
}
public IEnumerable<OctreeNode<TType>> GetLeafNodes()
{
return node.GetLeafNodes();
}
}
public class OctreeNode<TType>
{
Vector3 position;
float size;
OctreeNode<TType>[] subnodes;
TType data;
int depth;
public OctreeNode(Vector3 Position,float Size,int depth,TType value = default(TType))
{
this.position = Position;
this.size = Size;
this.depth = depth;
}
public IEnumerable<OctreeNode<TType>> Nodes
{
get { return subnodes; }
}
public Vector3 Position
{
get { return position; }
}
public float Size
{
get { return size; }
}
public OctreeNode<TType> Subdivide(Vector3 targetpos,TType type, int depth = 0)
{
if(depth == 0)
{
return this;
}
var subdivindex = GetIndexOfPosition(targetpos, position);
if (subnodes == null)
{
subnodes = new OctreeNode<TType>[8];
for (int i = 0; i < subnodes.Length; i)
{
Vector3 newPos = position;
if ((i & 4) == 4)
{
newPos.y = size * 0.25f;
}
else
{
newPos.y -= size * 0.25f;
}
if ((i & 2) == 2)
{
newPos.x = size * 0.25f;
}
else
{
newPos.x -= size * 0.25f;
}
if ((i & 1) == 1)
{
newPos.z = size * 0.25f;
}
else
{
newPos.z -= size * 0.25f;
}
subnodes[i] = new OctreeNode<TType>(newPos, size * 0.5f,depth - 1);
}
}
return subnodes[subdivindex].Subdivide(targetpos, type, depth - 1);
}
private int GetIndexOfPosition(Vector3 lookupPosition, Vector3 nodePosition)
{
int index = 0;
index |= lookupPosition.y > nodePosition.y ? 4 : 0;
index |= lookupPosition.x > nodePosition.x ? 2 : 0;
index |= lookupPosition.z > nodePosition.z ? 1 : 0;
return index;
}
public bool IsLeaf()
{
return depth == 0;
}
public IEnumerable<OctreeNode<TType>> GetLeafNodes()
{
if (IsLeaf())
{
yield return this;
}
else
{
if(Nodes != null)
{
foreach (var node in subnodes)
{
foreach (var leaf in node.GetLeafNodes())
{
yield return leaf;
}
}
}
}
}
public TType Data
{
get { return data; }
internal set { this.data = value; }
}
}
}
Author
Account Strength
0%
Account Age
7 years
Verified Email
Yes
Verified Flair
No
Total Karma
34,548
Link Karma
9,973
Comment Karma
23,263
Profile updated: 7 months ago
Posts updated: 8 months ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/Unity3D/com...