Improve up axis handling
This commit is contained in:
@@ -434,6 +434,7 @@ class Importer {
|
||||
|
||||
static function importFbx(path:String) {
|
||||
iron.data.Data.getBlob(path, function(b:kha.Blob) {
|
||||
iron.format.fbx.FbxParser.parseTransform = UITrait.inst.parseTransform;
|
||||
var obj = new iron.format.fbx.FbxParser(b);
|
||||
makeMesh(obj, path);
|
||||
while (obj.next()) {
|
||||
|
||||
@@ -774,35 +774,35 @@ class MaterialBuilder {
|
||||
return con_mesh;
|
||||
}
|
||||
|
||||
public static function make_depth(data:CyclesShaderData, matcon:TMaterialContext):CyclesShaderContext {
|
||||
var context_id = 'depth';
|
||||
var con_depth:CyclesShaderContext = data.add_context({
|
||||
name: context_id,
|
||||
depth_write: true,
|
||||
compare_mode: 'less',
|
||||
cull_mode: 'clockwise',
|
||||
color_writes_red: [false],
|
||||
color_writes_green: [false],
|
||||
color_writes_blue: [false],
|
||||
color_writes_alpha: [false],
|
||||
vertex_elements: [{name: "pos", data: 'short4norm'}]
|
||||
});
|
||||
// public static function make_depth(data:CyclesShaderData, matcon:TMaterialContext):CyclesShaderContext {
|
||||
// var context_id = 'depth';
|
||||
// var con_depth:CyclesShaderContext = data.add_context({
|
||||
// name: context_id,
|
||||
// depth_write: true,
|
||||
// compare_mode: 'less',
|
||||
// cull_mode: 'clockwise',
|
||||
// color_writes_red: [false],
|
||||
// color_writes_green: [false],
|
||||
// color_writes_blue: [false],
|
||||
// color_writes_alpha: [false],
|
||||
// vertex_elements: [{name: "pos", data: 'short4norm'}]
|
||||
// });
|
||||
|
||||
var vert = con_depth.make_vert();
|
||||
var frag = con_depth.make_frag();
|
||||
// var vert = con_depth.make_vert();
|
||||
// var frag = con_depth.make_frag();
|
||||
|
||||
frag.ins = vert.outs;
|
||||
// frag.ins = vert.outs;
|
||||
|
||||
vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrix');
|
||||
vert.write('gl_Position = mul(vec4(pos.xyz, 1.0), WVP);');
|
||||
// vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrix');
|
||||
// vert.write('gl_Position = mul(vec4(pos.xyz, 1.0), WVP);');
|
||||
|
||||
// Cycles.finalize(con_depth);
|
||||
con_depth.data.shader_from_source = true;
|
||||
con_depth.data.vertex_shader = vert.get();
|
||||
con_depth.data.fragment_shader = frag.get();
|
||||
// // Cycles.finalize(con_depth);
|
||||
// con_depth.data.shader_from_source = true;
|
||||
// con_depth.data.vertex_shader = vert.get();
|
||||
// con_depth.data.fragment_shader = frag.get();
|
||||
|
||||
return con_depth;
|
||||
}
|
||||
// return con_depth;
|
||||
// }
|
||||
|
||||
public static function make_particle(data:CyclesShaderData):CyclesShaderContext {
|
||||
var context_id = 'mesh';
|
||||
|
||||
@@ -173,18 +173,18 @@ class MaterialParser {
|
||||
m.contexts.push(self);
|
||||
});
|
||||
|
||||
var dcon = MaterialBuilder.make_depth(_sd, _matcon);
|
||||
var dcdata = dcon.data;
|
||||
// from_source is synchronous..
|
||||
var dsc = new ShaderContext(dcdata, function(sc:ShaderContext){});
|
||||
m.shader.contexts.push(dsc);
|
||||
var dmatcon:TMaterialContext = {
|
||||
name: "depth"
|
||||
}
|
||||
m.raw.contexts.push(dmatcon);
|
||||
new MaterialContext(dmatcon, function(self:MaterialContext) {
|
||||
m.contexts.push(self);
|
||||
});
|
||||
// var dcon = MaterialBuilder.make_depth(_sd, _matcon);
|
||||
// var dcdata = dcon.data;
|
||||
// // from_source is synchronous..
|
||||
// var dsc = new ShaderContext(dcdata, function(sc:ShaderContext){});
|
||||
// m.shader.contexts.push(dsc);
|
||||
// var dmatcon:TMaterialContext = {
|
||||
// name: "depth"
|
||||
// }
|
||||
// m.raw.contexts.push(dmatcon);
|
||||
// new MaterialContext(dmatcon, function(self:MaterialContext) {
|
||||
// m.contexts.push(self);
|
||||
// });
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
@@ -115,6 +115,7 @@ class UITrait extends iron.Trait {
|
||||
public var isSubs = false;
|
||||
public var isSubsSpace = 0;
|
||||
public var isUdim = false;
|
||||
public var parseTransform = false;
|
||||
public var hwnd = Id.handle();
|
||||
public var hwnd1 = Id.handle();
|
||||
public var hwnd2 = Id.handle();
|
||||
@@ -2203,9 +2204,11 @@ class UITrait extends iron.Trait {
|
||||
if (ui.button("Import")) importMesh();
|
||||
if (ui.isHovered) ui.tooltip("Import mesh file (Ctrl + Shift + I)");
|
||||
|
||||
isUdim = ui.check(Id.handle({selected: isUdim}), "UDIM import");
|
||||
isUdim = ui.check(Id.handle({selected: isUdim}), "UDIM Import");
|
||||
if (ui.isHovered) ui.tooltip("Split mesh per UDIM tile");
|
||||
|
||||
parseTransform = ui.check(Id.handle({selected: parseTransform}), "Parse Transforms");
|
||||
|
||||
if (ui.panel(Id.handle({selected: false}), "Scene", 0, true)) {
|
||||
var i = 0;
|
||||
function drawList(h:Handle, o:MeshObject) {
|
||||
@@ -2241,16 +2244,20 @@ class UITrait extends iron.Trait {
|
||||
ddirty = 2;
|
||||
}
|
||||
|
||||
ui.row([1/2, 1/2]);
|
||||
var upHandle = Id.handle();
|
||||
var lastUp = upHandle.position;
|
||||
// TODO: Turn into axis rotation instead
|
||||
var axisUp = ui.combo(upHandle, ["Z", "-Z", "Y", "-Y"], "Up Axis", true);
|
||||
if (upHandle.changed && axisUp != lastUp) {
|
||||
MeshUtil.switchUpAxis(axisUp);
|
||||
ui.row([1/3, 1/3, 1/3]);
|
||||
if (ui.button("Rotate X")) {
|
||||
MeshUtil.swapAxis(1, 2);
|
||||
ddirty = 2;
|
||||
}
|
||||
|
||||
if (ui.button("Rotate Y")) {
|
||||
MeshUtil.swapAxis(2, 0);
|
||||
ddirty = 2;
|
||||
}
|
||||
if (ui.button("Rotate Z")) {
|
||||
MeshUtil.swapAxis(0, 1);
|
||||
ddirty = 2;
|
||||
}
|
||||
|
||||
var dispHandle = Id.handle({value: displaceStrength});
|
||||
displaceStrength = ui.slider(dispHandle, "Displace", 0.0, 2.0, true);
|
||||
if (dispHandle.changed) {
|
||||
|
||||
@@ -66,47 +66,47 @@ class MeshUtil {
|
||||
});
|
||||
}
|
||||
|
||||
public static function switchUpAxis(axisUp:Int) {
|
||||
public static function swapAxis(a:Int, b:Int) {
|
||||
for (p in UITrait.inst.paintObjects) {
|
||||
// Remapping vertices, backle up
|
||||
// 0 - x, 1 - y, 2 - z
|
||||
var vas = p.data.raw.vertex_arrays;
|
||||
var pa = vas[0].values;
|
||||
var na0 = a == 2 ? vas[0].values : vas[1].values;
|
||||
var na1 = b == 2 ? vas[0].values : vas[1].values;
|
||||
var c = a == 2 ? 3 : a;
|
||||
var d = b == 2 ? 3 : b;
|
||||
var e = a == 2 ? 4 : 2;
|
||||
var f = b == 2 ? 4 : 2;
|
||||
|
||||
for (i in 0...Std.int(pa.length / 4)) {
|
||||
var t = pa[i * 4 + a];
|
||||
pa[i * 4 + a] = pa[i * 4 + b];
|
||||
pa[i * 4 + b] = -t;
|
||||
t = na0[i * e + c];
|
||||
na0[i * e + c] = na1[i * f + d];
|
||||
na1[i * f + d] = -t;
|
||||
}
|
||||
|
||||
var g = p.data.geom;
|
||||
var vertices = g.vertexBuffer.lockInt16(); // posnortex
|
||||
var verticesDepth = g.vertexBufferMap.get("pos").lockInt16();
|
||||
if (axisUp == 2 || axisUp == 3) { // Y / -Y
|
||||
var sign = axisUp == 2 ? 1 : -1;
|
||||
for (i in 0...Std.int(vertices.length / 8)) {
|
||||
// Swap Y/Z
|
||||
var f = vertices[i * 8 + 1] * sign;
|
||||
vertices[i * 8 + 1] = vertices[i * 8 + 2] * sign;
|
||||
vertices[i * 8 + 2] = -f;
|
||||
|
||||
f = vertices[i * 8 + 5] * sign;
|
||||
vertices[i * 8 + 5] = vertices[i * 8 + 3] * sign;
|
||||
vertices[i * 8 + 3] = -f;
|
||||
|
||||
f = verticesDepth[i * 4 + 1] * sign;
|
||||
verticesDepth[i * 4 + 1] = verticesDepth[i * 4 + 2] * sign;
|
||||
verticesDepth[i * 4 + 2] = -f;
|
||||
}
|
||||
}
|
||||
else if (axisUp == 0 || axisUp == 1) { // Z / -Z
|
||||
var sign = axisUp == 0 ? 1 : -1;
|
||||
for (i in 0...Std.int(vertices.length / 8)) {
|
||||
var f = vertices[i * 8 + 1] * sign;
|
||||
vertices[i * 8 + 1] = -vertices[i * 8 + 2] * sign;
|
||||
vertices[i * 8 + 2] = f;
|
||||
|
||||
f = vertices[i * 8 + 5] * sign;
|
||||
vertices[i * 8 + 5] = -vertices[i * 8 + 3] * sign;
|
||||
vertices[i * 8 + 3] = f;
|
||||
|
||||
f = verticesDepth[i * 4 + 1] * sign;
|
||||
verticesDepth[i * 4 + 1] = -verticesDepth[i * 4 + 2] * sign;
|
||||
verticesDepth[i * 4 + 2] = f;
|
||||
}
|
||||
for (i in 0...Std.int(vertices.length / 8)) {
|
||||
vertices[i * 8 ] = vas[0].values[i * 4 ];
|
||||
vertices[i * 8 + 1] = vas[0].values[i * 4 + 1];
|
||||
vertices[i * 8 + 2] = vas[0].values[i * 4 + 2];
|
||||
vertices[i * 8 + 3] = vas[0].values[i * 4 + 3];
|
||||
vertices[i * 8 + 4] = vas[1].values[i * 2 ];
|
||||
vertices[i * 8 + 5] = vas[1].values[i * 2 + 1];
|
||||
}
|
||||
g.vertexBuffer.unlock();
|
||||
g.vertexBufferMap.get("pos").unlock();
|
||||
}
|
||||
|
||||
if (UITrait.inst.mergedObject != null) {
|
||||
UITrait.inst.mergedObject.remove();
|
||||
iron.data.Data.deleteMesh(UITrait.inst.mergedObject.data.handle);
|
||||
UITrait.inst.mergedObject = null;
|
||||
}
|
||||
mergeMesh();
|
||||
}
|
||||
|
||||
public static function flipNormals() {
|
||||
|
||||
Reference in New Issue
Block a user