Make wasm plugins embeddable

This commit is contained in:
Lubos Lenco
2021-11-06 12:45:15 +01:00
parent 7daaef051b
commit deefcf70c9
11 changed files with 96 additions and 0 deletions
+88
View File
@@ -0,0 +1,88 @@
let a = Krom_uv_unwrap;
class R {
get buffer() { return Krom_uv_unwrap._buffer(); }
}
let r = new R();
// uv_unwrap.js
let plugin = new arm.Plugin();
let h1 = new zui.Handle();
plugin.drawUI = function(ui) {
if (ui.panel(h1, "UV Unwrap")) {
if (ui.button("Unwrap Mesh")) {
for (const po of arm.Project.paintObjects) {
let raw = po.data.raw;
let positions = raw.vertex_arrays[0].values;
let normals = raw.vertex_arrays[1].values;
let indices = raw.index_arrays[0].values;
let vertexCount = positions.length / 4;
let indexCount = indices.length;
a._setVertexCount(vertexCount);
a._setIndexCount(indexCount);
let pa = new Float32Array(r.buffer, a._setPositions(), vertexCount * 3);
let na = new Float32Array(r.buffer, a._setNormals(), vertexCount * 3);
let ia = new Uint32Array(r.buffer, a._setIndices(), indexCount);
let inv = 1 / 32767;
for (let i = 0; i < vertexCount; i++) {
pa[i * 3 ] = positions[i * 4 ] * inv;
pa[i * 3 + 1] = positions[i * 4 + 1] * inv;
pa[i * 3 + 2] = positions[i * 4 + 2] * inv;
na[i * 3 ] = normals [i * 2 ] * inv;
na[i * 3 + 1] = normals [i * 2 + 1] * inv;
na[i * 3 + 2] = positions[i * 4 + 3] * inv;
}
for (let i = 0; i < indexCount; i++) {
ia[i] = indices[i];
}
a._unwrap();
vertexCount = a._getVertexCount();
indexCount = a._getIndexCount();
pa = new Float32Array(r.buffer, a._getPositions(), vertexCount * 3);
na = new Float32Array(r.buffer, a._getNormals(), vertexCount * 3);
let ua = new Float32Array(r.buffer, a._getUVs(), vertexCount * 2);
ia = new Uint32Array(r.buffer, a._getIndices(), indexCount);
let pa16 = new Int16Array(vertexCount * 4);
let na16 = new Int16Array(vertexCount * 2);
let ua16 = new Int16Array(vertexCount * 2);
let ia32 = new Uint32Array(indexCount);
for (let i = 0; i < vertexCount; i++) {
pa16[i * 4 ] = pa[i * 3 ] / inv;
pa16[i * 4 + 1] = pa[i * 3 + 1] / inv;
pa16[i * 4 + 2] = pa[i * 3 + 2] / inv;
pa16[i * 4 + 3] = na[i * 3 + 2] / inv;
na16[i * 2 ] = na[i * 3 ] / inv;
na16[i * 2 + 1] = na[i * 3 + 1] / inv;
ua16[i * 2 ] = ua[i * 2 ] / inv;
ua16[i * 2 + 1] = ua[i * 2 + 1] / inv;
}
for (let i = 0; i < indexCount; i++) {
ia32[i] = ia[i];
}
po.data.raw.vertex_arrays[0].values = pa16;
po.data.raw.vertex_arrays[1].values = na16;
po.data.raw.vertex_arrays[2].values = ua16;
po.data.raw.index_arrays[0].values = ia32;
let geom = po.data.geom;
geom.indices[0] = ia32;
geom.ready = false;
geom.build();
a._destroy();
}
arm.MeshUtil.mergeMesh();
}
}
}
+1
View File
@@ -66,6 +66,7 @@ cp -a build/krom/ armorcore/Deployment
cd armorcore
git apply patch/ios_document_picker.diff --directory=Kinc
git apply patch/metal_depth.diff --directory=Kinc
git clone https://github.com/armory3d/armorpaint_plugins Libraries/plugins
node Kinc/make ios -g metal
# Open generated Xcode project `build/ArmorPaint.xcodeproj`
# Set iOS Deployment Target to 11.0
+7
View File
@@ -9,6 +9,7 @@ let raytrace = d3d12 || vulkan;
let metal = process.argv.indexOf("metal") >= 0;
let vr = process.argv.indexOf("--vr") >= 0;
let snapshot = process.argv.indexOf("--snapshot") >= 0;
let plugin_embed = ios;
let project = new Project("ArmorPaint");
project.addSources("Sources");
@@ -28,6 +29,12 @@ project.addAssets("Assets/keymap_presets/*", { destination: "data/keymap_presets
project.addAssets("Assets/locale/*", { destination: "data/locale/{name}" });
project.addAssets("Assets/licenses/**", { destination: "data/licenses/{name}" });
project.addAssets("Assets/plugins/*", { destination: "data/plugins/{name}" });
if (plugin_embed) {
project.addAssets("Assets/plugins/embed/*", { destination: "data/plugins/{name}" });
}
else {
project.addAssets("Assets/plugins/wasm/*", { destination: "data/plugins/{name}" });
}
project.addAssets("Assets/meshes/*", { destination: "data/meshes/{name}" });
project.addAssets("Libraries/armorbase/Assets/licenses/**", { destination: "data/licenses/{name}" });
project.addAssets("Libraries/armorbase/Assets/themes/*.json", { destination: "data/themes/{name}" });