Work on port of meshgen code
This commit is contained in:
parent
9330ebf8d6
commit
d8ad5acf77
5
build.sh
5
build.sh
@ -4,6 +4,5 @@ cd src/shaders/
|
|||||||
./compile_shaders.sh
|
./compile_shaders.sh
|
||||||
cd ..
|
cd ..
|
||||||
cd ..
|
cd ..
|
||||||
/home/katajisto/bin/jai/bin/jai-linux -x64 first.jai
|
jai -x64 first.jai
|
||||||
./first &
|
./first
|
||||||
/home/katajisto/bin/jai/bin/jai-linux first.jai - wasm
|
|
||||||
|
|||||||
@ -3,6 +3,8 @@ rotation : float = 0.0;
|
|||||||
tilt : float = 0.0;
|
tilt : float = 0.0;
|
||||||
zoom : float = 3.0;
|
zoom : float = 3.0;
|
||||||
|
|
||||||
|
brush_radius : int = 5;
|
||||||
|
|
||||||
roughness : int = 0;
|
roughness : int = 0;
|
||||||
metallic : int = 0;
|
metallic : int = 0;
|
||||||
emittance : int = 0;
|
emittance : int = 0;
|
||||||
@ -62,6 +64,22 @@ handle_tool_click :: () {
|
|||||||
if current_mode == .POINT {
|
if current_mode == .POINT {
|
||||||
apply_tool_to_trixel(hovered_trixel_x, hovered_trixel_y, hovered_trixel_z);
|
apply_tool_to_trixel(hovered_trixel_x, hovered_trixel_y, hovered_trixel_z);
|
||||||
}
|
}
|
||||||
|
if current_mode == .BRUSH {
|
||||||
|
is_in_radius :: (point : Vector3, radius: float) -> bool {
|
||||||
|
center : Vector3 = .{xx hovered_trixel_x, xx hovered_trixel_y, xx hovered_trixel_z};
|
||||||
|
return length(point - center) <= radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
for x: 0..15 {
|
||||||
|
for y: 0..15 {
|
||||||
|
for z: 0..15 {
|
||||||
|
if is_in_radius(.{xx x, xx y, xx z}, xx brush_radius) {
|
||||||
|
apply_tool_to_trixel(x,y,z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if current_mode == .AREA {
|
if current_mode == .AREA {
|
||||||
if area_active {
|
if area_active {
|
||||||
// Apply tool to all trixels in the area.
|
// Apply tool to all trixels in the area.
|
||||||
@ -164,6 +182,9 @@ draw_tool_tab :: (theme: *GR.Overall_Theme, area: GR.Rect) {
|
|||||||
if GR.button(r, "Brush (c-B)", *t_button_selectable(theme, current_mode == .BRUSH)) {
|
if GR.button(r, "Brush (c-B)", *t_button_selectable(theme, current_mode == .BRUSH)) {
|
||||||
current_mode = .BRUSH;
|
current_mode = .BRUSH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.y += r.h;
|
||||||
|
GR.slider(r, *brush_radius, 0, 12, 1, *theme.slider_theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_material_tab :: (theme: *GR.Overall_Theme, area: GR.Rect) {
|
draw_material_tab :: (theme: *GR.Overall_Theme, area: GR.Rect) {
|
||||||
@ -241,6 +262,7 @@ draw_trile :: () {
|
|||||||
hovered_trixel_x = x;
|
hovered_trixel_x = x;
|
||||||
hovered_trixel_y = y;
|
hovered_trixel_y = y;
|
||||||
hovered_trixel_z = z;
|
hovered_trixel_z = z;
|
||||||
|
print("%\n", hit.normal);
|
||||||
min_distance = hit.distance;
|
min_distance = hit.distance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -231,9 +231,9 @@ init_quads :: (quads: *Quads) { // NOTE: unsure about if this is correctly porte
|
|||||||
for side : trileSideValues {
|
for side : trileSideValues {
|
||||||
idx := side_to_quad_list_index(side);
|
idx := side_to_quad_list_index(side);
|
||||||
for i : 0..15 {
|
for i : 0..15 {
|
||||||
qlist := *quads[idx];
|
quadset : Quad_Set;
|
||||||
array_add(qlist, .{});
|
table_add(*quadset, .{.{16,16}, .{0,0}}, true);
|
||||||
table_add(qlist[i], .{.{16,16}, .{0,0}}, true);
|
array_add(*quads.*[idx], quadset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -258,12 +258,12 @@ change_perspective :: (x: *$T, y: *T, z: *T, side: Trile_Side) -> (*T,*T,*T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
quad2d_add_to_quads_3d :: (quads2d: *[..]Vector2, quads3d: *[..]Vector3, side: Trile_Side, depth: int, normals: *[..]float) {
|
quad2d_add_to_quads3d :: (quads2d: *[..]Vector2, quads3d: *[..]Vector3, side: Trile_Side, depth: int, normals: *[..]float) {
|
||||||
x, y, z : float;
|
x, y, z : float;
|
||||||
normal : [3]float;
|
normal : [3]float;
|
||||||
offset : float = 0.0;
|
offset : float = 0.0;
|
||||||
|
|
||||||
ux, uy, uz = change_perspective(*x, *y, *z, side);
|
ux, uy, uz := change_perspective(*x, *y, *z, side);
|
||||||
|
|
||||||
if side == {
|
if side == {
|
||||||
case Trile_Side.TOP;
|
case Trile_Side.TOP;
|
||||||
@ -314,51 +314,34 @@ quads_to_vecs :: (quads: *Quads, vecs: *[..]float, normals: *[..]float) {
|
|||||||
idx := side_to_quad_list_index(side);
|
idx := side_to_quad_list_index(side);
|
||||||
for 0..quads[idx].count-1 {
|
for 0..quads[idx].count-1 {
|
||||||
quads2d : [..]Vector2;
|
quads2d : [..]Vector2;
|
||||||
Quad_Set :: Table(Quad, bool, quad_hash, quad_comp);
|
table := quads.*[idx][it];
|
||||||
Quads :: [6][..]Quad_Set;
|
for k, v : table {
|
||||||
for quad : quads[idx][it] {
|
array_add(*quads2d, v.bottomLeft);
|
||||||
array_add(*quads2d, quad.bottomLeft);
|
array_add(*quads2d, .{v.bottomLeft.x, v.topRight.y});
|
||||||
array_add(*quads2d, .{quad.bottomLeft.x, quad.topRight.y});
|
array_add(*quads2d, v.topRight);
|
||||||
array_add(*quads2d, quad.topRight);
|
array_add(*quads2d, .{v.topRight.x, v.bottomLeft.y});
|
||||||
array_add(*quads2d, .{quad.topRight.x, quad.bottomLeft.y});
|
|
||||||
}
|
}
|
||||||
quad2_add_to_quads3d(*quads2d, *quads3d, side, it, normals);
|
quad2d_add_to_quads3d(*quads2d, *quads3d, side, it, normals);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for quad : quads3d {
|
||||||
|
array_add(vecs, quad.x);
|
||||||
|
array_add(vecs, quad.y);
|
||||||
|
array_add(vecs, quad.z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
a_is_inside_b :: (a: Quad, b: Quad) -> bool {
|
||||||
|
if (b.topRight.x >= a.topRight.x) && (b.topRight.y >= a.topRight.y) {
|
||||||
void quadsToVecs(Quads& quads, std::vector<float>& vecs, std::vector<float>& normals){
|
if (b.bottomLeft.x <= a.bottomLeft.x) && (b.bottomLeft.y <= a.bottomLeft.y) {
|
||||||
std::vector<Vector3> quads3d;
|
|
||||||
for(TrileSide side : TrileSideValues){
|
|
||||||
for(int i=0; i<quads[side].size(); i++){
|
|
||||||
std::vector<Vector2> quads2d;
|
|
||||||
for(Quad quad : quads[side][i]){
|
|
||||||
quads2d.push_back(quad.bottomLeft);
|
|
||||||
quads2d.push_back({quad.bottomLeft.x,quad.topRight.y});
|
|
||||||
quads2d.push_back(quad.topRight);
|
|
||||||
quads2d.push_back({quad.topRight.x,quad.bottomLeft.y});
|
|
||||||
}
|
|
||||||
quad2dAddToQuads3d(quads2d,quads3d,side,i,normals);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(Vector3 quad : quads3d) {
|
|
||||||
vecs.push_back(quad.x);
|
|
||||||
vecs.push_back(quad.y);
|
|
||||||
vecs.push_back(quad.z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isInsideOther(Quad a, Quad other){
|
|
||||||
if( (other.topRight.x >= a.topRight.x) && (other.topRight.y >= a.topRight.y)){
|
|
||||||
if( (other.bottomLeft.x <= a.bottomLeft.x) && (other.bottomLeft.y <= a.bottomLeft.y) ){
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
void removeQuad(Quad quad, std::set<Quad>& quadSet){
|
void removeQuad(Quad quad, std::set<Quad>& quadSet){
|
||||||
auto parentIt = quadSet.lower_bound(quad);
|
auto parentIt = quadSet.lower_bound(quad);
|
||||||
while(!isInsideOther(quad,*parentIt)){
|
while(!isInsideOther(quad,*parentIt)){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user