transparency first version
This commit is contained in:
parent
f0fa28bdd8
commit
66902df99c
14 changed files with 225 additions and 92 deletions
src/scene
|
@ -1,7 +1,6 @@
|
|||
use cgmath::Vector3;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashSet;
|
||||
use std::rc::Rc;
|
||||
|
||||
use std::time::Instant;
|
||||
|
@ -50,6 +49,14 @@ impl EmptyVolume {
|
|||
self.position[1] + self.size_y > pos[1] && pos[1] >= self.position[1] &&
|
||||
self.position[2] + self.size_z > pos[2] && pos[2] >= self.position[2]
|
||||
}
|
||||
|
||||
fn check_transparent(cube_result: Option<Cube>, transparent_color: &Vector3<f32>) -> bool {
|
||||
if let Some(c) = cube_result {
|
||||
return c.transparent && &c.color == transparent_color
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
// MARK: From Oct Tree
|
||||
pub fn from_oct_tree(tree: &OctTree<Cube>) -> (Vec<Rc<RefCell<EmptyVolume>>>, OctTree<Rc<RefCell<EmptyVolume>>>) {
|
||||
// todo: ppotentially use a child exist check while going through the oct tree to find some obvios starting empty volumes. Will still need to check for possible expansions though
|
||||
|
@ -64,8 +71,14 @@ impl EmptyVolume {
|
|||
for z_index in 0..tree.size {
|
||||
// check if there is a block at that position
|
||||
let query_result = tree.test_element(x_index, y_index, z_index);
|
||||
|
||||
if !query_result.0 {
|
||||
let mut transparent = false;
|
||||
let mut transparent_color = Vector3 {x: 0.0, y: 0.0, z: 0.0};
|
||||
if let Some(c) = query_result.3 {
|
||||
transparent = c.transparent;
|
||||
transparent_color = c.color;
|
||||
}
|
||||
if !query_result.0 || transparent {
|
||||
|
||||
//if not check that it is not already inside of a volume
|
||||
let mut contained = false;
|
||||
for volume in &volumes {
|
||||
|
@ -99,7 +112,7 @@ impl EmptyVolume {
|
|||
while z < z_size.max(1) && y < y_size.max(1) {
|
||||
let query_result = tree.test_element(x_index + x_size + 1, y_index + y, z_index + z);
|
||||
check_its += 1;
|
||||
grow &= !query_result.0 &&
|
||||
grow &= ((!query_result.0 && !transparent) || (transparent && EmptyVolume::check_transparent(query_result.3, &transparent_color))) &&
|
||||
neighbors.get_element(x_index + x_size + 1, y_index + y, z_index + z).is_none();
|
||||
|
||||
if query_result.1 > 1 {
|
||||
|
@ -146,7 +159,7 @@ impl EmptyVolume {
|
|||
while z < z_size.max(1) && x < x_size.max(1) {
|
||||
let query_result = tree.test_element(x_index + x, y_index + y_size + 1, z_index + z);
|
||||
check_its += 1;
|
||||
grow &= !query_result.0 &&
|
||||
grow &= ((!query_result.0 && !transparent) || (transparent && EmptyVolume::check_transparent(query_result.3, &transparent_color))) &&
|
||||
neighbors.get_element(x_index + x, y_index + y_size + 1, z_index + z).is_none();
|
||||
|
||||
if query_result.1 > 1 {
|
||||
|
@ -194,7 +207,7 @@ impl EmptyVolume {
|
|||
while y < y_size.max(1) && x < x_size.max(1) {
|
||||
let query_result = tree.test_element(x_index + x, y_index + y, z_index + z_size + 1);
|
||||
check_its += 1;
|
||||
grow &= !query_result.0 &&
|
||||
grow &= ((!query_result.0 && !transparent) || (transparent && EmptyVolume::check_transparent(query_result.3, &transparent_color))) &&
|
||||
neighbors.get_element(x_index + x, y_index + y, z_index + z_size + 1).is_none();
|
||||
|
||||
if query_result.1 > 1 {
|
||||
|
@ -683,12 +696,14 @@ impl EmptyVolume {
|
|||
for x in 0..self.size_x {
|
||||
for y in 0..self.size_y {
|
||||
let index = x * self.size_y + y;
|
||||
if self.color_bottom.len() == 0 {
|
||||
if self.color_bottom.len() <= index {
|
||||
continue;
|
||||
}
|
||||
if self.neighbor_bottom.len() > index {
|
||||
if let Some(_) = self.neighbor_bottom[index] {
|
||||
continue;
|
||||
if self.color_bottom[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
let quad = Quad {
|
||||
|
@ -707,12 +722,14 @@ impl EmptyVolume {
|
|||
for x in 0..self.size_x {
|
||||
for y in 0..self.size_y {
|
||||
let index = x * self.size_y + y;
|
||||
if self.color_top.len() == 0 {
|
||||
if self.color_top.len() <= 0 {
|
||||
continue;
|
||||
}
|
||||
if self.neighbor_top.len() > index {
|
||||
if let Some(_) = self.neighbor_top[index] {
|
||||
continue;
|
||||
if self.color_top[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
let quad = Quad {
|
||||
|
@ -732,12 +749,14 @@ impl EmptyVolume {
|
|||
for x in 0..self.size_x {
|
||||
for z in 0..self.size_z {
|
||||
let index = x * self.size_z + z;
|
||||
if self.color_front.len() == 0 {
|
||||
if self.color_front.len() <= 0 {
|
||||
continue;
|
||||
}
|
||||
if self.neighbor_front.len() > index {
|
||||
if let Some(_) = self.neighbor_front[index] {
|
||||
continue;
|
||||
if self.color_front[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
let quad = Quad {
|
||||
|
@ -757,12 +776,14 @@ impl EmptyVolume {
|
|||
for x in 0..self.size_x {
|
||||
for z in 0..self.size_z {
|
||||
let index = x * self.size_z + z;
|
||||
if self.color_back.len() == 0 {
|
||||
if self.color_back.len() <= 0 {
|
||||
continue;
|
||||
}
|
||||
if self.neighbor_back.len() > index {
|
||||
if let Some(_) = self.neighbor_back[index] {
|
||||
continue;
|
||||
if self.color_back[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
let quad = Quad {
|
||||
|
@ -782,12 +803,14 @@ impl EmptyVolume {
|
|||
for y in 0..self.size_y {
|
||||
for z in 0..self.size_z {
|
||||
let index = y * self.size_z + z;
|
||||
if self.color_left.len() == 0 {
|
||||
if self.color_left.len() <= 0 {
|
||||
continue;
|
||||
}
|
||||
if self.neighbor_left.len() > index {
|
||||
if let Some(_) = self.neighbor_left[index] {
|
||||
continue;
|
||||
if self.color_left[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
let quad = Quad {
|
||||
|
@ -807,12 +830,14 @@ impl EmptyVolume {
|
|||
for y in 0..self.size_y {
|
||||
for z in 0..self.size_z {
|
||||
let index = y * self.size_z + z;
|
||||
if self.color_right.len() == 0 {
|
||||
if self.color_right.len() <= 0 {
|
||||
continue;
|
||||
}
|
||||
if self.neighbor_right.len() > index {
|
||||
if let Some(_) = self.neighbor_right[index] {
|
||||
continue;
|
||||
if self.color_right[index] == (Vector3 {x: 0, y: 0, z: 0}) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
let quad = Quad {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue