// VOX file loader struct VoxAcc { unsigned char *ptr; size_t numBytes; }; struct VoxChunk { char chunk_id[4]; int content_size_bytes; int children_bytes; VoxAcc chunk_content; VoxAcc children_chunks; }; bool test_chunk(const VoxAcc &acc, const char *chunk_id, unsigned char **found) { unsigned char *ptr = acc.ptr; if (ptr[0]==chunk_id[0] && ptr[1]==chunk_id[1] && ptr[2]==chunk_id[2] && ptr[3]==chunk_id[3]) { *found=0; return true; } return false; } VoxChunk read_chunk(VoxAcc &acc) { unsigned char *ptr = acc.ptr; VoxChunk res; std::copy(ptr,ptr+4,(unsigned char*)res.chunk_id); std::copy(ptr+4,ptr+8,(unsigned char*)&res.content_size_bytes); std::copy(ptr+8,ptr+12,(unsigned char*)&res.children_bytes); res.chunk_content.ptr = ptr+12; res.chunk_content.numBytes = res.content_size_bytes; res.children_chunks.ptr = ptr+12+res.content_size_bytes; res.children_chunks.numBytes = res.children_bytes; acc.ptr += 12 + res.content_size_bytes + res.children_bytes; return res; } struct VoxMainPair { VoxChunk size; VoxChunk xyzi; }; struct VoxMain { VoxChunk pack; // optional std::vector models; VoxChunk rgba; // optional }; int pack_to_numModels(const VoxChunk &pack) { assert(pack.chunk_id[0]=='P'); assert(pack.chunk_id[1]=='A'); assert(pack.chunk_id[2]=='C'); assert(pack.chunk_id[3]=='K'); unsigned char *ptr = pack.chunk_content.ptr; int *ptr2 = (int*)ptr; return *ptr2; } struct VoxSize { int sx, sy, sz; }; VoxSize size_to_size(const VoxChunk &size) { assert(size.chunk_id[0]=='S'); assert(size.chunk_id[1]=='I'); assert(size.chunk_id[2]=='Z'); assert(size.chunk_id[3]=='E'); unsigned char *ptr = size.chunk_content.ptr; int *ptr2 = (int*)ptr; VoxSize res; res.sx = ptr2[0]; res.sy = ptr2[1]; res.sz = ptr2[2]; return res; } struct VoxXYZI { int numVoxels; int *ptr; // [int(x,y,z,colorIndex)] }; struct XYZI { unsigned char x; unsigned char y; unsigned char z; unsigned char colorIndex; }; XYZI ptr_to_xyzi(int *ptr) { unsigned char *ptr2 = (unsigned char*)ptr; XYZI res; res.x = ptr2[0]; res.y = ptr2[1]; res.z = ptr2[2]; res.colorIndex = ptr2[3]; return res; } XYZI Vox_to_xyzi(const VoxXYZI &vox, int i) { if (i<0 || i>=vox.numVoxels) { std::cout << "ERROR at index / Vox_to_xyzi: i=" << i << std::endl; i=0; } return ptr_to_xyzi(vox.ptr + i); } VoxXYZI xyzi_to_xyzi(const VoxChunk &xyzi) { assert(xyzi.chunk_id[0]=='X'); assert(xyzi.chunk_id[1]=='Y'); assert(xyzi.chunk_id[2]=='Z'); assert(xyzi.chunk_id[3]=='I'); unsigned char *ptr = xyzi.chunk_content.ptr; int *ptr2 = (int*)ptr; VoxXYZI res; res.numVoxels = ptr2[0]; res.ptr = ptr2 + 1; return res; } struct VoxPalette { unsigned int palette[256]; }; unsigned int default_palette[256] = { 0x00000000, 0xffffffff, 0xffccffff, 0xff99ffff, 0xff66ffff, 0xff33ffff, 0xff00ffff, 0xffffccff, 0xffccccff, 0xff99ccff, 0xff66ccff, 0xff33ccff, 0xff00ccff, 0xffff99ff, 0xffcc99ff, 0xff9999ff, 0xff6699ff, 0xff3399ff, 0xff0099ff, 0xffff66ff, 0xffcc66ff, 0xff9966ff, 0xff6666ff, 0xff3366ff, 0xff0066ff, 0xffff33ff, 0xffcc33ff, 0xff9933ff, 0xff6633ff, 0xff3333ff, 0xff0033ff, 0xffff00ff, 0xffcc00ff, 0xff9900ff, 0xff6600ff, 0xff3300ff, 0xff0000ff, 0xffffffcc, 0xffccffcc, 0xff99ffcc, 0xff66ffcc, 0xff33ffcc, 0xff00ffcc, 0xffffcccc, 0xffcccccc, 0xff99cccc, 0xff66cccc, 0xff33cccc, 0xff00cccc, 0xffff99cc, 0xffcc99cc, 0xff9999cc, 0xff6699cc, 0xff3399cc, 0xff0099cc, 0xffff66cc, 0xffcc66cc, 0xff9966cc, 0xff6666cc, 0xff3366cc, 0xff0066cc, 0xffff33cc, 0xffcc33cc, 0xff9933cc, 0xff6633cc, 0xff3333cc, 0xff0033cc, 0xffff00cc, 0xffcc00cc, 0xff9900cc, 0xff6600cc, 0xff3300cc, 0xff0000cc, 0xffffff99, 0xffccff99, 0xff99ff99, 0xff66ff99, 0xff33ff99, 0xff00ff99, 0xffffcc99, 0xffcccc99, 0xff99cc99, 0xff66cc99, 0xff33cc99, 0xff00cc99, 0xffff9999, 0xffcc9999, 0xff999999, 0xff669999, 0xff339999, 0xff009999, 0xffff6699, 0xffcc6699, 0xff996699, 0xff666699, 0xff336699, 0xff006699, 0xffff3399, 0xffcc3399, 0xff993399, 0xff663399, 0xff333399, 0xff003399, 0xffff0099, 0xffcc0099, 0xff990099, 0xff660099, 0xff330099, 0xff000099, 0xffffff66, 0xffccff66, 0xff99ff66, 0xff66ff66, 0xff33ff66, 0xff00ff66, 0xffffcc66, 0xffcccc66, 0xff99cc66, 0xff66cc66, 0xff33cc66, 0xff00cc66, 0xffff9966, 0xffcc9966, 0xff999966, 0xff669966, 0xff339966, 0xff009966, 0xffff6666, 0xffcc6666, 0xff996666, 0xff666666, 0xff336666, 0xff006666, 0xffff3366, 0xffcc3366, 0xff993366, 0xff663366, 0xff333366, 0xff003366, 0xffff0066, 0xffcc0066, 0xff990066, 0xff660066, 0xff330066, 0xff000066, 0xffffff33, 0xffccff33, 0xff99ff33, 0xff66ff33, 0xff33ff33, 0xff00ff33, 0xffffcc33, 0xffcccc33, 0xff99cc33, 0xff66cc33, 0xff33cc33, 0xff00cc33, 0xffff9933, 0xffcc9933, 0xff999933, 0xff669933, 0xff339933, 0xff009933, 0xffff6633, 0xffcc6633, 0xff996633, 0xff666633, 0xff336633, 0xff006633, 0xffff3333, 0xffcc3333, 0xff993333, 0xff663333, 0xff333333, 0xff003333, 0xffff0033, 0xffcc0033, 0xff990033, 0xff660033, 0xff330033, 0xff000033, 0xffffff00, 0xffccff00, 0xff99ff00, 0xff66ff00, 0xff33ff00, 0xff00ff00, 0xffffcc00, 0xffcccc00, 0xff99cc00, 0xff66cc00, 0xff33cc00, 0xff00cc00, 0xffff9900, 0xffcc9900, 0xff999900, 0xff669900, 0xff339900, 0xff009900, 0xffff6600, 0xffcc6600, 0xff996600, 0xff666600, 0xff336600, 0xff006600, 0xffff3300, 0xffcc3300, 0xff993300, 0xff663300, 0xff333300, 0xff003300, 0xffff0000, 0xffcc0000, 0xff990000, 0xff660000, 0xff330000, 0xff0000ee, 0xff0000dd, 0xff0000bb, 0xff0000aa, 0xff000088, 0xff000077, 0xff000055, 0xff000044, 0xff000022, 0xff000011, 0xff00ee00, 0xff00dd00, 0xff00bb00, 0xff00aa00, 0xff008800, 0xff007700, 0xff005500, 0xff004400, 0xff002200, 0xff001100, 0xffee0000, 0xffdd0000, 0xffbb0000, 0xffaa0000, 0xff880000, 0xff770000, 0xff550000, 0xff440000, 0xff220000, 0xff110000, 0xffeeeeee, 0xffdddddd, 0xffbbbbbb, 0xffaaaaaa, 0xff888888, 0xff777777, 0xff555555, 0xff444444, 0xff222222, 0xff111111 }; unsigned int palette098[256] = { 0x00000000,0xffffffff,0xff7f7f7f,0xffbfbfbf,0xff000000,0xff3f3f3f,0xff7f7f3f,0xff7fbf7f, 0xff3f7fbf,0xff7f3fbf,0xffbf3fbf,0xffbf7f7f,0xffbf3f3f,0xffbf7f3f,0xffbfbf3f,0xff7fbf3f, 0xff3fbf3f,0xff3fbf7f,0xff3fbfbf,0xff3f7f7f,0xff3f7f3f,0xff7f7f00,0xffbfbf00,0xff7fbf00, 0xff3fbf00,0xff00bf00,0xff00bf3f,0xff00bfbf,0xff007f7f,0xff007f3f,0xff007f00,0xff00007f, 0xff3f007f,0xff7f007f,0xffbf007f,0xffbf3f7f,0xff7f3f7f,0xff3f3f7f,0xff3f007f,0xff0000bf, 0xff3f00bf,0xff7f00bf,0xffbf00bf,0xffbf3fbf,0xff7f3fbf,0xff3f3fbf,0xff3f00bf,0xff0000ff, 0xff3f00ff,0xff7f00ff,0xffbf00ff,0xffbf3fff,0xff7f3fff,0xff3f3fff,0xff3f00ff,0xff00bfff, 0xff3fbfff,0xff7fbfff,0xffbfbfff,0xffbf7fff,0xff7f7fff,0xff3f7fff,0xff3f3fff,0xff007fff, 0xff3f7fff,0xff7f7fff,0xffbf7fff,0xffbf7fbf,0xff7f7fbf,0xff3f7fbf,0xff3f3fbf,0xff00bfbf, 0xff3fbfbf,0xff7fbfbf,0xffbfbfbf,0xffbf7fbf,0xff7f7fbf,0xff3f7fbf,0xff3f3fbf,0xff00ffbf, 0xff3fffbf,0xff7fffbf,0xffbfffbf,0xffbfff7f,0xff7fff7f,0xff3fff7f,0xff3f7f7f,0xff00ff7f, 0xff3fff7f,0xff7fff7f,0xffbfff7f,0xffbfbf3f,0xff7fbf3f,0xff3fbf3f,0xff3f7f3f,0xff00bf3f, 0xff3fbf3f,0xff7fbf3f,0xffbfbf3f,0xffbf7f3f,0xff7f7f3f,0xff3f7f3f,0xff3f3f3f,0xffbf3f00, 0xff7f3f00,0xff3f3f00,0xff3f3f00,0xff7f3f00,0xffbf3f00,0xffbf7f00,0xff7f7f00,0xff3f7f00, 0xff3f3f00,0xff7f0000,0xffbf0000,0xffbf3f00,0xff7f3f00,0xff3f3f00,0xff3f3f00,0xff7f3f00, 0xffbf3f00,0xffbf7f00,0xff7f7f00,0xff3f7f00,0xff3f3f00,0xffbf0000,0xffff0000,0xffbf3f00, 0xff7f3f00,0xff3f3f00,0xff3f3f00,0xff7f3f00,0xffbf3f00,0xffbf7f00,0xff7f7f00,0xff3f7f00, 0xff3f3f00,0xffbf7f00,0xffff7f00,0xffbf7f3f,0xff7f7f3f,0xff3f7f3f,0xff3f3f3f,0xffbf7f00, 0xffffbf00,0xffbfbf3f,0xff7fbf3f,0xff3fbf3f,0xff3f7f3f,0xffbf7f00,0xffffbf00,0xffbfbf3f, 0xff7fbf3f,0xff3fbf3f,0xff3f7f3f,0xffbf7f00,0xffffbf00,0xffbfbf3f,0xff7fbf3f,0xff3fbf3f, 0xff3f7f3f,0xff7f7f00,0xffbfbf00,0xff7fbf00,0xff3fbf00,0xff007f00,0xff007f3f,0xff007f7f, 0xff003f3f,0xff003f00,0xff3f3f00,0xff7f7f00,0xffbfbf00,0xff7fbf00,0xff3fbf00,0xff007f00, 0xff007f3f,0xff007f7f,0xff003f3f,0xff003f00,0xff3f3f00,0xff3f3f00,0xff7f7f00,0xffbfbf00, 0xff7fbf00,0xff3fbf00,0xff007f00,0xff007f3f,0xff007f7f,0xff003f3f,0xff003f00,0xff3f3f00, 0xff7f3f00,0xffbf3f00,0xffff7f00,0xffbf7f3f,0xff7f7f3f,0xff3f7f3f,0xff3f3f3f,0xffbf7f00, 0xffffbf00,0xffbfbf3f,0xff7fbf3f,0xff3fbf3f,0xff3f7f3f,0xffbf7f00,0xffffbf00,0xffbfbf3f, 0xff7fbf3f,0xff3fbf3f,0xff3f7f3f,0xffbf7f00,0xffffbf00,0xffbfbf3f,0xff7fbf3f,0xff3fbf3f, 0xff3f7f3f,0xff7f7f00,0xffbfbf00,0xff7fbf00,0xff3fbf00,0xff007f00,0xff007f3f,0xff007f7f, 0xff003f3f,0xff003f00,0xff3f3f00,0xff000000,0xff00003f,0xff00007f,0xff003fbf,0xff007fff, 0xff3fbfff,0xff7fbfff,0xffbfbfff,0xffffffff }; unsigned int convert_palette_chunk(unsigned int c) { //std::cout << std::hex << c << std::endl;; unsigned int a = c & 0xff000000; unsigned int b = c & 0x00ff0000; unsigned int g = c & 0x0000ff00; unsigned int r = c & 0x000000ff; b>>=16; g>>=8; r<<=16; g<<=8; return r+g+b+a; } unsigned int convert_palette(unsigned int c) { unsigned int a = c & 0xff000000; unsigned int b = c & 0x00ff0000; unsigned int g = c & 0x0000ff00; unsigned int r = c & 0x000000ff; b >>= 16; g >>= 8; r <<= 16; g <<= 8; return a+r+g+b; } VoxPalette default_vox_palette() { if (1) { VoxPalette res; std::transform(default_palette,default_palette+256,res.palette, [](auto x) { return convert_palette(x); }); return res; } else { VoxPalette res; std::transform(&palette098[0],&palette098[256],&res.palette[0], [](unsigned int x) { return convert_palette(x); }); return res; } } VoxPalette palette_from_chunk(const VoxChunk &palette) { VoxPalette res; unsigned char *ptr = palette.chunk_content.ptr; unsigned int *ptr2 = (unsigned int*)ptr; res.palette[0]=0x00000000; for(int i=0;i<=254;i++) { res.palette[i+1] = convert_palette_chunk(ptr2[i]); } return res; } class VoxMainLoopItem : public MainLoopItem { public: VoxMainLoopItem(GameApi::Env &env, GameApi::EveryApi &ev, std::string url, std::string homepage, float sx, float sy, float sz, int model0) : env(env), ev(ev), url(url), homepage(homepage), sx(sx), sy(sy), sz(sz), model0(model0) { } ~VoxMainLoopItem() { delete m_ptr; } virtual void Collect(CollectVisitor &vis) { vis.register_obj(this); } virtual void HeavyPrepare() { if (!sizes.size()) { #ifndef EMSCRIPTEN env.async_load_url(url, homepage); #endif GameApi::ASyncVec *ptr = env.get_loaded_async_url(url); if (!ptr) { std::cout << "async not ready!" << std::endl; return; } //data = new std::vector(ptr->begin(),ptr->end()); m_ptr=ptr; error = false; int offset = 8; VoxAcc main_chunk; main_chunk.ptr = const_cast(ptr->begin()) /*&data->operator[](0)*/ + offset; main_chunk.numBytes = ptr->size() /*data->size()*/ -offset; VoxChunk main_ch = read_chunk(main_chunk); VoxAcc &main_children = main_ch.children_chunks; unsigned char *found=0; bool has_pack = test_chunk(main_children, "PACK",&found); VoxChunk pack; if (has_pack) { pack = read_chunk(main_children); numModels = pack_to_numModels(pack); } else { numModels = 1000; } for(int i=0;i translates; do { has_nTRN = test_chunk(main_children,"nTRN",&found2); has_nGRP = test_chunk(main_children,"nGRP",&found2); has_nSHP = test_chunk(main_children,"nSHP",&found2); if (has_nTRN) { VoxChunk trn = read_chunk(main_children); VoxTranslate trans = translate_from_chunk(trn); if (count==0) root=trans; else translates.push_back(trans); print(trans); } if (has_nGRP) { VoxChunk grp = read_chunk(main_children); VoxGroup grp2 = parse_group(grp); print(grp2); } if (has_nSHP) { VoxChunk shp = read_chunk(main_children); VoxShape shp2 = parse_shape(shp); print(shp2); //std::cout << "SHP" << std::endl; } } while(has_nTRN||has_nGRP||has_nSHP); #endif } } virtual void Prepare() { HeavyPrepare(); } virtual void execute(MainLoopEnv &e) { } virtual void handle_event(MainLoopEvent &e) { } virtual std::vector shader_id() { return std::vector(); } VoxSize get_size(bool &res_error, int model) const { res_error = error; if (!error && (model-model0>=0 && model-model0=0 && model-model0=0 && model-model0palette[palette_index] == 0x0) return ev.polygon_api.p_empty(); GameApi::P cube = ev.polygon_api.cube(0.0,sx,0.0,sy,0.0,sz); GameApi::P c_cube = ev.polygon_api.color(cube, pal->palette[palette_index]); delete pal; cubecache[palette_index] = c_cube; return c_cube; } GameApi::P get_voxel_model(int model) const { bool error = false; VoxPalette *pal = new VoxPalette(get_palette(error)); int num = get_num_vox(error, model-model0); if (!error) { std::vector vec; VoxSize siz = get_size(error, model-model0); if (!error) { float start_x = siz.sx*sx/2.0; float start_y = siz.sy*sy/2.0; float start_z = siz.sz*sz/2.0; for(int i=0;ipalette[p.colorIndex]); vec.push_back(c_cube); } if (!error) { delete pal; GameApi::P p = ev.polygon_api.or_array3(vec); GameApi::P p2 = ev.polygon_api.rotatex(p,-3.14159/2.0); return p2; } } } delete pal; return ev.polygon_api.p_empty(); } private: GameApi::Env &env; GameApi::EveryApi &ev; GameApi::ASyncVec *m_ptr=0; std::string url; std::string homepage; //std::vector *data = 0; int numModels=0; std::vector sizes; std::vector xyzis; bool error = false; VoxPalette rgba; float sx,sy,sz; int model0; mutable std::vector cubecache; mutable int lastmodel=-1; }; class MultiplyFaceCollection : public ForwardFaceCollection { public: MultiplyFaceCollection(FaceCollection *coll, int sx, int sy, int sz) : ForwardFaceCollection(*coll),coll(coll), sx(sx),sy(sy),sz(sz) { } virtual Point FacePoint(int face, int point) const { Point p = coll->FacePoint(face,point); return Point(p.x*sx,p.y*sy,p.z*sz); } virtual std::string name() const { return "MultiplyFaceCollection"; } // TODO texcoord might need changes here to repeat the texture properly, // but requires knowledge of the cubes. private: FaceCollection *coll; int sx,sy,sz; }; GameApi::P GameApi::PolygonApi::multiply_facecoll(GameApi::P p, int sx, int sy, int sz) { FaceCollection *coll = find_facecoll(e,p); return add_polygon2(e, new MultiplyFaceCollection(coll,sx,sy,sz),1); } class OptCubesImpl : public OptCubes { public: OptCubesImpl(GameApi::Env &env, GameApi::EveryApi &ev, float sx, float sy, float sz) : env(env), ev(ev),sx(sx),sy(sy),sz(sz) { } virtual void Prepare() { } virtual void Collect(CollectVisitor &vis) { } virtual void HeavyPrepare() { } // the cubes virtual CubeSpec get_cube(unsigned int color, float border_width, unsigned int border_color, int sx, int sy, int sz) const { CubeSpec spec; spec.shapesize.size.sx = sx; spec.shapesize.size.sy = sy; spec.shapesize.size.sz = sz; spec.shapesize.shape.color = color; spec.shapesize.shape.border_width = border_width; spec.shapesize.shape.border_color = border_color; return spec; } virtual FaceCollection *create_cube(const CubeSpec &spec) const { GameApi::P cube = ev.polygon_api.cube(0.0,sx,0.0,sy,0.0,sz); GameApi::P c_cube = ev.polygon_api.color(cube, spec.shapesize.shape.color); GameApi::P m_cube = ev.polygon_api.multiply_facecoll(c_cube,spec.shapesize.size.sx,spec.shapesize.size.sy,spec.shapesize.size.sz); FaceCollection *coll = find_facecoll(env,m_cube); return coll; } private: GameApi::Env &env; GameApi::EveryApi &ev; float sx,sy,sz; }; class OptVoxelResizeVoxels : public OptVoxel { public: OptVoxelResizeVoxels(OptVoxel &vx, Voxel &vx2) : vx(vx), vx2(vx2) { } virtual void Prepare() { vx.Prepare(); vx2.Prepare(); HeavyPrepare(); } virtual void Collect(CollectVisitor &vis) { vx.Collect(vis); vx2.Collect(vis); vis.register_obj(this); } virtual void HeavyPrepare() { SizeSpec ps = vx.Size(); int sz0 = vx.SizeSize(); int ws = vx.WorldSize(); for(int w=0;w=p0.x+s0.sx) continue; if (p.y>=p0.y+s0.sy) continue; if (p.z>=p0.z+s0.sz) continue; /* if ((!(p.x>=p0.x && p.x=p0.y && p.y=p0.z && p.z &vx2; std::vector disable_list[20]; std::vector disable_list_size[20]; std::vector specs; std::vector e_specs; }; GameApi::OVX GameApi::VoxelApi::resize_voxels(OVX vx, VX vx2) { OptVoxel *vvx = find_opt_voxel(e,vx); Voxel *vvx2 = find_int_voxel(e,vx2); return add_opt_voxel(e, new OptVoxelResizeVoxels(*vvx,*vvx2)); } class OptVoxelRemoveExtraColours : public OptVoxel { public: OptVoxelRemoveExtraColours(OptVoxel &vx) : vx(vx) { } virtual void Collect(CollectVisitor &vis) { vx.Collect(vis); vis.register_obj(this); } virtual void HeavyPrepare() { newindicesfromold.resize(vx.ShapeSize(),-1); int s = vx.WorldSize(); for(int i=0;i " << shapeindices.size()-1 << std::endl; } } } void Prepare() { vx.Prepare(); HeavyPrepare(); } virtual SizeSpec Size() const { return vx.Size(); } virtual int ShapeSize() const { return shapeindices.size(); } virtual ShapeSpec WorldShapeIndex(int sh) const { return shapes[sh]; } virtual int SizeSize() const { return vx.SizeSize(); } virtual SizeSpec WorldSizeIndex(int sizesize) const { return vx.WorldSizeIndex(sizesize); } virtual int WorldSize() const { return vx.WorldSize(); } virtual ElemSpec WorldIndex(int w) const { ElemSpec e = vx.WorldIndex(w); e.shapeindex = newindicesfromold[e.shapeindex]; return e; } private: OptVoxel &vx; std::vector shapeindices; std::vector shapes; std::vector newindicesfromold; }; GameApi::OVX GameApi::VoxelApi::remove_colours(OVX vx) { OptVoxel *vvx = find_opt_voxel(e,vx); return add_opt_voxel(e, new OptVoxelRemoveExtraColours(*vvx)); } class OptVoxelRemoveNotEnabled : public OptVoxel { public: OptVoxelRemoveNotEnabled(OptVoxel &vx) : vx(vx) { firsttime = true;} virtual void Collect(CollectVisitor &vis) { vx.Collect(vis); vis.register_obj(this); } virtual void HeavyPrepare() { if (firsttime) { firsttime = false; int s = vx.WorldSize(); for(int i=0;i vec; bool firsttime; }; GameApi::OVX GameApi::VoxelApi::remove_not_enabled(OVX vx) { OptVoxel *vvx = find_opt_voxel(e,vx); return add_opt_voxel(e,new OptVoxelRemoveNotEnabled(*vvx)); } class VectorPTS : public PointsApiPoints { public: VectorPTS(const std::vector &p) : pp(p) { } virtual void Collect(CollectVisitor &vis) { } virtual void HeavyPrepare() { } virtual int NumPoints() const { return pp.size(); } virtual Point Pos(int i) const { return pp[i]; } virtual unsigned int Color(int i) const { return 0xffffffff; } virtual Vector Normal(int i) const { Vector v{0.0,0.0,-400.0}; return v; } private: std::vector pp; }; GameApi::PTS convert_to_pts(GameApi::Env &e, const std::vector &p) { return add_points_api_points(e,new VectorPTS(p)); } class OptVoxelRender { public: OptVoxelRender(OptVoxel &vx, OptCubes &cubes) : vx(vx), cubes(cubes) { } GameApi::P convert_to_P(GameApi::Env &e, GameApi::EveryApi &ev, float sx, float sy, float sz) { std::vector *specs = new std::vector; int s1 = vx.ShapeSize(); int s2 = vx.SizeSize(); std::cout << "Sizes:" << s1 << " " << s2 << std::endl; specs->reserve(s1*s2); CubeSpec spec; for(int i=0;ipush_back(spec); } } std::vector faces; int s = specs->size(); for(int i=0;ioperator[](i))); } delete specs; std::vector > ptss; // ptss[facesnum][pointnum] ptss.resize(faces.size()); int s3 = vx.WorldSize(); for(int i=0;i" << index << "/" << faces.size() << std::endl; } } // filter out empty ptss std::vector*> ptss3; std::vector faces3; int sg = ptss.size(); ptss3.reserve(sg); for(int i=0;i ptss2; int s4 = ptss3.size(); ptss2.reserve(s4); for(int i=0;i ps; int s5 = faces3.size(); ps.reserve(s5); for(int i=0;i mls; int s6 = std::min(ptss2.size(),ps.size()); // min probably doesnt do anything since sizes are the same. mls.reserve(s6); for(int i=0;i *specs = new std::vector; int s1 = vx.ShapeSize(); int s2 = vx.SizeSize(); std::cout << "Sizes:" << s1 << " " << s2 << std::endl; specs->reserve(s1*s2); CubeSpec spec; for(int i=0;ipush_back(spec); } } std::vector faces; int s = specs->size(); for(int i=0;ioperator[](i))); } delete specs; std::vector > ptss; // ptss[facesnum][pointnum] ptss.resize(faces.size()); int s3 = vx.WorldSize(); for(int i=0;i" << index << "/" << faces.size() << std::endl; } } // filter out empty ptss std::vector*> ptss3; std::vector faces3; int sg = ptss.size(); ptss3.reserve(sg); faces3.reserve(sg); for(int i=0;i ptss2; int s4 = ptss3.size(); ptss2.reserve(s4); for(int i=0;i ps; int s5 = faces3.size(); ps.reserve(s5); for(int i=0;i mls; int s6 = std::min(ps.size(),ptss2.size()); // min probably doesnt do anything since sizes are the same. mls.reserve(s6); for(int i=0;iCollect(vis); vis.register_obj(this); } virtual void HeavyPrepare() { if (p.id == -1) { cubesimpl = new OptCubesImpl(e,ev,sx,sy,sz); OptVoxel *vvx = find_opt_voxel(e,vx); render = new OptVoxelRender(*vvx,*cubesimpl); p = render->convert_to_P(e,ev,sx,sy,sz); FaceCollection *coll = find_facecoll(e,p); coll->Prepare(); } } virtual void Prepare() { OptVoxel *vvx = find_opt_voxel(e,vx); vvx->Prepare(); HeavyPrepare(); } virtual int NumFaces() const { if (p.id==-1) return 0; FaceCollection *coll = find_facecoll(e,p); return coll->NumFaces(); } virtual int NumPoints(int face) const { if (p.id==-1) return 3; FaceCollection *coll = find_facecoll(e,p); return coll->NumPoints(face); } virtual Point FacePoint(int face, int point) const { if (p.id==-1) return Point(0.0,0.0,0.0); FaceCollection *coll = find_facecoll(e,p); return coll->FacePoint(face,point); } virtual Vector PointNormal(int face, int point) const { if (p.id==-1) return Vector(0.0,0.0,0.0); FaceCollection *coll = find_facecoll(e,p); return coll->PointNormal(face,point); } virtual float Attrib(int face, int point, int id) const { return 0.0; } virtual int AttribI(int face, int point, int id) const { return 0; } virtual unsigned int Color(int face, int point) const { if (p.id==-1) return 0xffffffff; FaceCollection *coll = find_facecoll(e,p); return coll->Color(face,point); } virtual Point2d TexCoord(int face, int point) const { if (p.id==-1) { Point2d p; p.x = 0.0; p.y = 0.0; return p; } FaceCollection *coll = find_facecoll(e,p); return coll->TexCoord(face,point); } virtual float TexCoord3(int face, int point) const { if (p.id==-1) { return 0.0; } FaceCollection *coll = find_facecoll(e,p); return coll->TexCoord3(face,point); } virtual VEC4 Joints(int face, int point) const { if (p.id==-1) { VEC4 v; return v; } FaceCollection *coll = find_facecoll(e,p); return coll->Joints(face,point); } virtual VEC4 Weights(int face, int point) const { if (p.id==-1) { VEC4 v; return v; } FaceCollection *coll = find_facecoll(e,p); return coll->Weights(face,point); } private: GameApi::Env &e; GameApi::EveryApi &ev; GameApi::OVX vx; float sx,sy,sz; GameApi::P p = { -1 }; mutable OptCubesImpl *cubesimpl=0; mutable OptVoxelRender *render=0; }; class RenderOVX : public MainLoopItem { public: RenderOVX(GameApi::Env &e, GameApi::EveryApi &ev, GameApi::OVX vx, GameApi::MT mat, float sx, float sy, float sz) : e(e), ev(ev), vx(vx), mat(mat), sx(sx),sy(sy), sz(sz) { } ~RenderOVX() { delete cubesimpl; delete render; } virtual void Collect(CollectVisitor &vis) { OptVoxel *vvx = find_opt_voxel(e,vx); vvx->Collect(vis); vis.register_obj(this); } virtual void HeavyPrepare() { if (ml.id == -1) { cubesimpl = new OptCubesImpl(e,ev,sx,sy,sz); OptVoxel *vvx = find_opt_voxel(e,vx); render = new OptVoxelRender(*vvx,*cubesimpl); ml = render->convert_to_ML(e,ev,sx,sy,sz,mat); MainLoopItem *item = find_main_loop(e,ml); item->Prepare(); } } virtual void Prepare() { OptVoxel *vvx = find_opt_voxel(e,vx); vvx->Prepare(); HeavyPrepare(); } virtual void execute(MainLoopEnv &e2) { if (ml.id != -1) { MainLoopItem *item = find_main_loop(e,ml); item->execute(e2); } } virtual void handle_event(MainLoopEvent &e2) { if (ml.id != -1) { MainLoopItem *item = find_main_loop(e,ml); item->handle_event(e2); } } virtual std::vector shader_id() { if (ml.id != -1) { MainLoopItem *item = find_main_loop(e,ml); return item->shader_id(); } return std::vector(); } private: GameApi::Env &e; GameApi::EveryApi &ev; GameApi::OVX vx; GameApi::MT mat; float sx,sy,sz; GameApi::ML ml = { -1 }; mutable OptCubesImpl *cubesimpl; mutable OptVoxelRender *render; }; GameApi::ML GameApi::VoxelApi::render_ovx(GameApi::EveryApi &ev, OVX vx, MT mat, float sx, float sy, float sz) { GameApi::ML ml = add_main_loop(e, new RenderOVX(e,ev,vx,mat,sx,sy,sz)); GameApi::MN I1=ev.move_api.mn_empty(); GameApi::MN mn=ev.move_api.rotatex(I1,-3.14159/2.0); GameApi::ML ml2 = ev.move_api.move_ml(ev,ml,mn,1,10.0); return ml2; } GameApi::P GameApi::VoxelApi::render_ovx_p(GameApi::EveryApi &ev, OVX vx, float sx, float sy, float sz) { GameApi::P p = add_polygon2(e, new RenderOVXToP(e,ev,vx,sx,sy,sz),1); GameApi::P p2 = ev.polygon_api.rotatex(p,-3.14159/2.0); return p2; } class EmptyOptVoxel : public OptVoxel { public: EmptyOptVoxel() { } virtual void Prepare() { } virtual void Collect(CollectVisitor &vis) { } virtual void HeavyPrepare() { } // the grid virtual SizeSpec Size() const { SizeSpec sz; sz.sx = 1; sz.sy=1;sz.sz=1; return sz; } // the world virtual int ShapeSize() const { return 0; } virtual ShapeSpec WorldShapeIndex(int shapesize) const { ShapeSpec s; return s; } virtual int SizeSize() const { return 0; } virtual SizeSpec WorldSizeIndex(int sizesize) const { SizeSpec s; return s; } virtual int WorldSize() const { return 0; } virtual ElemSpec WorldIndex(int w) const { ElemSpec e; return e; } }; GameApi::OVX GameApi::VoxelApi::empty_ovx() { return add_opt_voxel(e,new EmptyOptVoxel); } class VoxelToOptVoxel : public OptVoxel { public: // uses just the colour from the FaceCollections => compatible with voxvoxels. VoxelToOptVoxel(Voxel &vx, std::vector cubes) : vx(vx), cubes(cubes) { } virtual void Collect(CollectVisitor &vis) { vx.Collect(vis); int s = cubes.size(); for(int i=0;iCollect(vis); } vis.register_obj(this); } virtual void HeavyPrepare() { c_sx = vx.SizeX(); c_sy = vx.SizeY(); c_sz = vx.SizeZ(); } virtual void Prepare() { vx.Prepare(); int s = cubes.size(); for(int i=0;iPrepare(); } HeavyPrepare(); } // the grid virtual SizeSpec Size() const { SizeSpec sz; sz.sx = c_sx; //vx.SizeX(); sz.sy = c_sy; //vx.SizeY(); sz.sz = c_sz; //vx.SizeZ(); return sz; } // the world virtual int ShapeSize() const { return cubes.size(); } virtual int SizeSize() const { return 1; } virtual int WorldSize() const { return vx.SizeX()*vx.SizeY()*vx.SizeZ(); } virtual ShapeSpec WorldShapeIndex(int shape) const { ShapeSpec spec; spec.color = cubes[shape]->Color(0,0); // fetch cube color. spec.border_width = 0.0f; spec.border_color = 0xff000000; return spec; } virtual SizeSpec WorldSizeIndex(int size) const { SizeSpec spec; spec.sx = 1; spec.sy = 1; spec.sz = 1; return spec; } virtual ElemSpec WorldIndex(int w) const { int sx = c_sx; int sy = c_sy; int sz = c_sz; int sss_x = w / (sy*sz); int sss_xr = w - (sss_x*sy*sz); int sss_y = sss_xr / sz; int sss_yr = sss_xr - (sss_y*sz); int sss_z = sss_yr; //std::cout << "Sizes:" << sx << " " << sy << " " << sz << std::endl; //std::cout << "Index:" << sss_x << " " << sss_y << " " << sss_z << std::endl; ElemSpec e_spec; e_spec.pos.x = sss_x; e_spec.pos.y = sss_y; e_spec.pos.z = sss_z; if (sss_x<1 || sss_y<1 ||sss_z<1|| sss_x>=sx-1 || sss_y>=sy-1 || sss_z >=sz-1) { e_spec.enabled = false; e_spec.shapeindex = 0; e_spec.sizeindex = 0; return e_spec; } int val = vx.Map(sss_x,sss_y,sss_z); bool b = false; if (val!=-1) { int val_x = vx.Map(sss_x+1,sss_y,sss_z); if (val_x==-1) { b=true; } else { int val_y = vx.Map(sss_x,sss_y+1,sss_z); if (val_y==-1) { b=true; } else { int val_z = vx.Map(sss_x,sss_y,sss_z+1); if (val_z==-1) { b=true; } else { int val_mx = vx.Map(sss_x-1,sss_y,sss_z); if (val_mx==-1) { b=true; } else { int val_my = vx.Map(sss_x,sss_y-1,sss_z); if (val_my==-1) { b=true; } else { int val_mz = vx.Map(sss_x,sss_y,sss_z-1); if (val_mz==-1) { b=true; } } } } } } } e_spec.enabled = val!=-1 && b; e_spec.shapeindex = val; e_spec.sizeindex = 0; return e_spec; } private: Voxel &vx; std::vector cubes; int c_sx, c_sy, c_sz; }; GameApi::OVX GameApi::VoxelApi::vx_to_ovx(VX vx, std::vector

vec) { Voxel *vvx = find_int_voxel(e,vx); std::vector facecoll; int s = vec.size(); for(int i=0;i { public: VoxVoxel(GameApi::Env &e, GameApi::EveryApi &ev, std::string url, int model, float sx, float sy, float sz) : ml(e,ev,url,gameapi_homepageurl,sx,sy,sz,model), model(model) { } virtual void Collect(CollectVisitor &vis) { ml.Collect(vis); vis.register_obj(this); } virtual void HeavyPrepare() { bool error = false; int s = ml.get_num_vox(error,model); int sx = SizeX(); int sy = SizeY(); int sz = SizeZ(); vox.resize(sx); for(int x=0;x=vox.size()||y>=vox[x].size()||z>=vox[x][y].size()) return -1; int res = vox[x][y][z]; if (res==0) res=-1; return res; #if 0 if (x>=0 && x=0 && y=0 && z>> vox; }; class VoxCubeFaceCollection : public FaceCollection { public: VoxCubeFaceCollection(GameApi::Env &e, GameApi::EveryApi &ev, std::string url, std::string homepage, int model, int palette_index, float sx, float sy, float sz, VoxMainLoopItem &ml) : env(e), url(url),homepage(homepage), ml(ml),model(model),palette_index(palette_index) { } virtual std::string name() const { return "VoxFaceCollection"; } virtual void Collect(CollectVisitor &vis) { ml.Collect(vis); vis.register_obj(this); } virtual void HeavyPrepare() { faces = ml.get_cube(model,palette_index); } virtual void Prepare() { ml.Prepare(); HeavyPrepare(); } virtual int NumFaces() const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->NumFaces(); } return 0; } virtual int NumPoints(int face) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->NumPoints(face); } return 0; } virtual Point FacePoint(int face, int point) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->FacePoint(face,point); } return Point(0.0,0.0,0.0); } virtual Vector PointNormal(int face, int point) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->PointNormal(face,point); } return Vector(0.0,0.0,0.0); } virtual float Attrib(int face, int point, int id) const { return 0.0; } virtual int AttribI(int face, int point, int id) const { return 0; } virtual unsigned int Color(int face, int point) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->Color(face,point); } return 0xffffffff; } virtual Point2d TexCoord(int face, int point) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->TexCoord(face,point); } Point2d p; return p; } virtual float TexCoord3(int face, int point) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->TexCoord3(face,point); } return 0.0f; } virtual VEC4 Joints(int face, int point) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->Joints(face,point); } VEC4 v; return v; } virtual VEC4 Weights(int face, int point) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->Weights(face,point); } VEC4 v; return v; } private: GameApi::Env &env; std::string url; std::string homepage; VoxMainLoopItem &ml; GameApi::P faces = { -1 }; int model; int palette_index; }; class VoxFaceCollection : public FaceCollection { public: VoxFaceCollection(GameApi::Env &e, GameApi::EveryApi &ev, std::string url, std::string homepage, int model, float sx, float sy, float sz) : env(e), url(url),homepage(homepage), ml(e,ev,url,homepage,sx,sy,sz,model),model(model) { } virtual std::string name() const { return "VoxFaceCollection"; } virtual void Collect(CollectVisitor &vis) { ml.Collect(vis); } virtual void HeavyPrepare() { faces = ml.get_voxel_model(model); } virtual void Prepare() { ml.Prepare(); HeavyPrepare(); } virtual int NumFaces() const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->NumFaces(); } return 0; } virtual int NumPoints(int face) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->NumPoints(face); } return 0; } virtual Point FacePoint(int face, int point) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->FacePoint(face,point); } return Point(0.0,0.0,0.0); } virtual Vector PointNormal(int face, int point) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->PointNormal(face,point); } return Vector(0.0,0.0,0.0); } virtual float Attrib(int face, int point, int id) const { return 0.0; } virtual int AttribI(int face, int point, int id) const { return 0; } virtual unsigned int Color(int face, int point) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->Color(face,point); } return 0xffffffff; } virtual Point2d TexCoord(int face, int point) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->TexCoord(face,point); } Point2d p; return p; } virtual float TexCoord3(int face, int point) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->TexCoord3(face,point); } return 0.0f; } virtual VEC4 Joints(int face, int point) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->Joints(face,point); } VEC4 v; return v; } virtual VEC4 Weights(int face, int point) const { if (faces.id != -1) { FaceCollection *coll = find_facecoll(env,faces); return coll->Weights(face,point); } VEC4 v; return v; } private: GameApi::Env &env; std::string url; std::string homepage; VoxMainLoopItem ml; GameApi::P faces = { -1 }; int model; }; GameApi::P GameApi::VoxelApi::vox_voxel(GameApi::EveryApi &ev, std::string url, int model, float sx, float sy, float sz) { GameApi::VX vx = vox_voxel2(ev,url,model,sx,sy,sz); Voxel *vvx = find_int_voxel(e,vx); vvx->Prepare(); int ssx = vvx->SizeX(); int ssy = vvx->SizeY(); int ssz = vvx->SizeZ(); float u_x = ssx*sx; float u_y = ssy*sy; float u_z = ssz*sz; float p_x = -u_x/2.0; float p_y = -u_y/2.0; float p_z = -u_z/2.0; std::vector cubes; GameApi::ARR cubes_arr = ev.voxel_api.vox_cubes(ev,url, model, sx,sy,sz); ArrayType *arr_type = find_array(e,cubes_arr); int s = arr_type->vec.size(); for(int i=0;ivec[i]; cubes.push_back(p); } std::vector ptss; GameApi::ARR pts_arr = ev.voxel_api.voxel_instancing(vx,256,p_x,p_x+u_x,p_y,p_y+u_y,p_z,p_z+u_z); ArrayType *pts_type = find_array(e,pts_arr); int s2 = pts_type->vec.size(); for(int i=0;ivec[i]; ptss.push_back(pts); } GameApi::P p = ev.voxel_api.voxel_static(ev,cubes,ptss); GameApi::P p2 = ev.polygon_api.rotatex(p,-3.14159/2.0); return p2; //return add_polygon2(e, new VoxFaceCollection(e,ev, url,gameapi_homepageurl,model,sx,sy,sz),1); } GameApi::P GameApi::VoxelApi::vox_voxel3(GameApi::EveryApi &ev, std::string url, int model, float sx, float sy, float sz) { GameApi::VX vx = vox_voxel2(ev,url,model,sx,sy,sz); std::vector cubes; GameApi::ARR cubes_arr = ev.voxel_api.vox_cubes(ev,url, model, sx,sy,sz); ArrayType *arr_type = find_array(e,cubes_arr); int s = arr_type->vec.size(); for(int i=0;ivec[i]; cubes.push_back(p); } GameApi::OVX ovx = vx_to_ovx(vx,cubes); GameApi::OVX I4=ev.voxel_api.remove_not_enabled(ovx); GameApi::OVX I40=ev.voxel_api.remove_colours(I4); GameApi::OVX I41=ev.voxel_api.resize_voxels(I40,vx); GameApi::P p = render_ovx_p(ev,I41,sx,sy,sz); return p; } GameApi::VX GameApi::VoxelApi::vox_voxel2(GameApi::EveryApi &ev, std::string url, int model, float sx, float sy, float sz) { return add_int_voxel(e,new VoxVoxel(e,ev,url, model,sx,sy,sz)); } GameApi::ARR GameApi::VoxelApi::vox_cubes(GameApi::EveryApi &ev, std::string url, int model, float sx, float sy, float sz) { ArrayType *array = new ArrayType; array->type = 44; int s = 256; VoxMainLoopItem *ml = new VoxMainLoopItem(e,ev,url,gameapi_homepageurl,sx,sy,sz,model); for(int i=0;ivec.push_back(add_polygon2(e,new VoxCubeFaceCollection(e,ev,url,gameapi_homepageurl, model, i, sx,sy,sz,*ml),1).id); } return add_array(e,array); } class VoxML : public MainLoopItem { public: VoxML(GameApi::Env &env, GameApi::EveryApi &ev, std::string url, int model, float sx, float sy, float sz, GameApi::MT mt) : env(env), ev(ev), url(url), model(model), sx(sx), sy(sy), sz(sz),mt(mt) { } virtual void Collect(CollectVisitor &vis) { vis.register_obj(this); } virtual void HeavyPrepare() { GameApi::ARR I1=ev.voxel_api.vox_cubes(ev,url,model,sx,sy,sz); ArrayType *arr2 = find_array(env,I1); std::vector vec2; int s2 = arr2->vec.size(); for(int i=0;ivec[i]; vec2.push_back(p); } GameApi::VX I2=ev.voxel_api.vox_voxel2(ev,url,model,sx,sy,sz); Voxel *vvx = find_int_voxel(env,I2); vvx->Prepare(); int ssx = vvx->SizeX(); int ssy = vvx->SizeY(); int ssz = vvx->SizeZ(); float u_x = ssx*sx; float u_y = ssy*sy; float u_z = ssz*sz; float p_x = -u_x/2.0; float p_y = -u_y/2.0; float p_z = -u_z/2.0; GameApi::ARR I3=ev.voxel_api.voxel_instancing(I2,256,p_x,p_x+u_x,p_y,p_y+u_y,p_z,p_z+u_z); GameApi::MT I4=mt; //ev.materials_api.colour_material(ev,1.0); //ev.materials_api.m_def(ev); ArrayType *arr = find_array(env,I3); std::vector vec; int s = arr->vec.size(); for(int i=0;ivec[i]; vec.push_back(p); } GameApi::ML I5=ev.voxel_api.voxel_bind(ev,vec2,vec,I4); item = find_main_loop(env,I5); item->Prepare(); vvx->CleanPrepare(); } virtual void Prepare() { HeavyPrepare(); } virtual void execute(MainLoopEnv &e) { if (item) item->execute(e); } virtual void handle_event(MainLoopEvent &e) { if (item) item->handle_event(e); } virtual std::vector shader_id() { if (item) return item->shader_id(); return std::vector(); } private: GameApi::Env &env; GameApi::EveryApi &ev; std::string url; int model; float sx, sy, sz; MainLoopItem *item=0; GameApi::MT mt; }; GameApi::ML GameApi::VoxelApi::vox_ml(GameApi::EveryApi &ev, std::string url, int model, float sx, float sy, float sz) { GameApi::MT mt = ev.materials_api.colour_material(ev,1.0); GameApi::ML ml = add_main_loop(e, new VoxML(e,ev,url,model,sx,sy,sz,mt)); GameApi::MN mn0 = ev.move_api.mn_empty(); GameApi::MN mn1 = ev.move_api.rotatex(mn0,-3.14159/2.0); GameApi::ML ml1 = ev.move_api.move_ml(ev,ml,mn1,1,10.0); return ml1; } GameApi::ML GameApi::VoxelApi::vox_ml2(GameApi::EveryApi &ev, std::string url, int model, float sx, float sy, float sz) { GameApi::VX I1=ev.voxel_api.vox_voxel2(ev,url,model,sx,sy,sz); GameApi::ARR I2=ev.voxel_api.vox_cubes(ev,url,model,sx,sy,sz); ArrayType *t = find_array(e,I2); std::vector vec; int s = t->vec.size(); for(int i=0;ivec[i]; vec.push_back(p); } GameApi::OVX I3=ev.voxel_api.vx_to_ovx(I1,vec); GameApi::OVX I4=ev.voxel_api.remove_not_enabled(I3); GameApi::OVX I40=ev.voxel_api.remove_colours(I4); GameApi::OVX I41=ev.voxel_api.resize_voxels(I40,I1); // TODO ADD MORE OPTIMIZATIONS TO THIS GameApi::MT I5=ev.materials_api.colour_material(ev,1); GameApi::ML I6=ev.voxel_api.render_ovx(ev,I41,I5,20,20,20); return I6; } GameApi::ML GameApi::VoxelApi::vox_bind_ml(GameApi::EveryApi &ev, std::string url, int model, float sx, float sy, float sz, GameApi::MT mt) { GameApi::ML ml = add_main_loop(e, new VoxML(e,ev,url,model,sx,sy,sz,mt)); GameApi::MN mn0 = ev.move_api.mn_empty(); GameApi::MN mn1 = ev.move_api.rotatex(mn0,-3.14159/2.0); GameApi::ML ml1 = ev.move_api.move_ml(ev,ml,mn1,1,10.0); return ml1; } GameApi::ML GameApi::VoxelApi::vox_bind_ml2(GameApi::EveryApi &ev, std::string url, int model, float sx, float sy, float sz, GameApi::MT mt) { GameApi::VX I1=ev.voxel_api.vox_voxel2(ev,url,model,sx,sy,sz); GameApi::ARR I2=ev.voxel_api.vox_cubes(ev,url,model,sx,sy,sz); ArrayType *t = find_array(e,I2); std::vector vec; int s = t->vec.size(); for(int i=0;ivec[i]; vec.push_back(p); } GameApi::OVX I3=ev.voxel_api.vx_to_ovx(I1,vec); GameApi::OVX I4=ev.voxel_api.remove_not_enabled(I3); GameApi::OVX I40=ev.voxel_api.remove_colours(I4); GameApi::OVX I41=ev.voxel_api.resize_voxels(I40,I1); // TODO ADD MORE OPTIMIZATIONS TO THIS GameApi::ML I6=ev.voxel_api.render_ovx(ev,I41,mt,sx,sy,sz); return I6; }