diff --git a/.gitattributes b/.gitattributes index 26e7e7115777704e43009452c20f56a15912ea38..7e8f065ab701ae13765909ccbb068e781108869b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -40,3 +40,5 @@ Stable-Diffusion-Webui-Civitai-Helper/img/all_in_one.png filter=lfs diff=lfs mer posex/image/sample-webui2.jpg filter=lfs diff=lfs merge=lfs -text posex/image/sample-webui2.png filter=lfs diff=lfs merge=lfs -text sd_feed/assets/pinterest.png filter=lfs diff=lfs merge=lfs -text +sd-3dmodel-loader/models/Samba[[:space:]]Dancing.fbx filter=lfs diff=lfs merge=lfs -text +sd-3dmodel-loader/models/pose.vrm filter=lfs diff=lfs merge=lfs -text diff --git a/sd-3dmodel-loader/doc/images/sceneVisible.png b/sd-3dmodel-loader/doc/images/sceneVisible.png new file mode 100644 index 0000000000000000000000000000000000000000..bd1439ff015c64701390e797bb9ea089a5d28899 Binary files /dev/null and b/sd-3dmodel-loader/doc/images/sceneVisible.png differ diff --git a/sd-3dmodel-loader/doc/images/sendToControlNet.png b/sd-3dmodel-loader/doc/images/sendToControlNet.png new file mode 100644 index 0000000000000000000000000000000000000000..4e7024f3db66280d98477121175e41e077eef74b Binary files /dev/null and b/sd-3dmodel-loader/doc/images/sendToControlNet.png differ diff --git a/sd-3dmodel-loader/doc/images/uploadSettingsPanel.png b/sd-3dmodel-loader/doc/images/uploadSettingsPanel.png new file mode 100644 index 0000000000000000000000000000000000000000..35e7bb2cbd19403d341b81acc7ef546c06ddd099 Binary files /dev/null and b/sd-3dmodel-loader/doc/images/uploadSettingsPanel.png differ diff --git a/sd-3dmodel-loader/index.html b/sd-3dmodel-loader/index.html new file mode 100644 index 0000000000000000000000000000000000000000..c5ecbe70b03f8d8b02f743c8d01483dd5016833b --- /dev/null +++ b/sd-3dmodel-loader/index.html @@ -0,0 +1,25 @@ + + +
+ + + + + + + + + \ No newline at end of file diff --git a/sd-3dmodel-loader/javascript/3d-model-loader-import.js b/sd-3dmodel-loader/javascript/3d-model-loader-import.js new file mode 100644 index 0000000000000000000000000000000000000000..c63355421f980c4a9d9b48c01dfc54099849866e --- /dev/null +++ b/sd-3dmodel-loader/javascript/3d-model-loader-import.js @@ -0,0 +1,40 @@ +(function () { + if (!globalThis.threeDModelLoader) globalThis.threeDModelLoader = {}; + const threeDModelLoader = globalThis.threeDModelLoader; + + function load(cont) { + const scripts = cont.textContent.trim().split('\n'); + const base_path = `/file=${scripts.shift()}/js`; + cont.textContent = ''; + + const df = document.createDocumentFragment(); + for (let src of scripts) { + const script = document.createElement('script'); + script.async = true; + script.type = 'module'; + script.src = `file=${src}`; + df.appendChild(script); + } + + globalThis.threeDModelLoader.import = async () => { + const threeDModelLoader = await import(`${base_path}/3d-model-loader.bundle.js`); + + return {threeDModelLoader}; + }; + + if (!globalThis.threeDModelLoader.imports) { + globalThis.threeDModelLoader.imports = {}; + } + + if (!globalThis.threeDModelLoader.imports.threeDModelLoader) { + globalThis.threeDModelLoader.imports.threeDModelLoader = async () => await import(`${base_path}/3d-model-loader.bundle.js`); + } + + cont.appendChild(df); + } + + onUiLoaded(function () { + webGLOutputDiv3DModel = gradioApp().querySelector('#WebGL-output-3dmodel-import'); + load(webGLOutputDiv3DModel); + }) +})(); \ No newline at end of file diff --git a/sd-3dmodel-loader/javascript/lazyload/3d-model-loader-webui.js b/sd-3dmodel-loader/javascript/lazyload/3d-model-loader-webui.js new file mode 100644 index 0000000000000000000000000000000000000000..17256f13144c4f339e9024f8443bfcc13911532d --- /dev/null +++ b/sd-3dmodel-loader/javascript/lazyload/3d-model-loader-webui.js @@ -0,0 +1,116 @@ +console.log('[3D Model Loader] loading...'); + +async function _import() { + if (!globalThis.threeDModelLoader || !globalThis.threeDModelLoader.import) { + return await import('threeDModelLoader'); + } else { + return await globalThis.threeDModelLoader.imports.threeDModelLoader(); + } +} + +await _import(); + +(async function () { + const container = gradioApp().querySelector('#threeDModelLoader-container'); + + const parent = container.parentNode; + parent.classList.remove("prose"); + + const controlNetNumInput = gradioApp().querySelector('#threeDModelLoader-control-net-num'); + const controlNetNum = controlNetNumInput.value; + + async function init_canvas() { + create3dmodelLoaderApp({container: container, controlNetNum: controlNetNum}); + + setSendImageFunc3dmodel(sendImage); + } + + await init_canvas(); + + function sendImage(type, index, dt) { + const selector = type === "txt2img" ? "#txt2img_script_container" : "#img2img_script_container"; + + if (type === "txt2img") { + switch_to_txt2img(); + } else if (type === "img2img") { + switch_to_img2img(); + } + + let container = gradioApp().querySelector(selector); + + let element = container.querySelector('#controlnet'); + + if (!element) { + for (const spans of container.querySelectorAll < HTMLSpanElement > ( + '.cursor-pointer > span' + )) { + if (!spans.textContent?.includes('ControlNet')) { + continue + } + if (spans.textContent?.includes('M2M')) { + continue + } + element = spans.parentElement?.parentElement + } + if (!element) { + console.error('ControlNet element not found') + return + } + } + + const imageElems = element.querySelectorAll('div[data-testid="image"]') + + if (!imageElems[Number(index)]) { + let accordion = element.querySelector('.icon'); + + if (accordion) { + accordion.click(); + + let controlNetAppeared = false; + + let observer = new MutationObserver(function (mutations) { + mutations.forEach(function (mutation) { + if (mutation.type === "childList" && mutation.addedNodes.length > 0) { + for (let i = 0; i < mutation.addedNodes.length; i++) { + if (mutation.addedNodes[i].tagName === "INPUT") { + + controlNetAppeared = true; + + const imageElems2 = element.querySelectorAll('div[data-testid="image"]'); + + updateGradioImage(imageElems2[Number(index)], dt); + + observer.disconnect(); + + return; + } + } + } + }); + }); + + observer.observe(element, {childList: true, subtree: true}); + } + } else { + updateGradioImage(imageElems[Number(index)], dt); + } + } + + function updateGradioImage(element, dt) { + let clearButton = element.querySelector("button[aria-label='Clear']"); + + if (clearButton) { + clearButton.click(); + } + + const input = element.querySelector("input[type='file']"); + input.value = '' + input.files = dt.files + input.dispatchEvent( + new Event('change', { + bubbles: true, + composed: true, + }) + ) + } +})(); diff --git a/sd-3dmodel-loader/js/3d-model-loader.bundle.js b/sd-3dmodel-loader/js/3d-model-loader.bundle.js new file mode 100644 index 0000000000000000000000000000000000000000..3fc717d04f553a5b38f9e7e680fc8f91e4eff671 --- /dev/null +++ b/sd-3dmodel-loader/js/3d-model-loader.bundle.js @@ -0,0 +1,75 @@ +/*! For license information please see 3d-model-loader.bundle.js.LICENSE.txt */ +!function(){var e,t,n={6751:function(e,t,n){"use strict";n.d(t,{Z:function(){return re}});var r=function(){function e(e){var t=this;this._insertTag=function(e){var n;n=0===t.tags.length?t.insertionPoint?t.insertionPoint.nextSibling:t.prepend?t.container.firstChild:t.before:t.tags[t.tags.length-1].nextSibling,t.container.insertBefore(e,n),t.tags.push(e)},this.isSpeedy=void 0===e.speedy||e.speedy,this.tags=[],this.ctr=0,this.nonce=e.nonce,this.key=e.key,this.container=e.container,this.prepend=e.prepend,this.insertionPoint=e.insertionPoint,this.before=null}var t=e.prototype;return t.hydrate=function(e){e.forEach(this._insertTag)},t.insert=function(e){this.ctr%(this.isSpeedy?65e3:1)==0&&this._insertTag(function(e){var t=document.createElement("style");return t.setAttribute("data-emotion",e.key),void 0!==e.nonce&&t.setAttribute("nonce",e.nonce),t.appendChild(document.createTextNode("")),t.setAttribute("data-s",""),t}(this));var t=this.tags[this.tags.length-1];if(this.isSpeedy){var n=function(e){if(e.sheet)return e.sheet;for(var t=0;t