[lab] Auto-apply displacement

This commit is contained in:
luboslenco
2023-09-18 13:35:09 +02:00
parent 4c012939f3
commit 9ea17f22bc
4 changed files with 36 additions and 5 deletions
+33 -2
View File
@@ -1,8 +1,12 @@
package arm.ui;
import kha.arrays.ByteArray;
@:access(zui.Zui)
class UINodesExt {
static var lastVertices: ByteArray = null; // Before displacement
public static function drawButtons(ew: Float, startY: Float) {
var ui = UINodes.inst.ui;
if (ui.button(tr("Run"))) {
@@ -70,8 +74,35 @@ class UINodesExt {
texpaint_pack.g4.drawIndexedVertices();
texpaint_pack.g4.end();
// arm.util.MeshUtil.applyDisplacement(texpaint_pack, 0.08, Context.raw.brushScale);
// arm.util.MeshUtil.calcNormals();
// Make copy of vertices before displacement
var o = Project.paintObjects[0];
var g = o.data.geom;
var vertices = g.vertexBuffer.lock();
if (lastVertices == null || lastVertices.byteLength != vertices.byteLength) {
lastVertices = ByteArray.make(vertices.byteLength);
for (i in 0...Std.int(vertices.byteLength / 2)) {
lastVertices.setInt16(i * 2, vertices.getInt16(i * 2));
}
}
else {
for (i in 0...Std.int(vertices.byteLength / 2)) {
vertices.setInt16(i * 2, lastVertices.getInt16(i * 2));
}
}
g.vertexBuffer.unlock();
// Apply displacement
if (Config.raw.displace_strength > 0) {
arm.App.notifyOnNextFrame(function() {
Console.progress(tr("Apply Displacement"));
arm.App.notifyOnNextFrame(function() {
arm.util.MeshUtil.applyDisplacement(texpaint_pack, 0.05 * Config.raw.displace_strength, Context.raw.brushScale);
arm.util.MeshUtil.calcNormals();
Context.raw.ddirty = 2;
Console.progress(null);
});
});
}
}
Context.raw.ddirty = 2;
+2 -1
View File
@@ -79,7 +79,8 @@ class TabMeshes {
MeshUtil.applyDisplacement(Project.layers[0].texpaint_pack);
#end
#if is_lab
MeshUtil.applyDisplacement(arm.logic.BrushOutputNode.inst.texpaint_pack, 0.05, Context.raw.brushScale);
var displace_strength = Config.raw.displace_strength > 0 ? Config.raw.displace_strength : 1.0;
MeshUtil.applyDisplacement(arm.logic.BrushOutputNode.inst.texpaint_pack, 0.05 * displace_strength, Context.raw.brushScale);
#end
MeshUtil.calcNormals();
+1 -1
View File
@@ -163,7 +163,7 @@ class UIView2D {
#end
}
#if (is_paint || is_sculpt)
#if is_paint
else if (type == View2DLayer) {
var layer = l;
-1
View File
@@ -348,7 +348,6 @@ class MeshUtil {
g.vertexBuffer.unlock();
var va0 = o.data.raw.vertex_arrays[0].values;
var va1 = o.data.raw.vertex_arrays[1].values;
for (i in 0...Std.int(vertices.byteLength / 4 / l)) {
va0[i * 4 ] = vertices.getInt16((i * l ) * 2);
va0[i * 4 + 1] = vertices.getInt16((i * l + 1) * 2);