time based trails and width subdivisions and default material
This commit is contained in:
parent
3c95c9e5f3
commit
0a3a2c4477
7 changed files with 198 additions and 120 deletions
4
asset/flag.image.lx
Normal file
4
asset/flag.image.lx
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
image = {
|
||||
source = "asset/flag.png"
|
||||
generate_mipmaps_at_load = false
|
||||
}
|
||||
8
asset/flag.material.lx
Normal file
8
asset/flag.material.lx
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
material = {
|
||||
basis = "luxe: material_basis/sprite"
|
||||
inputs = {
|
||||
sprite.image = "asset/flag"
|
||||
sprite.color = [1 1 1 1]
|
||||
sprite.uv = [1 0 0 1]
|
||||
}
|
||||
}
|
||||
BIN
asset/flag.png
Normal file
BIN
asset/flag.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 839 B |
|
|
@ -46,7 +46,7 @@ class Game is Ready {
|
|||
}
|
||||
|
||||
// app.color.r = app.color.g = app.color.b = (IO.timestamp()/20 % 1)
|
||||
|
||||
System.print(1/delta)
|
||||
} //tick
|
||||
|
||||
destroy() {
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@ modifier = {
|
|||
fields = [
|
||||
{ name="edge_length" type="number" default=100 }
|
||||
{ name="time_based" type="boolean" default=false }
|
||||
{ name="length" type="number" default=100 }
|
||||
{ name="subdivisions" type="number" default=20 }
|
||||
{ name="material" type="id32" editor="material" default="luxe: material/solid"}
|
||||
{ name="length" type="number" default=500 }
|
||||
{ name="subdivisions_length" type="number" default=1000 }
|
||||
{ name="subdivisions_width" type="number" default=10 }
|
||||
{ name="material" type="id32" editor="material" default="asset/flag"}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -158,9 +158,10 @@ import "luxe: world" for Block
|
|||
construct new() {
|
||||
_edge_length = 100
|
||||
_time_based = false
|
||||
_length = 100
|
||||
_subdivisions = 20
|
||||
_material = "luxe: material/solid"
|
||||
_length = 500
|
||||
_subdivisions_length = 1000
|
||||
_subdivisions_width = 10
|
||||
_material = "asset/flag"
|
||||
} //new
|
||||
|
||||
edge_length { _edge_length }
|
||||
|
|
@ -172,8 +173,11 @@ import "luxe: world" for Block
|
|||
length { _length }
|
||||
length=(vvv) { _length = vvv }
|
||||
|
||||
subdivisions { _subdivisions }
|
||||
subdivisions=(vvv) { _subdivisions = vvv }
|
||||
subdivisions_length { _subdivisions_length }
|
||||
subdivisions_length=(vvv) { _subdivisions_length = vvv }
|
||||
|
||||
subdivisions_width { _subdivisions_width }
|
||||
subdivisions_width=(vvv) { _subdivisions_width = vvv }
|
||||
|
||||
material { _material }
|
||||
material=(vvv) { _material = vvv }
|
||||
|
|
@ -197,7 +201,9 @@ import "luxe: world" for Block
|
|||
|
||||
size = size + 8 // length
|
||||
|
||||
size = size + 8 // subdivisions
|
||||
size = size + 8 // subdivisions_length
|
||||
|
||||
size = size + 8 // subdivisions_width
|
||||
|
||||
size = size + 4 // material
|
||||
|
||||
|
|
@ -216,7 +222,8 @@ import "luxe: world" for Block
|
|||
"edge_length": false,
|
||||
"time_based": false,
|
||||
"length": false,
|
||||
"subdivisions": false,
|
||||
"subdivisions_length": false,
|
||||
"subdivisions_width": false,
|
||||
"material": false,
|
||||
}
|
||||
for(element in elements) {
|
||||
|
|
@ -252,17 +259,22 @@ import "luxe: world" for Block
|
|||
|
||||
|
||||
var length = instance["length"]
|
||||
if(length == null) length = 100
|
||||
if(length == null) length = 500
|
||||
out.write_float64(length)
|
||||
|
||||
|
||||
var subdivisions = instance["subdivisions"]
|
||||
if(subdivisions == null) subdivisions = 20
|
||||
out.write_float64(subdivisions)
|
||||
var subdivisions_length = instance["subdivisions_length"]
|
||||
if(subdivisions_length == null) subdivisions_length = 1000
|
||||
out.write_float64(subdivisions_length)
|
||||
|
||||
|
||||
var subdivisions_width = instance["subdivisions_width"]
|
||||
if(subdivisions_width == null) subdivisions_width = 10
|
||||
out.write_float64(subdivisions_width)
|
||||
|
||||
|
||||
var material = instance["material"]
|
||||
if(material == null) material = "luxe: material/solid"
|
||||
if(material == null) material = "asset/flag"
|
||||
out.write_uint32((material && material != "") ? compiler.string.hash(material) : 0)
|
||||
|
||||
|
||||
|
|
@ -272,7 +284,7 @@ import "luxe: world" for Block
|
|||
|
||||
bytes_count_block() {
|
||||
|
||||
return 80
|
||||
return 96
|
||||
|
||||
} //bytes_count_block
|
||||
|
||||
|
|
@ -282,7 +294,7 @@ import "luxe: world" for Block
|
|||
out.write_uint32(compiler.string.hash("modifiers/trail/trail > data"))
|
||||
|
||||
//fields count
|
||||
out.write_int32(5)
|
||||
out.write_int32(6)
|
||||
|
||||
// edge_length
|
||||
out.write_uint32(compiler.string.hash("edge_length"))
|
||||
|
|
@ -301,21 +313,28 @@ import "luxe: world" for Block
|
|||
// length
|
||||
out.write_uint32(compiler.string.hash("length"))
|
||||
out.write_uint32(467038368) //type number
|
||||
var length_default = 100
|
||||
var length_default = 500
|
||||
out.write_float64(length_default)
|
||||
|
||||
|
||||
// subdivisions
|
||||
out.write_uint32(compiler.string.hash("subdivisions"))
|
||||
// subdivisions_length
|
||||
out.write_uint32(compiler.string.hash("subdivisions_length"))
|
||||
out.write_uint32(467038368) //type number
|
||||
var subdivisions_default = 20
|
||||
out.write_float64(subdivisions_default)
|
||||
var subdivisions_length_default = 1000
|
||||
out.write_float64(subdivisions_length_default)
|
||||
|
||||
|
||||
// subdivisions_width
|
||||
out.write_uint32(compiler.string.hash("subdivisions_width"))
|
||||
out.write_uint32(467038368) //type number
|
||||
var subdivisions_width_default = 10
|
||||
out.write_float64(subdivisions_width_default)
|
||||
|
||||
|
||||
// material
|
||||
out.write_uint32(compiler.string.hash("material"))
|
||||
out.write_uint32(2729592961) //type id32
|
||||
var material_default = "luxe: material/solid"
|
||||
var material_default = "asset/flag"
|
||||
out.write_uint32((material_default && material_default != "") ? compiler.string.hash(material_default) : 0)
|
||||
|
||||
|
||||
|
|
@ -355,9 +374,10 @@ import "luxe: world" for Block
|
|||
_inst = _inst_type.new(_block, 0)
|
||||
Block.add(_block, "edge_length", "number", 100)
|
||||
Block.add(_block, "time_based", "boolean", false)
|
||||
Block.add(_block, "length", "number", 100)
|
||||
Block.add(_block, "subdivisions", "number", 20)
|
||||
Block.add(_block, "material", "id32", "luxe: material/solid")
|
||||
Block.add(_block, "length", "number", 500)
|
||||
Block.add(_block, "subdivisions_length", "number", 1000)
|
||||
Block.add(_block, "subdivisions_width", "number", 10)
|
||||
Block.add(_block, "material", "id32", "asset/flag")
|
||||
Block.set_type(_block, "modifiers/trail/trail > data")
|
||||
} //new
|
||||
|
||||
|
|
@ -370,8 +390,10 @@ import "luxe: world" for Block
|
|||
time_based=(v) { Block.set(_block, "time_based", _slot, v) }
|
||||
length { Block.get(_block, "length", _slot) }
|
||||
length=(v) { Block.set(_block, "length", _slot, v) }
|
||||
subdivisions { Block.get(_block, "subdivisions", _slot) }
|
||||
subdivisions=(v) { Block.set(_block, "subdivisions", _slot, v) }
|
||||
subdivisions_length { Block.get(_block, "subdivisions_length", _slot) }
|
||||
subdivisions_length=(v) { Block.set(_block, "subdivisions_length", _slot, v) }
|
||||
subdivisions_width { Block.get(_block, "subdivisions_width", _slot) }
|
||||
subdivisions_width=(v) { Block.set(_block, "subdivisions_width", _slot, v) }
|
||||
material { Block.get(_block, "material", _slot) }
|
||||
material=(v) { Block.set(_block, "material", _slot, v) }
|
||||
slot { _slot }
|
||||
|
|
|
|||
|
|
@ -90,10 +90,16 @@ class TrailSystem is ModifierSystem {
|
|||
edge_debug.thickness = 2
|
||||
edge_debug.cap = LineCap.round
|
||||
_debug_edge_style = edge_debug
|
||||
|
||||
var path_debug = PathStyle.new()
|
||||
path_debug.color = [1, 0, 0, 1]
|
||||
path_debug.thickness = 1
|
||||
_debug_path_style = path_debug
|
||||
|
||||
var mesh_debug = PathStyle.new()
|
||||
mesh_debug.color = [0, 0, 1, 1]
|
||||
mesh_debug.thickness = 0.5
|
||||
_debug_mesh_style = mesh_debug
|
||||
}
|
||||
|
||||
reset(entity: Entity){
|
||||
|
|
@ -107,89 +113,81 @@ class TrailSystem is ModifierSystem {
|
|||
attach(entity, data: ModifierData) {
|
||||
var material_id = Strings.get(data.material)
|
||||
var material = Assets.material(material_id)
|
||||
var index_buffer = create_index_buffer(data.subdivisions)
|
||||
var geo = Geometry.create(Primitive.triangle, material, (data.subdivisions - 1) * 6, IndexType.u16, index_buffer)
|
||||
var pos_buffer = create_position_buffer(data.edge_length, data.length, data.subdivisions)
|
||||
|
||||
var index_buffer = create_index_buffer(data.subdivisions_length, data.subdivisions_width)
|
||||
var geo = Geometry.create(Primitive.triangle, material, (data.subdivisions_length - 1) * 6, IndexType.u16, index_buffer)
|
||||
|
||||
var pos_buffer = create_position_buffer(data.edge_length, data.length, data.subdivisions_length, data.subdivisions_width)
|
||||
Geometry.set_vertex_buffer(geo, 0, pos_buffer)
|
||||
var color_buffer = create_color_buffer(data.edge_length, data.length, data.subdivisions)
|
||||
|
||||
var color_buffer = create_color_buffer(data.subdivisions_length, data.subdivisions_width)
|
||||
Geometry.set_vertex_buffer(geo, 1, color_buffer)
|
||||
var uv_buffer = create_uv_buffer(data.edge_length, data.length, data.subdivisions)
|
||||
|
||||
var uv_buffer = create_uv_buffer(data.subdivisions_length, data.subdivisions_width)
|
||||
Geometry.set_vertex_buffer(geo, 2, uv_buffer)
|
||||
var identity = Floats.new(16)
|
||||
identity.transform(0, 0, 0, 0, 0, 0, 1, 1, 1)
|
||||
Geometry.set_world_matrix(geo, identity)
|
||||
|
||||
World.render_set_add(_world, geo, entity)
|
||||
|
||||
_instance_data[entity] = TrailData.new(geo, index_buffer, pos_buffer, color_buffer, uv_buffer)
|
||||
}
|
||||
|
||||
create_position_buffer(height: Num, length: Num, subdivs: Num): VertexBuffer{
|
||||
var raw = Floats.new(4 * 2 * subdivs)
|
||||
for(i in 0...subdivs){
|
||||
var x = length * i / (subdivs - 1)
|
||||
raw[i*2*4+0] = x
|
||||
raw[i*2*4+1] = 0
|
||||
raw[i*2*4+2] = 0
|
||||
raw[i*2*4+3] = 1
|
||||
create_position_buffer(height: Num, length: Num, subdivs_len: Num, subdivs_width: Num): VertexBuffer{
|
||||
var raw = Floats.new(4 * subdivs_width * subdivs_len)
|
||||
return Render.create_vertex_buffer(raw, raw.length)
|
||||
}
|
||||
|
||||
raw[i*2*4+4] = x
|
||||
raw[i*2*4+5] = height
|
||||
raw[i*2*4+6] = 0
|
||||
raw[i*2*4+7] = 1
|
||||
create_color_buffer(subdivs_len: Num, subdivs_width: Num): VertexBuffer{
|
||||
var raw = Floats.new(4 * subdivs_width * subdivs_len)
|
||||
for(i in 0...subdivs_len){
|
||||
for(ii in 0...subdivs_width){
|
||||
raw[i*subdivs_width*4 + ii*4 + 0] = 1
|
||||
raw[i*subdivs_width*4 + ii*4 + 1] = 1
|
||||
raw[i*subdivs_width*4 + ii*4 + 2] = 1
|
||||
raw[i*subdivs_width*4 + ii*4 + 3] = 1
|
||||
}
|
||||
}
|
||||
//var arr = (0...(raw.size/4)).map{|i|"[%(raw[i*4]), %(raw[i*4+1]), %(raw[i*4+2])]"}.join("\n")
|
||||
//System.print(arr)
|
||||
return Render.create_vertex_buffer(raw, raw.length)
|
||||
}
|
||||
|
||||
create_color_buffer(height: Num, length: Num, subdivs: Num): VertexBuffer{
|
||||
var raw = Floats.new(4 * 2 * subdivs)
|
||||
for(i in 0...subdivs){
|
||||
var x = length * i / (subdivs - 1)
|
||||
raw[i*2*4+0] = 1
|
||||
raw[i*2*4+1] = 1
|
||||
raw[i*2*4+2] = 1
|
||||
raw[i*2*4+3] = 1
|
||||
|
||||
raw[i*2*4+4] = 1
|
||||
raw[i*2*4+5] = 1
|
||||
raw[i*2*4+6] = 1
|
||||
raw[i*2*4+7] = 1
|
||||
}
|
||||
//var arr = (0...(raw.size/4)).map{|i|"[%(raw[i*4]), %(raw[i*4+1]), %(raw[i*4+2])]"}.join("\n")
|
||||
//System.print(arr)
|
||||
return Render.create_vertex_buffer(raw, raw.length)
|
||||
}
|
||||
|
||||
create_uv_buffer(height: Num, length: Num, subdivs: Num): VertexBuffer{
|
||||
var raw = Floats.new(2 * 2 * subdivs)
|
||||
for(i in 0...subdivs){
|
||||
var x = i / (subdivs - 1)
|
||||
raw[i*2*2+0] = x
|
||||
raw[i*2*2+1] = 1
|
||||
|
||||
raw[i*2*2+2] = x
|
||||
raw[i*2*2+3] = 0
|
||||
create_uv_buffer(subdivs_len: Num, subdivs_width: Num): VertexBuffer{
|
||||
var raw = Floats.new(2 * subdivs_width * subdivs_len)
|
||||
for(i in 0...subdivs_len){
|
||||
var x = i / (subdivs_len - 1)
|
||||
for(ii in 0...subdivs_width){
|
||||
var y = ii / (subdivs_width - 1)
|
||||
raw[i*2*subdivs_width + ii*2 + 0] = x
|
||||
raw[i*2*subdivs_width + ii*2 + 1] = y
|
||||
}
|
||||
}
|
||||
//var arr = (0...(raw.size/2)).map{|i|"[%(raw[i*2]), %(raw[i*2+1])]"}.join("\n")
|
||||
//System.print(arr)
|
||||
return Render.create_vertex_buffer(raw, raw.length)
|
||||
}
|
||||
|
||||
create_index_buffer(subdivs: Num): IndexBuffer{
|
||||
var index_count = (subdivs - 1) * 6
|
||||
create_index_buffer(subdivs_len: Num, subdivs_width: Num): IndexBuffer{
|
||||
var rows = subdivs_len - 1
|
||||
var cols = subdivs_width-1
|
||||
var index_count = rows * cols * 6
|
||||
var raw = Uint16.new(index_count)
|
||||
for(i in 0...(subdivs-1)){
|
||||
//first triangle
|
||||
raw[i*6+0] = i * 2 + 0
|
||||
raw[i*6+1] = i * 2 + 2
|
||||
raw[i*6+2] = i * 2 + 1
|
||||
for(i in 0...rows){
|
||||
for(ii in 0...cols){
|
||||
//System.print("x: %(i) | y:%(ii)")
|
||||
//first triangle
|
||||
raw[i*6*cols + ii*6 + 0] = i * (cols+1) + ii + 0
|
||||
raw[i*6*cols + ii*6 + 1] = i * (cols+1) + ii + cols+1
|
||||
raw[i*6*cols + ii*6 + 2] = i * (cols+1) + ii + 1
|
||||
//System.print("(%(i*6*cols + ii*6 + 0), %(i*6*cols + ii*6 + 1), %(i*6*cols + ii*6 + 2))")
|
||||
//System.print("[%(i * (cols+1) + ii + 0), %(i * (cols+1) + ii + cols+1), %(i * (cols+1) + ii + 1)]")
|
||||
|
||||
//second triangle
|
||||
raw[i*6+3] = i * 2 + 1
|
||||
raw[i*6+4] = i * 2 + 2
|
||||
raw[i*6+5] = i * 2 + 3
|
||||
//second triangle
|
||||
raw[i*6*cols + ii*6 + 3] = i * (cols+1) + ii + 1
|
||||
raw[i*6*cols + ii*6 + 4] = i * (cols+1) + ii + cols+1
|
||||
raw[i*6*cols + ii*6 + 5] = i * (cols+1) + ii + cols+2
|
||||
//System.print("(%(i*6*cols + ii*6 + 3), %(i*6*cols + ii*6 + 4), %(i*6*cols + ii*6 + 5))")
|
||||
//System.print("[%(i * (cols+1) + ii + 1), %(i * (cols+1) + ii + cols+1), %(i * (cols+1) + ii + cols+2)]")
|
||||
}
|
||||
}
|
||||
//var arr = (0...(raw.length/(3*4))).map{|i|"[%(raw[i*3]), %(raw[i*3+1]), %(raw[i*3+2])]"}.join("\n")
|
||||
//System.print(arr)
|
||||
|
|
@ -203,15 +201,15 @@ class TrailSystem is ModifierSystem {
|
|||
|
||||
tick(delta) {
|
||||
//System.print("positions")
|
||||
record_positions()
|
||||
record_positions(delta)
|
||||
//System.print("buffers")
|
||||
update_buffers()
|
||||
//System.print("debug")
|
||||
debug_draw()
|
||||
//debug_draw()
|
||||
//System.print("end")
|
||||
} //tick
|
||||
|
||||
record_positions(){
|
||||
record_positions(delta: Num){
|
||||
each{|entity, data: ModifierData|
|
||||
if(!Transform.has(entity)) return
|
||||
|
||||
|
|
@ -223,22 +221,34 @@ class TrailSystem is ModifierSystem {
|
|||
var prev_up = instance_data.previous_up || up
|
||||
|
||||
var dist = instance_data.progress_since_last_point
|
||||
var diff = Math.dist(pos, prev_pos)
|
||||
var diff:Num
|
||||
if(data.time_based){
|
||||
diff = delta
|
||||
} else {
|
||||
diff = Math.dist(pos, prev_pos)
|
||||
}
|
||||
if(diff > data.length){
|
||||
var dir = [prev_pos.x - pos.x, prev_pos.y - pos.y, prev_pos.z - pos.z]
|
||||
Math.normalize(dir)
|
||||
dir.x = dir.x * data.length
|
||||
dir.y = dir.y * data.length
|
||||
dir.z = dir.z * data.length
|
||||
|
||||
prev_pos.x = pos.x + dir.x
|
||||
prev_pos.y = pos.y + dir.y
|
||||
prev_pos.z = pos.z + dir.z
|
||||
|
||||
if(data.time_based){
|
||||
var t = data.length / diff
|
||||
prev_pos.x = Math.lerp(pos.x, prev_pos.x, t)
|
||||
prev_pos.y = Math.lerp(pos.y, prev_pos.y, t)
|
||||
prev_pos.z = Math.lerp(pos.z, prev_pos.z, t)
|
||||
} else {
|
||||
var dir = [prev_pos.x - pos.x, prev_pos.y - pos.y, prev_pos.z - pos.z]
|
||||
Math.normalize(dir)
|
||||
|
||||
dir.x = dir.x * data.length
|
||||
dir.y = dir.y * data.length
|
||||
dir.z = dir.z * data.length
|
||||
|
||||
prev_pos.x = pos.x + dir.x
|
||||
prev_pos.y = pos.y + dir.y
|
||||
prev_pos.z = pos.z + dir.z
|
||||
}
|
||||
diff = data.length
|
||||
}
|
||||
dist = dist + diff
|
||||
var step = data.length / data.subdivisions
|
||||
var step = data.length / data.subdivisions_length
|
||||
while(dist > step){
|
||||
dist = dist - step
|
||||
var t = 1 - dist / diff
|
||||
|
|
@ -252,7 +262,7 @@ class TrailSystem is ModifierSystem {
|
|||
Math.lerp(prev_up.z, up.z, t)
|
||||
])
|
||||
Math.normalize(point.up)
|
||||
if(instance_data.points.count >= data.subdivisions - 1) instance_data.points.dequeue()
|
||||
if(instance_data.points.count >= data.subdivisions_length - 1) instance_data.points.dequeue()
|
||||
instance_data.points.enqueue(point)
|
||||
}
|
||||
instance_data.progress_since_last_point = dist
|
||||
|
|
@ -272,30 +282,34 @@ class TrailSystem is ModifierSystem {
|
|||
var i = -1
|
||||
for(p in instance_data.points){
|
||||
i = i + 1
|
||||
positions[i * 8 + 0] = p.pos.x - p.up.x * data.edge_length * 0.5
|
||||
positions[i * 8 + 1] = p.pos.y - p.up.y * data.edge_length * 0.5
|
||||
positions[i * 8 + 2] = p.pos.z - p.up.z * data.edge_length * 0.5
|
||||
|
||||
positions[i * 8 + 4] = p.pos.x + p.up.x * data.edge_length * 0.5
|
||||
positions[i * 8 + 5] = p.pos.y + p.up.y * data.edge_length * 0.5
|
||||
positions[i * 8 + 6] = p.pos.z + p.up.z * data.edge_length * 0.5
|
||||
for(ii in 0...data.subdivisions_width){
|
||||
var t = ii / (data.subdivisions_width-1)
|
||||
var offset_x = Math.lerp(-p.up.x, p.up.x, t)
|
||||
var offset_y = Math.lerp(-p.up.y, p.up.y, t)
|
||||
var offset_z = Math.lerp(-p.up.z, p.up.z, t)
|
||||
positions[i*4*data.subdivisions_width + ii*4 + 0] = p.pos.x + offset_x * data.edge_length * 0.5
|
||||
positions[i*4*data.subdivisions_width + ii*4 + 1] = p.pos.y + offset_y * data.edge_length * 0.5
|
||||
positions[i*4*data.subdivisions_width + ii*4 + 2] = p.pos.z + offset_z * data.edge_length * 0.5
|
||||
}
|
||||
}
|
||||
if(Transform.has(entity)){
|
||||
i = i + 1
|
||||
|
||||
|
||||
var start = Transform.local_point_to_world(entity, 0, data.edge_length * -0.5, 0)
|
||||
var end = Transform.local_point_to_world(entity, 0, data.edge_length * 0.5, 0)
|
||||
|
||||
positions[i * 8 + 0] = start.x
|
||||
positions[i * 8 + 1] = start.y
|
||||
positions[i * 8 + 2] = start.z
|
||||
|
||||
positions[i * 8 + 4] = end.x
|
||||
positions[i * 8 + 5] = end.y
|
||||
positions[i * 8 + 6] = end.z
|
||||
for(ii in 0...data.subdivisions_width){
|
||||
var t = ii / (data.subdivisions_width-1)
|
||||
var pos_x = Math.lerp(start.x, end.x, t)
|
||||
var pos_y = Math.lerp(start.y, end.y, t)
|
||||
var pos_z = Math.lerp(start.z, end.z, t)
|
||||
positions[i*4*data.subdivisions_width + ii*4 + 0] = pos_x
|
||||
positions[i*4*data.subdivisions_width + ii*4 + 1] = pos_y
|
||||
positions[i*4*data.subdivisions_width + ii*4 + 2] = pos_z
|
||||
}
|
||||
}
|
||||
Render.vertex_buffer_replace(instance_data.position_buffer, positions, positions.length)
|
||||
Geometry.set_vert_count(instance_data.geometry, i.max(0) * 6)
|
||||
Geometry.set_vert_count(instance_data.geometry, i.max(0) * 6 * (data.subdivisions_width-1))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -312,9 +326,38 @@ class TrailSystem is ModifierSystem {
|
|||
Draw.line(_draw, start.x, start.y, end.x, end.y, depth, _debug_edge_style)
|
||||
|
||||
var instance_data: TrailData = _instance_data[entity]
|
||||
|
||||
if(instance_data.points.count > 1){
|
||||
Draw.path3D(_draw, instance_data.points.map{|p:Point|p.pos}.toList, _debug_path_style, false)
|
||||
}
|
||||
|
||||
instance_data.points.each{|point: Point|
|
||||
var from_x = point.pos.x + point.up.x * data.edge_length * 0.5
|
||||
var from_y = point.pos.y + point.up.y * data.edge_length * 0.5
|
||||
var from_z = point.pos.x + point.up.x * data.edge_length * 0.5
|
||||
|
||||
var to_x = point.pos.x - point.up.x * data.edge_length * 0.5
|
||||
var to_y = point.pos.y - point.up.y * data.edge_length * 0.5
|
||||
var to_z = point.pos.z - point.up.z * data.edge_length * 0.5
|
||||
|
||||
Draw.path3D(_draw, [[from_x, from_y, from_z], [to_x, to_y, to_z]], _debug_path_style, false)
|
||||
}
|
||||
|
||||
var positions = Floats.new(Render.vertex_buffer_get_size(instance_data.position_buffer) / 4)
|
||||
Render.vertex_buffer_get_data(instance_data.position_buffer, positions, positions.size * 4, 0)
|
||||
var indices = Uint16.new(Render.index_buffer_get_size(instance_data.index_buffer) / 2)
|
||||
Render.index_buffer_get_data(instance_data.index_buffer, indices, indices.length, 0)
|
||||
for(i in 0...(Geometry.get_vert_count(instance_data.geometry) / 3)){
|
||||
var i1 = indices[i * 3 + 0]
|
||||
var i2 = indices[i * 3 + 1]
|
||||
var i3 = indices[i * 3 + 2]
|
||||
|
||||
var v1 = [positions[i1 * 4 + 0], positions[i1 * 4 + 1], positions[i1 * 4 + 2]]
|
||||
var v2 = [positions[i2 * 4 + 0], positions[i2 * 4 + 1], positions[i2 * 4 + 2]]
|
||||
var v3 = [positions[i3 * 4 + 0], positions[i3 * 4 + 1], positions[i3 * 4 + 2]]
|
||||
|
||||
Draw.path3D(_draw, [v1, v2, v3], _debug_mesh_style, true)
|
||||
}
|
||||
}
|
||||
Draw.commit(_draw)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue