Skip to content

Commit

Permalink
Support change background image on render
Browse files Browse the repository at this point in the history
  • Loading branch information
xianfei committed Jun 26, 2022
1 parent c7db6c3 commit 24a6183
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
Binary file modified .DS_Store
Binary file not shown.
29 changes: 28 additions & 1 deletion mocaprender/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,13 @@ const drawResults = (results) => {
// switch use camera or video file
if (localStorage.getItem("useCamera") == "camera") {
navigator.mediaDevices
.getUserMedia({ video: { deviceId: localStorage.getItem("cameraId"),width: 1280, height: 720 } })
.getUserMedia({
video: {
deviceId: localStorage.getItem("cameraId"),
width: 1280,
height: 720,
},
})
.then(function (stream) {
videoElement.srcObject = stream;
videoElement.play();
Expand Down Expand Up @@ -770,3 +776,24 @@ document.addEventListener("keydown", (event) => {
break;
}
});

var contentDom = document.querySelector("#model");

//阻止相关事件默认行为
contentDom.ondragcenter =
contentDom.ondragover =
contentDom.ondragleave =
() => {
return false;
};

//对拖动释放事件进行处理
contentDom.ondrop = (e) => {
//console.log(e);
var filePath = e.dataTransfer.files[0].path.replaceAll("\\", "/");
console.log(filePath);
contentDom.style.backgroundImage = `url(${filePath})`;
contentDom.style.backgroundSize = "cover";
contentDom.style.backgroundPosition = "center";
contentDom.style.backgroundRepeat = "no-repeat";
};
23 changes: 22 additions & 1 deletion render/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,25 @@ document.addEventListener("keydown", (event) => {

if (localStorage.getItem("useCamera") !== "camera") {
document.querySelector("#model").style.transform = "scale(-1, 1)";
}
}

var contentDom = document.querySelector("#model");

//阻止相关事件默认行为
contentDom.ondragcenter =
contentDom.ondragover =
contentDom.ondragleave =
() => {
return false;
};

//对拖动释放事件进行处理
contentDom.ondrop = (e) => {
//console.log(e);
var filePath = e.dataTransfer.files[0].path.replaceAll("\\", "/");
console.log(filePath);
contentDom.style.backgroundImage = `url(${filePath})`;
contentDom.style.backgroundSize = "cover";
contentDom.style.backgroundPosition = "center";
contentDom.style.backgroundRepeat = "no-repeat";
};

0 comments on commit 24a6183

Please sign in to comment.