| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884 |
- /******************************************************************************/
- #include "stdafx.h"
- namespace EE{
- /******************************************************************************/
- // MARCHING CUBES - based on Paul Bourke's - http://paulbourke.net/geometry/polygonise/
- /******************************************************************************/
- static const VecB VoxelOffset[]=
- {
- VecB(0, 0, 0), // 0
- VecB(1, 0, 0), // 1
- VecB(0, 1, 0), // 2
- VecB(1, 1, 0), // 3
- VecB(0, 0, 1), // 4
- VecB(1, 0, 1), // 5
- VecB(0, 1, 1), // 6
- VecB(1, 1, 1), // 7
- };
- static struct VoxelTri
- {
- U16 vtx_mask;
- Byte tris, quads, vtx_ind[13];
- }const VoxelTris[]=
- {
- {0x000, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x109, 1, 0, {3, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x203, 1, 0, {9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x30A, 0, 1, {1, 3, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x80C, 1, 0, {2, 11, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x905, 0, 1, {0, 2, 11, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0xA0F, 2, 0, {0, 9, 1, 11, 3, 2, 0, 0, 0, 0, 0, 0, 0}},
- {0xB06, 3, 0, {2, 11, 1, 11, 9, 1, 11, 8, 9, 0, 0, 0, 0}},
- {0x406, 1, 0, {10, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x50F, 2, 0, {3, 8, 0, 10, 2, 1, 0, 0, 0, 0, 0, 0, 0}},
- {0x605, 0, 1, {9, 10, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x70C, 3, 0, {3, 8, 2, 8, 10, 2, 8, 9, 10, 0, 0, 0, 0}},
- {0xC0A, 0, 1, {3, 1, 10, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0xD03, 3, 0, {1, 10, 0, 10, 8, 0, 10, 11, 8, 0, 0, 0, 0}},
- {0xE09, 3, 0, {0, 9, 3, 9, 11, 3, 9, 10, 11, 0, 0, 0, 0}},
- {0xF00, 2, 0, {10, 8, 9, 11, 8, 10, 0, 0, 0, 0, 0, 0, 0}},
- {0x190, 1, 0, {8, 7, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x099, 0, 1, {4, 0, 3, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x393, 2, 0, {9, 1, 0, 7, 4, 8, 0, 0, 0, 0, 0, 0, 0}},
- {0x29A, 3, 0, {9, 1, 4, 1, 7, 4, 1, 3, 7, 0, 0, 0, 0}},
- {0x99C, 2, 0, {7, 4, 8, 2, 11, 3, 0, 0, 0, 0, 0, 0, 0}},
- {0x895, 3, 0, {7, 4, 11, 4, 2, 11, 4, 0, 2, 0, 0, 0, 0}},
- {0xB9F, 3, 0, {1, 0, 9, 7, 4, 8, 11, 3, 2, 0, 0, 0, 0}},
- {0xA96, 2, 1, {2, 11, 9, 1, 2, 9, 11, 7, 4, 9, 0, 0, 0}},
- {0x596, 2, 0, {10, 2, 1, 7, 4, 8, 0, 0, 0, 0, 0, 0, 0}},
- {0x49F, 3, 0, {7, 4, 3, 4, 0, 3, 10, 2, 1, 0, 0, 0, 0}},
- {0x795, 3, 0, {10, 2, 9, 2, 0, 9, 7, 4, 8, 0, 0, 0, 0}},
- {0x69C, 4, 0, {9, 10, 2, 7, 9, 2, 3, 7, 2, 4, 9, 7, 0}},
- {0xD9A, 3, 0, {1, 10, 3, 10, 11, 3, 4, 8, 7, 0, 0, 0, 0}},
- {0xC93, 2, 1, {10, 11, 1, 4, 0, 1, 4, 1, 11, 7, 0, 0, 0}},
- {0xF99, 4, 0, {8, 7, 4, 11, 0, 9, 10, 11, 9, 3, 0, 11, 0}},
- {0xE90, 3, 0, {11, 7, 4, 9, 11, 4, 10, 11, 9, 0, 0, 0, 0}},
- {0x230, 1, 0, {4, 5, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x339, 2, 0, {4, 5, 9, 3, 8, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x033, 0, 1, {0, 4, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x13A, 3, 0, {4, 5, 8, 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, 4, 10, 3, 0, 10, 6, 7, 3}},
- {0x5F0, 2, 1, {10, 6, 7, 10, 4, 5, 10, 7, 8, 4, 0, 0, 0}},
- {0xB60, 3, 0, {5, 9, 6, 9, 11, 6, 9, 8, 11, 0, 0, 0, 0}},
- {0xA69, 2, 1, {6, 5, 0, 5, 9, 0, 3, 11, 6, 0, 0, 0, 0}},
- {0x963, 4, 0, {8, 11, 0, 11, 5, 0, 5, 1, 0, 11, 6, 5, 0}},
- {0x86A, 3, 0, {3, 11, 6, 5, 3, 6, 1, 3, 5, 0, 0, 0, 0}},
- {0x36C, 2, 1, {9, 8, 5, 2, 6, 5, 2, 5, 8, 3, 0, 0, 0}},
- {0x265, 3, 0, {6, 5, 9, 0, 6, 9, 2, 6, 0, 0, 0, 0, 0}},
- {0x16F, 3, 1, {8, 5, 1, 0, 8, 1, 8, 6, 5, 8, 3, 2, 6}},
- {0x066, 0, 1, {6, 5, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0xF66, 4, 0, {10, 2, 1, 11, 5, 9, 8, 11, 9, 6, 5, 11, 0}},
- {0xE6F, 3, 1, {3, 11, 0, 11, 6, 0, 10, 2, 1, 9, 0, 6, 5}},
- {0xD65, 3, 1, {5, 8, 11, 6, 5, 11, 5, 0, 8, 5, 10, 2, 0}},
- {0xC6C, 2, 1, {3, 11, 6, 3, 10, 2, 3, 6, 5, 10, 0, 0, 0}},
- {0x76A, 3, 1, {6, 3, 1, 10, 6, 1, 6, 8, 3, 6, 5, 9, 8}},
- {0x663, 2, 1, {0, 1, 10, 0, 5, 9, 0, 10, 6, 5, 0, 0, 0}},
- {0x569, 2, 0, {8, 3, 0, 10, 6, 5, 0, 0, 0, 0, 0, 0, 0}},
- {0x460, 1, 0, {6, 5, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x460, 1, 0, {5, 6, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x569, 2, 0, {3, 8, 0, 6, 10, 5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 0, 0, 0, 0, 0}},
- {0x1A3, 3, 0, {7, 8, 0, 1, 7, 0, 5, 7, 1, 0, 0, 0, 0}},
- {0x2A9, 3, 0, {3, 0, 9, 5, 3, 9, 7, 3, 5, 0, 0, 0, 0}},
- {0x3A0, 0, 1, {7, 8, 9, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0xD30, 3, 0, {4, 8, 5, 8, 10, 5, 8, 11, 10, 0, 0, 0, 0}},
- {0xC39, 4, 0, {4, 0, 5, 0, 11, 5, 11, 10, 5, 0, 3, 11, 0}},
- {0xF33, 4, 0, {9, 1, 0, 10, 4, 8, 11, 10, 8, 5, 4, 10, 0}},
- {0xE3A, 3, 1, {4, 11, 10, 5, 4, 10, 4, 3, 11, 4, 9, 1, 3}},
- {0x53C, 2, 1, {5, 4, 3, 4, 8, 3, 2, 10, 5, 3, 0, 0, 0}},
- {0x435, 3, 0, {2, 10, 5, 4, 2, 5, 0, 2, 4, 0, 0, 0, 0}},
- {0x73F, 3, 1, {2, 10, 3, 10, 5, 3, 9, 1, 0, 8, 3, 5, 4}},
- {0x636, 2, 1, {2, 10, 5, 2, 9, 1, 2, 5, 4, 9, 0, 0, 0}},
- {0x936, 2, 1, {1, 5, 2, 8, 11, 2, 8, 2, 5, 4, 0, 0, 0}},
- {0x83F, 3, 1, {11, 4, 0, 3, 11, 0, 11, 5, 4, 11, 2, 1, 5}},
- {0xB35, 3, 1, {5, 2, 0, 9, 5, 0, 5, 11, 2, 5, 4, 8, 11}},
- {0xA3C, 2, 0, {5, 4, 9, 3, 11, 2, 0, 0, 0, 0, 0, 0, 0}},
- {0x13A, 3, 0, {5, 4, 8, 3, 5, 8, 1, 5, 3, 0, 0, 0, 0}},
- {0x033, 0, 1, {5, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x339, 2, 1, {5, 4, 8, 5, 0, 9, 5, 8, 3, 0, 0, 0, 0}},
- {0x230, 1, 0, {5, 4, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0xE90, 3, 0, {7, 11, 4, 11, 9, 4, 11, 10, 9, 0, 0, 0, 0}},
- {0xF99, 4, 0, {3, 8, 0, 7, 9, 4, 7, 11, 9, 11, 10, 9, 0}},
- {0xC93, 2, 1, {11, 10, 1, 0, 4, 1, 11, 1, 4, 7, 0, 0, 0}},
- {0xD9A, 3, 1, {4, 1, 3, 8, 4, 3, 4, 10, 1, 4, 7, 11, 10}},
- {0x69C, 4, 0, {10, 9, 2, 9, 7, 2, 7, 3, 2, 9, 4, 7, 0}},
- {0x795, 3, 1, {7, 10, 9, 4, 7, 9, 7, 2, 10, 7, 8, 0, 2}},
- {0x49F, 3, 1, {10, 7, 3, 2, 10, 3, 10, 4, 7, 10, 1, 0, 4}},
- {0x596, 2, 0, {2, 10, 1, 4, 7, 8, 0, 0, 0, 0, 0, 0, 0}},
- {0xA96, 2, 1, {11, 2, 9, 2, 1, 9, 4, 7, 11, 9, 0, 0, 0}},
- {0xB9F, 3, 1, {4, 7, 9, 7, 11, 9, 3, 8, 0, 1, 9, 11, 2}},
- {0x895, 3, 0, {4, 7, 11, 2, 4, 11, 0, 4, 2, 0, 0, 0, 0}},
- {0x99C, 2, 1, {4, 7, 11, 4, 3, 8, 4, 11, 2, 3, 0, 0, 0}},
- {0x29A, 3, 0, {1, 9, 4, 7, 1, 4, 3, 1, 7, 0, 0, 0, 0}},
- {0x393, 2, 1, {1, 9, 4, 1, 8, 0, 1, 4, 7, 8, 0, 0, 0}},
- {0x099, 0, 1, {3, 0, 4, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x190, 1, 0, {7, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0xF00, 2, 0, {8, 10, 9, 8, 11, 10, 0, 0, 0, 0, 0, 0, 0}},
- {0xE09, 3, 0, {9, 0, 3, 11, 9, 3, 10, 9, 11, 0, 0, 0, 0}},
- {0xD03, 3, 0, {10, 1, 0, 8, 10, 0, 11, 10, 8, 0, 0, 0, 0}},
- {0xC0A, 0, 1, {10, 1, 3, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x70C, 3, 0, {8, 3, 2, 10, 8, 2, 9, 8, 10, 0, 0, 0, 0}},
- {0x605, 0, 1, {2, 10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x50F, 2, 1, {8, 3, 2, 8, 1, 0, 8, 2, 10, 1, 0, 0, 0}},
- {0x406, 1, 0, {2, 10, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0xB06, 3, 0, {11, 2, 1, 9, 11, 1, 8, 11, 9, 0, 0, 0, 0}},
- {0xA0F, 2, 1, {9, 0, 3, 9, 2, 1, 9, 3, 11, 2, 0, 0, 0}},
- {0x905, 0, 1, {11, 2, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x80C, 1, 0, {11, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x30A, 0, 1, {8, 3, 1, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x203, 1, 0, {1, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x109, 1, 0, {8, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- {0x000, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
- };
- /******************************************************************************/
- T1(TYPE) struct VoxelZero
- {
- static const TYPE value;
- };
- template<> const SByte VoxelZero<SByte>::value=0;
- template<> const Byte VoxelZero< Byte>::value=128;
- template<> const Flt VoxelZero< Flt >::value=0;
- static Flt VoxelLerp(SByte a_value, SByte b_value) { return (a_value!=b_value) ? Flt(a_value )/(a_value-b_value) : 0.5f;}
- static Flt VoxelLerp( Byte a_value, Byte b_value) { return (a_value!=b_value) ? Flt(a_value-128)/(a_value-b_value) : 0.5f;}
- static Flt VoxelLerp( Flt a_value, Flt b_value) {Flt d=a_value-b_value; return d ? a_value / d : 0.5f;}
- static Vec VoxelLerp(C VecI &a_pos, C VecI &b_pos, SByte a_value, SByte b_value) {return Lerp(a_pos, b_pos, VoxelLerp(a_value, b_value));}
- static Vec VoxelLerp(C VecI &a_pos, C VecI &b_pos, Byte a_value, Byte b_value) {return Lerp(a_pos, b_pos, VoxelLerp(a_value, b_value));}
- static Vec VoxelLerp(C VecI &a_pos, C VecI &b_pos, Flt a_value, Flt b_value) {return Lerp(a_pos, b_pos, VoxelLerp(a_value, b_value));}
- T1(TYPE) void _SetVoxelTris(C VecI &pos, TYPE (&Voxel)(C VecI &pos), MemPtr<Tri> tris)
- {
- #if 0
- VecI val_pos[8];
- TYPE val [8]; REPAO(val)=Voxel(val_pos[i]=pos+VoxelOffset[i]);
- #else
- TYPE val[8]; REPAO(val)=Voxel(pos+VoxelOffset[i]);
- #endif
- Int case_index=0;
- if(val[0]<VoxelZero<TYPE>::value)case_index|= 1;
- if(val[1]<VoxelZero<TYPE>::value)case_index|= 2;
- if(val[2]<VoxelZero<TYPE>::value)case_index|= 4;
- if(val[3]<VoxelZero<TYPE>::value)case_index|= 8;
- if(val[4]<VoxelZero<TYPE>::value)case_index|= 16;
- if(val[5]<VoxelZero<TYPE>::value)case_index|= 32;
- if(val[6]<VoxelZero<TYPE>::value)case_index|= 64;
- if(val[7]<VoxelZero<TYPE>::value)case_index|=128;
- C VoxelTri &vt=VoxelTris[case_index]; if(UInt vtx_mask=vt.vtx_mask)
- {
- Vec vtxs[12];
- #if 0
- if(vtx_mask& 1)vtxs[ 0]=VoxelLerp(val_pos[0], val_pos[1], val[0], val[1]);
- if(vtx_mask& 2)vtxs[ 1]=VoxelLerp(val_pos[1], val_pos[3], val[1], val[3]);
- if(vtx_mask& 4)vtxs[ 2]=VoxelLerp(val_pos[2], val_pos[3], val[2], val[3]);
- if(vtx_mask& 8)vtxs[ 3]=VoxelLerp(val_pos[0], val_pos[2], val[0], val[2]);
- if(vtx_mask& 16)vtxs[ 4]=VoxelLerp(val_pos[4], val_pos[5], val[4], val[5]);
- if(vtx_mask& 32)vtxs[ 5]=VoxelLerp(val_pos[5], val_pos[7], val[5], val[7]);
- if(vtx_mask& 64)vtxs[ 6]=VoxelLerp(val_pos[6], val_pos[7], val[6], val[7]);
- if(vtx_mask& 128)vtxs[ 7]=VoxelLerp(val_pos[4], val_pos[6], val[4], val[6]);
- if(vtx_mask& 256)vtxs[ 8]=VoxelLerp(val_pos[0], val_pos[4], val[0], val[4]);
- if(vtx_mask& 512)vtxs[ 9]=VoxelLerp(val_pos[1], val_pos[5], val[1], val[5]);
- if(vtx_mask&1024)vtxs[10]=VoxelLerp(val_pos[3], val_pos[7], val[3], val[7]);
- if(vtx_mask&2048)vtxs[11]=VoxelLerp(val_pos[2], val_pos[6], val[2], val[6]);
- #else
- if(vtx_mask& 1)vtxs[ 0].set(pos.x+VoxelLerp(val[0], val[1]), pos.y , pos.z);
- if(vtx_mask& 2)vtxs[ 1].set(pos.x+1 , pos.y+VoxelLerp(val[1], val[3]), pos.z);
- if(vtx_mask& 4)vtxs[ 2].set(pos.x+VoxelLerp(val[2], val[3]), pos.y+1 , pos.z);
- if(vtx_mask& 8)vtxs[ 3].set(pos.x , pos.y+VoxelLerp(val[0], val[2]), pos.z);
- if(vtx_mask& 16)vtxs[ 4].set(pos.x+VoxelLerp(val[4], val[5]), pos.y , pos.z+1);
- if(vtx_mask& 32)vtxs[ 5].set(pos.x+1 , pos.y+VoxelLerp(val[5], val[7]), pos.z+1);
- if(vtx_mask& 64)vtxs[ 6].set(pos.x+VoxelLerp(val[6], val[7]), pos.y+1 , pos.z+1);
- if(vtx_mask& 128)vtxs[ 7].set(pos.x , pos.y+VoxelLerp(val[4], val[6]), pos.z+1);
- if(vtx_mask& 256)vtxs[ 8].set(pos.x , pos.y , pos.z+VoxelLerp(val[0], val[4]));
- if(vtx_mask& 512)vtxs[ 9].set(pos.x+1 , pos.y , pos.z+VoxelLerp(val[1], val[5]));
- if(vtx_mask&1024)vtxs[10].set(pos.x+1 , pos.y+1 , pos.z+VoxelLerp(val[3], val[7]));
- if(vtx_mask&2048)vtxs[11].set(pos.x , pos.y+1 , pos.z+VoxelLerp(val[2], val[6]));
- #endif
- C Byte *src=vt.vtx_ind;
- REP(vt.tris)
- {
- C VecB &s=*(VecB*)src; src+=SIZE(VecB);
- Tri &t=tris.New();
- t.p[0]=vtxs[s.x];
- t.p[1]=vtxs[s.y];
- t.p[2]=vtxs[s.z];
- }
- if(vt.quads) // this can be either 0 or 1 (never anything else), so simple "if" check is enough
- {
- C VecB4 &s=*(VecB4*)src; //src+=SIZE(VecB4); not needed because it won't be used anymore
- Int i=tris.addNum(2);
- Tri &t0=tris[i], &t1=tris[i+1];
-
- #if 1 // fast
- t0.p[0]=vtxs[s.x];
- t0.p[1]=vtxs[s.y];
- t0.p[2]=vtxs[s.w];
- t1.p[0]=vtxs[s.w];
- t1.p[1]=vtxs[s.y];
- t1.p[2]=vtxs[s.z];
- #else // slower but only slightly better quality
- C Vec &a=vtxs[s.x],
- &b=vtxs[s.y],
- &c=vtxs[s.z],
- &d=vtxs[s.w];
- // quad can be made from 2 tris: abd+dbc, or abc+acd
- #if 0 // prefer option where 2 tris have similar area (and not where one is big and another small)
- if(Abs(TriArea2(a, b, d)-TriArea2(d, b, c))
- <Abs(TriArea2(a, b, c)-TriArea2(a, c, d)))
- #else // prefer option where 2 tris have smaller angle between each other (Cos of that angle is bigger)
- if(CosBetween(GetNormalU(a, b, d), GetNormalU(d, b, c))
- >CosBetween(GetNormalU(a, b, c), GetNormalU(a, c, d)))
- #endif
- {
- t0.p[0]=a; t0.p[1]=b; t0.p[2]=d;
- t1.p[0]=d; t1.p[1]=b; t1.p[2]=c;
- }else
- {
- t0.p[0]=a; t0.p[1]=b; t0.p[2]=c;
- t1.p[0]=a; t1.p[1]=c; t1.p[2]=d;
- }
- #endif
- }
- }
- }
- void SetVoxelTris(C VecI &pos, SByte (&Voxel)(C VecI &pos), MemPtr<Tri> tris) {return _SetVoxelTris(pos, Voxel, tris);}
- //void SetVoxelTris(C VecI &pos, Flt (&Voxel)(C VecI &pos), MemPtr<Tri> tris) {return _SetVoxelTris(pos, Voxel, tris);}
- /******************************************************************************
- // based on http://paulbourke.net/geometry/polygonise/marchingsource.cpp
- static const SByte VoxelTriEdgePoints[256][16]=
- {{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1},
- {3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1},
- {3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1},
- {3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1},
- {9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1},
- {1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1},
- {9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1},
- {2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1},
- {8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1},
- {9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1},
- {4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1},
- {3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1},
- {1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1},
- {4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1},
- {4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1},
- {9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1},
- {1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1},
- {5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1},
- {2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1},
- {9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1},
- {0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1},
- {2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1},
- {10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1},
- {4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1},
- {5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1},
- {5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1},
- {9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1},
- {0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1},
- {1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1},
- {10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1},
- {8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1},
- {2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1},
- {7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1},
- {9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1},
- {2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1},
- {11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1},
- {9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1},
- {5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1},
- {11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1},
- {11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1},
- {1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1},
- {9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1},
- {5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1},
- {2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1},
- {0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1},
- {5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1},
- {6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1},
- {0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1},
- {3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1},
- {6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1},
- {5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1},
- {1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1},
- {10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1},
- {6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1},
- {1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1},
- {8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1},
- {7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1},
- {3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1},
- {5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1},
- {0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1},
- {9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1},
- {8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1},
- {5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1},
- {0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1},
- {6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1},
- {10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1},
- {10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1},
- {8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1},
- {1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1},
- {3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1},
- {0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1},
- {10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1},
- {0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1},
- {3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1},
- {6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1},
- {9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1},
- {8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1},
- {3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1},
- {6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1},
- {0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1},
- {10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1},
- {10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1},
- {1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1},
- {2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1},
- {7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1},
- {7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1},
- {2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1},
- {1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1},
- {11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1},
- {8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1},
- {0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1},
- {7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1},
- {10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1},
- {2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1},
- {6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1},
- {7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1},
- {2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1},
- {1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1},
- {10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1},
- {10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1},
- {0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1},
- {7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1},
- {6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1},
- {8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1},
- {9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1},
- {6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1},
- {1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1},
- {4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1},
- {10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1},
- {8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1},
- {0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1},
- {1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1},
- {8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1},
- {10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1},
- {4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1},
- {10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1},
- {5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1},
- {11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1},
- {9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1},
- {6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1},
- {7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1},
- {3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1},
- {7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1},
- {9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1},
- {3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1},
- {6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1},
- {9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1},
- {1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1},
- {4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1},
- {7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1},
- {6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1},
- {3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1},
- {0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1},
- {6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1},
- {1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1},
- {0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1},
- {11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1},
- {6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1},
- {5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1},
- {9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1},
- {1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1},
- {1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1},
- {10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1},
- {0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1},
- {5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1},
- {10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1},
- {11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1},
- {0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1},
- {9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1},
- {7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1},
- {2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1},
- {8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1},
- {9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1},
- {9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1},
- {1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1},
- {9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1},
- {9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1},
- {5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1},
- {0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1},
- {10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1},
- {2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1},
- {0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1},
- {0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1},
- {9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1},
- {5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1},
- {3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1},
- {5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1},
- {8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1},
- {0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1},
- {9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1},
- {0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1},
- {1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1},
- {3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1},
- {4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1},
- {9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1},
- {11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1},
- {11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1},
- {2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1},
- {9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1},
- {3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1},
- {1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1},
- {4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1},
- {4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1},
- {0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1},
- {3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1},
- {3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1},
- {0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1},
- {9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1},
- {1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
- {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
- };
- void GenerateVoxelTris()
- {
- Mems<VoxelTri> vts; vts.setNumZero(Elms(VoxelTriEdgePoints));
- Memc<VecB> tris;
- Memc<VecB4> quads;
- Int mi=0;
- FREPAD(i, vts)
- {
- Int j=i;
- FlagSet(j, 4, FlagTest(i, 8)); FlagSet(j, 8, FlagTest(i, 4)); // swap #2 and #3
- FlagSet(j, 64, FlagTest(i, 128)); FlagSet(j, 128, FlagTest(i, 64)); // swap #6 and #7
- VoxelTri &vt=vts[j];
- vt.vtx_mask=0;
- for(Int p=0; VoxelTriEdgePoints[i][p]!=-1; p+=3)
- {
- VecB &t=tris.New();
- t.set(VoxelTriEdgePoints[i][p ],
- VoxelTriEdgePoints[i][p+1],
- VoxelTriEdgePoints[i][p+2]);
- t.reverse(); // reverse order of tris
- REPA(t)vt.vtx_mask|=1<<t.c[i];
- }
- REPA(tris)
- {
- VecB ti=tris[i];
- REPD(j, i)
- {
- VecB tj=tris[j];
- REPD(r, 3)if(ti.x==tj.c[r] && ti.y==tj.c[(r+2)%3])
- {
- tris.remove(i).remove(j); // remove 'i' first because it has bigger index, so after that, 'j' will be still the same
- quads.New().set(ti.x, tj.c[(r+1)%3], ti.y, ti.z);
- i--; goto next; // decrease by 1 because we've removed 2 and one "i--" is already called after 'next' automatically in 'REPA'
- }
- }
- next:;
- }
-
- MAX(mi, tris.elms()*3 + quads.elms()*4); DYNAMIC_ASSERT(mi<=MEMBER_ELMS(VoxelTri, vtx_ind), "mi out of range");
- DYNAMIC_ASSERT(quads.elms()<=1, "codes assume quads<=1");
- Byte *vtx_ind=vt.vtx_ind;
- vt. tris= tris.elms(); FREPA( tris){Copy(vtx_ind, & tris[i], SIZE(VecB )); vtx_ind+=SIZE(VecB );} tris .clear();
- vt.quads=quads.elms(); FREPA(quads){Copy(vtx_ind, &quads[i], SIZE(VecB4)); vtx_ind+=SIZE(VecB4);} quads.clear();
- }
- Str s;
- FREPA(vts)
- {
- C VoxelTri &vt=vts[i];
- s+=S+" {"+TextHex((UInt)vt.vtx_mask, 3, 0, true)+", "+vt.tris+", "+vt.quads+", {";
- //FREPA(vt.tri){if(i)s+=", "; s+=S+"{"+vt.tri[i]+"}";}
- FREPA(vt.vtx_ind){if(i)s+=", "; s+=vt.vtx_ind[i];}
- s+="}},\n";
- }
- ClipSet(s);
- }
- /******************************************************************************
- // SAMPLE USAGE
- /******************************************************************************
- SByte GetValue1(C VecI &pos) {return SFltToSByte(pos.length()-6);}
- Byte GetValue2(C VecI &pos) {return SFltToUByte(pos.length()-6);}
- Flt GetValue3(C VecI &pos) {return pos.length()-6 ;}
- {
- Memc<Tri> tris;
- for(Int x=-8; x<8; x++)
- for(Int y=-8; y<8; y++)
- for(Int z=-8; z<8; z++)
- {
- SetVoxelTris(VecI(x,y,z), GetValue3, tris);
- }
- MeshBase &base=mesh.parts(0).base;
- base.create(tris.elms()*3, 0, tris.elms(), 0);
- REPA(base.tri)base.tri.ind(i).set(i*3, i*3+1, i*3+2);
- REPA(tris)
- {
- base.vtx.pos(i*3 )=tris[i].p[0];
- base.vtx.pos(i*3+1)=tris[i].p[1];
- base.vtx.pos(i*3+2)=tris[i].p[2];
- }
- base.setNormals();
- //REPA(base.vtx)base.vtx.pos(i)+=base.vtx.nrm(i)*0.1f; // explode
- D.drawNullMaterials(true);
- mesh.setBox();
- mesh.setRender();
- }
- /******************************************************************************
-
- SURFACE NETS
- Based on:
- Mikola Lysenko "Surface Nets" (C) 2012, MIT License - https://github.com/mikolalysenko/mikolalysenko.github.com/blob/master/Isosurface/js/surfacenets.js
- S.F. Gibson, "Constrained Elastic Surface Nets". (1998) MERL Tech Report.
- /******************************************************************************/
- static const VecB2 CubeEdges[24]= // vertex number of each cube edge
- {
- {0, 1}, {0, 2}, {0, 4}, {1, 3}, {1, 5}, {2, 3}, {2, 6}, {3, 7}, {4, 5}, {4, 6}, {5, 7}, {6, 7}
- };
- static const U16 EdgeTable[256]= // 2^(cube configuration) -> 2^(edge configuration) map, there is one entry for each possible cube configuration, and the output is a 12-bit vector enumerating all edges crossing the 0-level
- {
- 0, 7, 25, 30, 98, 101, 123, 124, 168, 175, 177, 182, 202, 205, 211, 212, 772, 771, 797, 794, 870, 865, 895, 888, 940, 939, 949, 946, 974, 969, 983, 976, 1296, 1303, 1289, 1294, 1394, 1397, 1387, 1388, 1464, 1471, 1441, 1446, 1498, 1501, 1475, 1476, 1556, 1555, 1549, 1546, 1654, 1649, 1647, 1640, 1724, 1723, 1701, 1698, 1758, 1753, 1735, 1728, 2624, 2631, 2649, 2654, 2594, 2597, 2619, 2620, 2792, 2799, 2801, 2806, 2698, 2701, 2707, 2708, 2372, 2371, 2397, 2394, 2342, 2337, 2367, 2360, 2540, 2539, 2549, 2546, 2446, 2441, 2455, 2448, 3920, 3927, 3913, 3918, 3890, 3893, 3883, 3884, 4088, 4095, 4065, 4070, 3994, 3997, 3971, 3972, 3156, 3155, 3149, 3146, 3126, 3121, 3119, 3112, 3324, 3323, 3301, 3298, 3230, 3225, 3207, 3200, 3200, 3207, 3225, 3230, 3298, 3301, 3323, 3324, 3112, 3119, 3121, 3126, 3146, 3149, 3155, 3156, 3972, 3971, 3997, 3994, 4070, 4065, 4095, 4088, 3884, 3883, 3893, 3890, 3918, 3913, 3927, 3920, 2448, 2455, 2441, 2446, 2546, 2549, 2539, 2540, 2360, 2367, 2337, 2342, 2394, 2397, 2371, 2372, 2708, 2707, 2701, 2698, 2806, 2801, 2799, 2792, 2620, 2619, 2597, 2594, 2654, 2649, 2631, 2624, 1728, 1735, 1753, 1758, 1698, 1701, 1723, 1724, 1640, 1647, 1649, 1654, 1546, 1549, 1555, 1556, 1476, 1475, 1501, 1498, 1446, 1441, 1471, 1464, 1388, 1387, 1397, 1394, 1294, 1289, 1303, 1296, 976, 983, 969, 974, 946, 949, 939, 940, 888, 895, 865, 870, 794, 797, 771, 772, 212, 211, 205, 202, 182, 177, 175, 168, 124, 123, 101, 98, 30, 25, 7, 0
- };
- /*static void GenerateTables()
- {
- VecB2 cube_edges[12]; // vertex number of each cube edge
- Int k=0; FREP(8)for(Int j=1; j<=4; j<<=1)
- {
- Int p=i^j; if(i<=p)cube_edges[k++].set(i, p);
- }
- U16 edge_table[256];
- FREPA(edge_table)
- {
- UInt em=0;
- FREPAD(j, cube_edges)
- {
- Int a=!(i&(1<<cube_edges[j].x)),
- b=!(i&(1<<cube_edges[j].y));
- if(a!=b)em|=(1<<j);
- }
- edge_table[i]=em;
- }
- Str s ="{\n "; FREPA(cube_edges){if(i)s+=", "; s+=S+'{'+cube_edges[i]+'}';} s+="\n};\n";
- s+="{\n "; FREPA(edge_table){if(i)s+=", "; s+= edge_table[i] ;} s+="\n};\n";
- ClipSet(s);
- }*/
- void SetVoxelTris(Flt *data, C VecI &dims, MemPtr<Vec> vtxs, MemPtr<VecI4> quads, Bool smooth)
- {
- Int n=0, buf_no=1, R[]={1, (dims.x+1), (dims.x+1)*(dims.y+1)}, quad_start=quads.elms();
- Flt grid[8];
- VecI pos;
- Memt<Int> vtx_index_mem; Int *vtx_index=vtx_index_mem.setNum(R[2]*2).data();
-
- // March over the voxel grid
- for(pos.z=0; pos.z<dims.z-1; pos.z++, n+=dims.x, buf_no^=1, R[2]=-R[2])
- {
- // 'm' is the pointer into the 'vtx_index' we are going to use.
- // The contents of the buffer will be the indices of the vertices on the previous x/y slice of the volume
- Int m=1 + (dims.x+1)*(1 + buf_no*(dims.y+1));
- for(pos.y=0; pos.y<dims.y-1; pos.y++, n++, m+=2)
- for(pos.x=0; pos.x<dims.x-1; pos.x++, n++, m++)
- {
- // Read in 8 field values around this vertex and store them in an array
- // Also calculate 8-bit mask, like in marching cubes, so we can speed up sign checks later
- Int mask=0, g=0, id=n;
- for(Int k=0; k<2; k++, id+=dims.x*(dims.y-2))
- for(Int j=0; j<2; j++, id+=dims.x-2)
- for(Int i=0; i<2; i++, g++, id++)
- {
- Flt v=data[id];
- grid[g]=v;
- if(v<0)mask|=1<<g;
- }
-
- if(mask==0 || mask==0xFF)continue; // Check for early termination if cell does not intersect boundary
-
- // Sum up edge intersections
- Int edge_mask=EdgeTable[mask], e_count=0;
- Vec v=0;
-
- FREP(12) // For every edge of the cube...
- if(edge_mask&(1<<i)) // Use edge mask to check if it is crossed
- {
- e_count++; // If it did, increment number of edge crossings
- // Now find the point of intersection
- VecB2 edge=CubeEdges[i]; // get cube edge vertexes
- Flt g0 =grid[edge.x], // get grid values
- g1 =grid[edge.y],
- d =g0-g1; // Compute point of intersection
- if(d)d=g0/d;else continue;
-
- // Interpolate vertices and add up intersections (this can be done without multiplying)
- for(Int j=0, k=1; j<3; j++, k<<=1) // iterate all 3 dimensions
- {
- Int a=edge.x&k, // side of 'edge.x' point in 'j' dimension (left/right, down/up, back/front)
- b=edge.y&k; // side of 'edge.y' point in 'j' dimension (left/right, down/up, back/front)
- if(a!=b)v.c[j]+=(a ? 1-d : d);else // if sides are different, then we need to interpolate
- if(a )v.c[j]++; // if sides are the same, then just check which side is it
- }
- }
-
- // Add vertex
- vtx_index[m]=vtxs.elms(); // store vertex index
- vtxs.New()=pos+v/e_count; // Now we just average the edge intersections and add them to coordinate
-
- // Now we need to add faces together, to do this we just loop over 3 basis components
- FREP(3)
- {
- if(!(edge_mask&(1<<i)))continue; // The first three entries of the edge_mask count the crossings along the edge
- // i=axes we are point along. iu, iv = orthogonal axes
- Int iu=(i+1)%3,
- iv=(i+2)%3;
- // If we are on a boundary, skip it
- if(!pos.c[iu] || !pos.c[iv])continue;
- // Otherwise, look up adjacent edges in buffer
- Int du=R[iu],
- dv=R[iv];
- // Remember to flip orientation depending on the sign of the corner.
- if(mask&1)quads.New().set(vtx_index[m], vtx_index[m-du], vtx_index[m-du-dv], vtx_index[m-dv]);
- else quads.New().set(vtx_index[m], vtx_index[m-dv], vtx_index[m-du-dv], vtx_index[m-du]);
- }
- }
- }
- if(smooth)for(Int i=quads.elms(); --i>=quad_start; )
- {
- VecI4 &q=quads[i];
- C Vec &a=vtxs[q.x],
- &b=vtxs[q.y],
- &c=vtxs[q.z],
- &d=vtxs[q.w];
- // prefer option where 2 tris have smaller angle between each other (Cos of that angle is bigger)
- if(CosBetween(GetNormalU(a, b, d), GetNormalU(d, b, c))
- <CosBetween(GetNormalU(a, b, c), GetNormalU(a, c, d)))q.rotateOrder();
- }
- }
- /******************************************************************************/
- }
- /******************************************************************************/
|