Update app.py
Browse files
app.py
CHANGED
|
@@ -579,11 +579,7 @@ async(c, o, p, d, n, m)=>{
|
|
| 579 |
BABYLON.Engine.LastCreatedScene.render();
|
| 580 |
}
|
| 581 |
});
|
| 582 |
-
|
| 583 |
-
alert(JSON.parse(document.getElementById("output_video").getElementsByTagName("video")));
|
| 584 |
-
alert(JSON.parse(document.getElementById("depth_video").getElementsByTagName("video")));
|
| 585 |
|
| 586 |
-
|
| 587 |
BABYLON.Engine.LastCreatedScene.getEngine().setHardwareScalingLevel(1.0);
|
| 588 |
BABYLON.Engine.LastCreatedScene.clearColor = new BABYLON.Color4(255,255,255,255);
|
| 589 |
BABYLON.Engine.LastCreatedScene.ambientColor = new BABYLON.Color4(255,255,255,255);
|
|
@@ -668,6 +664,9 @@ async(c, o, p, d, n, m)=>{
|
|
| 668 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].rotation.y = coords[o_[j]].heading / 180 * Math.PI;
|
| 669 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].rotation.z = -coords[o_[j]].pitch / 180 * Math.PI;
|
| 670 |
}*/
|
|
|
|
|
|
|
|
|
|
| 671 |
const videoDome = new BABYLON.VideoDome(
|
| 672 |
"videoDome",
|
| 673 |
[document.getElementById("output_video").getElementsByTagName("video")[0].src],
|
|
@@ -690,14 +689,6 @@ async(c, o, p, d, n, m)=>{
|
|
| 690 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.useAlphaFromEmissiveTexture = true;
|
| 691 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].alphaIndex = 1;
|
| 692 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].visibility = 0.9999;
|
| 693 |
-
|
| 694 |
-
window.video = document.getElementById("depth_video").getElementsByTagName("video")[0];
|
| 695 |
-
videoDome.videoTexture.video.oncanplaythrough = function () {
|
| 696 |
-
videoDome.videoTexture.video.play();
|
| 697 |
-
video.play();
|
| 698 |
-
videoDome.videoTexture.video.oncanplaythrough = null;
|
| 699 |
-
video.oncanplaythrough = null;
|
| 700 |
-
};
|
| 701 |
|
| 702 |
window.md = false;
|
| 703 |
window.r_old = 1.0;
|
|
@@ -755,15 +746,7 @@ async(c, o, p, d, n, m)=>{
|
|
| 755 |
document.getElementById("model3D").getElementsByTagName("canvas")[0].addEventListener('pointerout', function() {
|
| 756 |
md = false;
|
| 757 |
});
|
| 758 |
-
|
| 759 |
-
video.addEventListener("playing", function () {
|
| 760 |
-
const canvas = document.createElement("canvas");
|
| 761 |
-
canvas.width = video.videoWidth;
|
| 762 |
-
canvas.height = video.videoHeight;
|
| 763 |
-
ctx = canvas.getContext("2d", { willReadFrequently: true });
|
| 764 |
-
|
| 765 |
-
updateMap();
|
| 766 |
-
});
|
| 767 |
|
| 768 |
function requestMap() {
|
| 769 |
ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
|
|
@@ -774,66 +757,30 @@ async(c, o, p, d, n, m)=>{
|
|
| 774 |
applyDisplacementMapFromBuffer(BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1], buffer, video.videoWidth, video.videoHeight, 0, 1, null, null, true);
|
| 775 |
setTimeout(updateMap, 40);
|
| 776 |
}
|
|
|
|
| 777 |
|
| 778 |
function updateMap() {
|
| 779 |
requestAnimationFrame(requestMap);
|
| 780 |
}
|
|
|
|
| 781 |
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
minHeight,
|
| 788 |
-
maxHeight,
|
| 789 |
-
uvOffset,
|
| 790 |
-
uvScale,
|
| 791 |
-
forceUpdate
|
| 792 |
-
) {
|
| 793 |
-
if (!mesh.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind) || !mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind) || !mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
|
| 794 |
-
alert("Cannot call applyDisplacementMap: Given mesh is not complete. Position, Normal or UV are missing");
|
| 795 |
-
return mesh;
|
| 796 |
-
}
|
| 797 |
-
|
| 798 |
-
const positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind, true, true);
|
| 799 |
-
const normals = mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
|
| 800 |
-
const uvs = mesh.getVerticesData(BABYLON.VertexBuffer.UVKind);
|
| 801 |
-
|
| 802 |
-
let position = BABYLON.Vector3.Zero();
|
| 803 |
-
const normal = BABYLON.Vector3.Zero();
|
| 804 |
-
const uv = BABYLON.Vector2.Zero();
|
| 805 |
-
|
| 806 |
-
uvOffset = uvOffset || BABYLON.Vector2.Zero();
|
| 807 |
-
uvScale = uvScale || new BABYLON.Vector2(1, 1);
|
| 808 |
-
|
| 809 |
-
for (let index = 0; index < positions.length; index += 3) {
|
| 810 |
-
BABYLON.Vector3.FromArrayToRef(positions, index, position);
|
| 811 |
-
BABYLON.Vector3.FromArrayToRef(normals, index, normal);
|
| 812 |
-
BABYLON.Vector2.FromArrayToRef(uvs, (index / 3) * 2, uv);
|
| 813 |
-
|
| 814 |
-
// Compute height
|
| 815 |
-
const u = (Math.abs(uv.x * uvScale.x + (uvOffset.x % 1)) * (heightMapWidth - 1)) % heightMapWidth | 0;
|
| 816 |
-
const v = (Math.abs(uv.y * uvScale.y + (uvOffset.y % 1)) * (heightMapHeight - 1)) % heightMapHeight | 0;
|
| 817 |
-
|
| 818 |
-
const pos = (u + v * heightMapWidth) * 4;
|
| 819 |
-
const r = buffer[pos] / 255.0;
|
| 820 |
-
const g = buffer[pos + 1] / 255.0;
|
| 821 |
-
const b = buffer[pos + 2] / 255.0;
|
| 822 |
-
const a = buffer[pos + 3] / 255.0;
|
| 823 |
-
|
| 824 |
-
const gradient = r * 0.33 + g * 0.33 + b * 0.33;
|
| 825 |
-
//const gradient = a;
|
| 826 |
-
|
| 827 |
-
normal.normalize();
|
| 828 |
-
normal.scaleInPlace(minHeight + (maxHeight - minHeight) * gradient);
|
| 829 |
-
position = position.add(normal);
|
| 830 |
|
| 831 |
-
|
| 832 |
-
}
|
| 833 |
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 837 |
|
| 838 |
if (document.getElementById("model")) {
|
| 839 |
document.getElementById("model").appendChild(document.getElementById("model3D"));
|
|
@@ -977,6 +924,63 @@ if (BABYLON) {
|
|
| 977 |
}
|
| 978 |
window.snapshot = snapshot;
|
| 979 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 980 |
|
| 981 |
var intv_ = setInterval(function(){
|
| 982 |
if (document.getElementById("image_edit") && document.getElementById("image_edit").getElementsByTagName("canvas")) {
|
|
|
|
| 579 |
BABYLON.Engine.LastCreatedScene.render();
|
| 580 |
}
|
| 581 |
});
|
|
|
|
|
|
|
|
|
|
| 582 |
|
|
|
|
| 583 |
BABYLON.Engine.LastCreatedScene.getEngine().setHardwareScalingLevel(1.0);
|
| 584 |
BABYLON.Engine.LastCreatedScene.clearColor = new BABYLON.Color4(255,255,255,255);
|
| 585 |
BABYLON.Engine.LastCreatedScene.ambientColor = new BABYLON.Color4(255,255,255,255);
|
|
|
|
| 664 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].rotation.y = coords[o_[j]].heading / 180 * Math.PI;
|
| 665 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].rotation.z = -coords[o_[j]].pitch / 180 * Math.PI;
|
| 666 |
}*/
|
| 667 |
+
alert(document.getElementById("output_video").innerHTML);
|
| 668 |
+
alert(document.getElementById("depth_video").innerHTML);
|
| 669 |
+
|
| 670 |
const videoDome = new BABYLON.VideoDome(
|
| 671 |
"videoDome",
|
| 672 |
[document.getElementById("output_video").getElementsByTagName("video")[0].src],
|
|
|
|
| 689 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.useAlphaFromEmissiveTexture = true;
|
| 690 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].alphaIndex = 1;
|
| 691 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].visibility = 0.9999;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 692 |
|
| 693 |
window.md = false;
|
| 694 |
window.r_old = 1.0;
|
|
|
|
| 746 |
document.getElementById("model3D").getElementsByTagName("canvas")[0].addEventListener('pointerout', function() {
|
| 747 |
md = false;
|
| 748 |
});
|
| 749 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 750 |
|
| 751 |
function requestMap() {
|
| 752 |
ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
|
|
|
|
| 757 |
applyDisplacementMapFromBuffer(BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1], buffer, video.videoWidth, video.videoHeight, 0, 1, null, null, true);
|
| 758 |
setTimeout(updateMap, 40);
|
| 759 |
}
|
| 760 |
+
window.requestMap = requestMap;
|
| 761 |
|
| 762 |
function updateMap() {
|
| 763 |
requestAnimationFrame(requestMap);
|
| 764 |
}
|
| 765 |
+
window.updateMap = updateMap;
|
| 766 |
|
| 767 |
+
video.addEventListener("playing", function () {
|
| 768 |
+
const canvas = document.createElement("canvas");
|
| 769 |
+
canvas.width = video.videoWidth;
|
| 770 |
+
canvas.height = video.videoHeight;
|
| 771 |
+
ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 772 |
|
| 773 |
+
updateMap();
|
| 774 |
+
});
|
| 775 |
|
| 776 |
+
window.video = document.getElementById("depth_video").getElementsByTagName("video")[0];
|
| 777 |
+
videoDome.videoTexture.video.oncanplaythrough = function () {
|
| 778 |
+
videoDome.videoTexture.video.play();
|
| 779 |
+
video.play();
|
| 780 |
+
videoDome.videoTexture.video.oncanplaythrough = null;
|
| 781 |
+
video.oncanplaythrough = null;
|
| 782 |
+
};
|
| 783 |
+
|
| 784 |
|
| 785 |
if (document.getElementById("model")) {
|
| 786 |
document.getElementById("model").appendChild(document.getElementById("model3D"));
|
|
|
|
| 924 |
}
|
| 925 |
window.snapshot = snapshot;
|
| 926 |
|
| 927 |
+
function applyDisplacementMapFromBuffer(
|
| 928 |
+
mesh,
|
| 929 |
+
buffer,
|
| 930 |
+
heightMapWidth,
|
| 931 |
+
heightMapHeight,
|
| 932 |
+
minHeight,
|
| 933 |
+
maxHeight,
|
| 934 |
+
uvOffset,
|
| 935 |
+
uvScale,
|
| 936 |
+
forceUpdate
|
| 937 |
+
) {
|
| 938 |
+
if (!mesh.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind) || !mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind) || !mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
|
| 939 |
+
alert("Cannot call applyDisplacementMap: Given mesh is not complete. Position, Normal or UV are missing");
|
| 940 |
+
return mesh;
|
| 941 |
+
}
|
| 942 |
+
|
| 943 |
+
const positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind, true, true);
|
| 944 |
+
const normals = mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
|
| 945 |
+
const uvs = mesh.getVerticesData(BABYLON.VertexBuffer.UVKind);
|
| 946 |
+
|
| 947 |
+
let position = BABYLON.Vector3.Zero();
|
| 948 |
+
const normal = BABYLON.Vector3.Zero();
|
| 949 |
+
const uv = BABYLON.Vector2.Zero();
|
| 950 |
+
|
| 951 |
+
uvOffset = uvOffset || BABYLON.Vector2.Zero();
|
| 952 |
+
uvScale = uvScale || new BABYLON.Vector2(1, 1);
|
| 953 |
+
|
| 954 |
+
for (let index = 0; index < positions.length; index += 3) {
|
| 955 |
+
BABYLON.Vector3.FromArrayToRef(positions, index, position);
|
| 956 |
+
BABYLON.Vector3.FromArrayToRef(normals, index, normal);
|
| 957 |
+
BABYLON.Vector2.FromArrayToRef(uvs, (index / 3) * 2, uv);
|
| 958 |
+
|
| 959 |
+
// Compute height
|
| 960 |
+
const u = (Math.abs(uv.x * uvScale.x + (uvOffset.x % 1)) * (heightMapWidth - 1)) % heightMapWidth | 0;
|
| 961 |
+
const v = (Math.abs(uv.y * uvScale.y + (uvOffset.y % 1)) * (heightMapHeight - 1)) % heightMapHeight | 0;
|
| 962 |
+
|
| 963 |
+
const pos = (u + v * heightMapWidth) * 4;
|
| 964 |
+
const r = buffer[pos] / 255.0;
|
| 965 |
+
const g = buffer[pos + 1] / 255.0;
|
| 966 |
+
const b = buffer[pos + 2] / 255.0;
|
| 967 |
+
const a = buffer[pos + 3] / 255.0;
|
| 968 |
+
|
| 969 |
+
const gradient = r * 0.33 + g * 0.33 + b * 0.33;
|
| 970 |
+
//const gradient = a;
|
| 971 |
+
|
| 972 |
+
normal.normalize();
|
| 973 |
+
normal.scaleInPlace(minHeight + (maxHeight - minHeight) * gradient);
|
| 974 |
+
position = position.add(normal);
|
| 975 |
+
|
| 976 |
+
position.toArray(positions, index);
|
| 977 |
+
}
|
| 978 |
+
|
| 979 |
+
mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions);
|
| 980 |
+
return mesh;
|
| 981 |
+
}
|
| 982 |
+
window.applyDisplacementMapFromBuffer = applyDisplacementMapFromBuffer;
|
| 983 |
+
|
| 984 |
|
| 985 |
var intv_ = setInterval(function(){
|
| 986 |
if (document.getElementById("image_edit") && document.getElementById("image_edit").getElementsByTagName("canvas")) {
|