position interpolation
This commit is contained in:
parent
f687405dbb
commit
4f31a4da34
3 changed files with 46 additions and 36 deletions
|
|
@ -10,8 +10,8 @@ modifier = {
|
|||
{ name="time_based" type="boolean" default=true }
|
||||
{ name="normalize_uvs" type="boolean" default=true }
|
||||
//{ name="interpolate_curves" type="boolean" default=true } //todo
|
||||
{ name="length" type="number" default=1 }
|
||||
{ name="subdivisions_length" type="number" default=30 }
|
||||
{ name="length" type="number" default=.2 }
|
||||
{ name="subdivisions_length" type="number" default=10 }
|
||||
{ name="subdivisions_width" type="number" default=5 }
|
||||
{ name="material" type="id32" editor="material" default="asset/flag"}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -159,8 +159,8 @@ import "luxe: world" for Block
|
|||
_edge_length = 100
|
||||
_time_based = true
|
||||
_normalize_uvs = true
|
||||
_length = 1
|
||||
_subdivisions_length = 30
|
||||
_length = 0.2
|
||||
_subdivisions_length = 10
|
||||
_subdivisions_width = 5
|
||||
_material = "asset/flag"
|
||||
} //new
|
||||
|
|
@ -271,12 +271,12 @@ import "luxe: world" for Block
|
|||
|
||||
|
||||
var length = instance["length"]
|
||||
if(length == null) length = 1
|
||||
if(length == null) length = 0.2
|
||||
out.write_float64(length)
|
||||
|
||||
|
||||
var subdivisions_length = instance["subdivisions_length"]
|
||||
if(subdivisions_length == null) subdivisions_length = 30
|
||||
if(subdivisions_length == null) subdivisions_length = 10
|
||||
out.write_float64(subdivisions_length)
|
||||
|
||||
|
||||
|
|
@ -332,14 +332,14 @@ import "luxe: world" for Block
|
|||
// length
|
||||
out.write_uint32(compiler.string.hash("length"))
|
||||
out.write_uint32(467038368) //type number
|
||||
var length_default = 1
|
||||
var length_default = 0.2
|
||||
out.write_float64(length_default)
|
||||
|
||||
|
||||
// subdivisions_length
|
||||
out.write_uint32(compiler.string.hash("subdivisions_length"))
|
||||
out.write_uint32(467038368) //type number
|
||||
var subdivisions_length_default = 30
|
||||
var subdivisions_length_default = 10
|
||||
out.write_float64(subdivisions_length_default)
|
||||
|
||||
|
||||
|
|
@ -394,8 +394,8 @@ import "luxe: world" for Block
|
|||
Block.add(_block, "edge_length", "number", 100)
|
||||
Block.add(_block, "time_based", "boolean", true)
|
||||
Block.add(_block, "normalize_uvs", "boolean", true)
|
||||
Block.add(_block, "length", "number", 1)
|
||||
Block.add(_block, "subdivisions_length", "number", 30)
|
||||
Block.add(_block, "length", "number", 0.2)
|
||||
Block.add(_block, "subdivisions_length", "number", 10)
|
||||
Block.add(_block, "subdivisions_width", "number", 5)
|
||||
Block.add(_block, "material", "id32", "asset/flag")
|
||||
Block.set_type(_block, "modifiers/trail/trail > data")
|
||||
|
|
|
|||
|
|
@ -262,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_length - 1) instance_data.points.dequeue()
|
||||
if(instance_data.points.count >= data.subdivisions_length) instance_data.points.dequeue()
|
||||
instance_data.points.enqueue(point)
|
||||
}
|
||||
instance_data.progress_since_last_point = dist
|
||||
|
|
@ -301,47 +301,57 @@ class TrailSystem is ModifierSystem {
|
|||
|
||||
var step = data.length / data.subdivisions_length
|
||||
|
||||
System.print(1 - instance_data.progress_since_last_point / step)
|
||||
|
||||
var point_index = -1
|
||||
while(true){
|
||||
point_index = point_index + 1
|
||||
if(point_index >= instance_data.points.count) break
|
||||
if(point_index >= instance_data.points.count - 1) break
|
||||
i = i + 1
|
||||
var p:Point = instance_data.points[point_index]
|
||||
|
||||
|
||||
var x = instance_data.points.count - i
|
||||
var p:Point = instance_data.points[point_index]
|
||||
var next:Point = instance_data.points[point_index + 1]
|
||||
|
||||
var to = p.pos
|
||||
var to_up = p.up
|
||||
|
||||
var from = to
|
||||
var from_up = to_up
|
||||
var from = next.pos
|
||||
var from_up = next.up
|
||||
|
||||
var t = instance_data.progress_since_last_point / step
|
||||
var pos_x = Math.lerp(from.x, to.x, t)
|
||||
var pos_y = Math.lerp(from.y, to.y, t)
|
||||
var pos_z = Math.lerp(from.z, to.z, t)
|
||||
var t = 1 - instance_data.progress_since_last_point / step
|
||||
|
||||
var pos = [
|
||||
Math.lerp(from.x, to.x, t),
|
||||
Math.lerp(from.y, to.y, t),
|
||||
Math.lerp(from.z, to.z, t)
|
||||
]
|
||||
|
||||
var up_x = Math.lerp(from_up.x, to_up.x, t)
|
||||
var up_y = Math.lerp(from_up.y, to_up.y, t)
|
||||
var up_z = Math.lerp(from_up.z, to_up.z, t)
|
||||
var up = [
|
||||
Math.lerp(from_up.x, to_up.x, t),
|
||||
Math.lerp(from_up.y, to_up.y, t),
|
||||
Math.lerp(from_up.z, to_up.z, t)
|
||||
]
|
||||
|
||||
Math.normalize(up)
|
||||
|
||||
|
||||
pos_x = to.x
|
||||
pos_y = to.y
|
||||
pos_z = to.z
|
||||
//pos_x = to.x
|
||||
//pos_y = to.y
|
||||
//pos_z = to.z
|
||||
|
||||
up_x = to_up.x
|
||||
up_y = to_up.y
|
||||
up_z = to_up.z
|
||||
//up_x = to_up.x
|
||||
//up_y = to_up.y
|
||||
//up_z = to_up.z
|
||||
|
||||
var x = instance_data.points.count + 1 - i
|
||||
for(y in 0...data.subdivisions_width){
|
||||
var t = y / (data.subdivisions_width-1)
|
||||
var offset_x = Math.lerp(-up_x, up_x, t)
|
||||
var offset_y = Math.lerp(-up_y, up_y, t)
|
||||
var offset_z = Math.lerp(-up_z, up_z, t)
|
||||
positions[x*4*data.subdivisions_width + y*4 + 0] = pos_x + offset_x * data.edge_length * 0.5
|
||||
positions[x*4*data.subdivisions_width + y*4 + 1] = pos_y + offset_y * data.edge_length * 0.5
|
||||
positions[x*4*data.subdivisions_width + y*4 + 2] = pos_z + offset_z * data.edge_length * 0.5
|
||||
var offset_x = Math.lerp(-up.x, up.x, t)
|
||||
var offset_y = Math.lerp(-up.y, up.y, t)
|
||||
var offset_z = Math.lerp(-up.z, up.z, t)
|
||||
positions[x*4*data.subdivisions_width + y*4 + 0] = pos.x + offset_x * data.edge_length * 0.5
|
||||
positions[x*4*data.subdivisions_width + y*4 + 1] = pos.y + offset_y * data.edge_length * 0.5
|
||||
positions[x*4*data.subdivisions_width + y*4 + 2] = pos.z + offset_z * data.edge_length * 0.5
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue