File size: 24,203 Bytes
f2959c6
 
 
 
 
 
e6ae7f4
 
 
 
f2959c6
e6ae7f4
 
 
f2959c6
 
22d4b27
e6ae7f4
22d4b27
f2959c6
e6ae7f4
f2959c6
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
  "id": "openpose-3d-editor",
  "name": "OpenPose 3D Editor",
  "description": "A powerful, custom interactive 3D character posing component for Gradio apps Inspired by Openart OpenPose Editor, using `gr.HTML` and Three.js. It allows users to manipulate a 3D model's bones in real-time, adjust camera angles, apply aspect ratio cropping, and export the resulting pose map directly to the Python backend..",
  "author": "elismasilva",
  "tags": [
    "openpose",
    "3D",
    "Editor",
    "Controlnet"
  ],
  "html_template": "\n<div id=\"op3d-root\" style=\"position:relative;width:100%;height:${height}px;overflow:hidden;border-radius:var(--block-radius, 10px);background:var(--background-fill-primary, #e8e8e8);\">\n  <!-- Three.js canvas mount point -->\n  <div id=\"op3d-mount\" style=\"width:100%;height:100%;\"></div>\n\n  <!-- CROP OVERLAY -->\n  <div id=\"op3d-crop-overlay\" style=\"\n    position:absolute;top:0;left:0;width:100%;height:100%;\n    pointer-events:none;display:flex;align-items:center;\n    justify-content:center;z-index:10;\">\n    <div id=\"op3d-crop-box\" style=\"border:2px solid rgba(255,255,255,0.85);\n      box-shadow:0 0 0 9999px rgba(0,0,0,0.38);\n      transition:width .25s ease,height .25s ease;\"></div>\n  </div>\n\n  <!-- VERTICAL TOOLBAR (Right aligned, Theme Aware) -->\n  <div id=\"op3d-toolbar\" style=\"\n    position:absolute;top:50%;right:16px;transform:translateY(-50%);\n    display:flex;flex-direction:column;align-items:center;gap:6px;\n    background:var(--block-background-fill);\n    border:1px solid var(--border-color-primary);\n    padding:12px 8px;border-radius:12px;\n    box-shadow:var(--shadow-drop);\n    z-index:20;\">\n\n    <!-- Aspect ratio -->\n    <select id=\"op3d-aspect\" title=\"Aspect Ratio\" style=\"\n      padding:6px 2px;border-radius:6px;border:1px solid var(--border-color-primary);\n      background:var(--background-fill-secondary);color:var(--body-text-color);\n      font-size:11px;font-weight:600;cursor:pointer;outline:none;\n      text-align:center;width:44px;appearance:none;-webkit-appearance:none;text-align-last:center;\">\n      <option value=\"1:1\">1:1</option>\n      <option value=\"16:9\">16:9</option>\n      <option value=\"4:3\">4:3</option>\n      <option value=\"3:2\">3:2</option>\n      <option value=\"5:4\">5:4</option>\n      <option value=\"2:3\">2:3</option>\n      <option value=\"4:5\">4:5</option>\n      <option value=\"9:16\">9:16</option>\n    </select>\n\n    <div class=\"op3d-sep\"></div>\n\n    <!-- Rotate Button -->\n    <button id=\"op3d-btn-rotate\" class=\"op3d-icon-btn active\" title=\"Rotate\">\n      <svg width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n        <path d=\"M21.5 2v6h-6\"/>\n        <path d=\"M21.34 15.57a10 10 0 1 1-.57-8.38\"/>\n      </svg>\n    </button>\n\n    <!-- Move Button -->\n    <button id=\"op3d-btn-translate\" class=\"op3d-icon-btn\" title=\"Move\">\n      <svg width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"currentColor\">\n        <path d=\"M12 2l-3 4h2.5v4.5H7V8L3 11l4 3v-2.5h4.5V16H9l3 4 3-4h-2.5v-4.5H17V14l4-3-4-3v2.5h-4.5V6H15z\"/>\n      </svg>\n    </button>\n\n    <div class=\"op3d-sep\"></div>\n\n    <!-- Undo Button -->\n    <button id=\"op3d-btn-undo\" class=\"op3d-icon-btn\" title=\"Undo (Ctrl+Z)\" disabled>\n      <svg width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n        <polyline points=\"9 14 4 9 9 4\"/><path d=\"M20 20v-7a4 4 0 0 0-4-4H4\"/>\n      </svg>\n    </button>\n\n    <!-- Redo Button -->\n    <button id=\"op3d-btn-redo\" class=\"op3d-icon-btn\" title=\"Redo (Ctrl+Shift+Z)\" disabled>\n      <svg width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n        <polyline points=\"15 14 20 9 15 4\"/><path d=\"M4 20v-7a4 4 0 0 1 4-4h12\"/>\n      </svg>\n    </button>\n\n    <div class=\"op3d-sep\"></div>\n\n    <!-- Reset Button -->\n    <button id=\"op3d-btn-reset\" class=\"op3d-icon-btn\" title=\"Reset Pose (Ctrl+R)\">\n      <svg width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n        <path d=\"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8\"/><path d=\"M3 3v5h5\"/>\n      </svg>\n    </button>\n\n    <div class=\"op3d-sep\"></div>\n\n    <!-- Export Button (Floppy disk) -->\n    <button id=\"op3d-btn-export\" class=\"op3d-icon-btn export\" title=\"Export to Python\">\n      <svg width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n        <rect x=\"2\" y=\"2\" width=\"20\" height=\"20\" rx=\"2\" ry=\"2\"/>\n        <path d=\"M7 2v7h10V2\"/>\n        <rect x=\"9\" y=\"2\" width=\"4\" height=\"5\" rx=\"0\"/>\n        <rect x=\"6\" y=\"14\" width=\"12\" height=\"7\" rx=\"1\"/>\n      </svg>\n    </button>\n  </div>\n</div>\n",
  "css_template": "\n  .op3d-icon-btn {\n    display: flex; align-items: center; justify-content: center;\n    width: 38px; height: 38px;\n    border: none; border-radius: 8px;\n    background: transparent; color: var(--body-text-color);\n    cursor: pointer; transition: all 0.15s ease;\n  }\n  .op3d-icon-btn:hover { background: var(--background-fill-secondary); }\n  .op3d-icon-btn.active { background: var(--color-accent); color: white; }\n  \n  .op3d-icon-btn:disabled { opacity: 0.3 !important; cursor: default; }\n  .op3d-icon-btn:disabled:hover { background: transparent; }\n  \n  .op3d-icon-btn.export { color: var(--color-accent); }\n  .op3d-icon-btn.export:hover { background: var(--color-accent); color: white; }\n\n  .op3d-sep { width: 24px; height: 1px; background: var(--border-color-primary); margin: 2px 0; }\n",
  "js_on_load": "\n(async () => {\n  try {\n    // Dynamic ESM Imports\n    const THREE = await import('https://esm.sh/three@0.160.0');\n    const { OrbitControls } = await import('https://esm.sh/three@0.160.0/examples/jsm/controls/OrbitControls.js');\n    const { TransformControls } = await import('https://esm.sh/three@0.160.0/examples/jsm/controls/TransformControls.js');\n    const { FBXLoader } = await import('https://esm.sh/three@0.160.0/examples/jsm/loaders/FBXLoader.js');\n\n    const root = element.querySelector('#op3d-mount');\n    if (!root) return;\n\n    const fbxUrl = props.fbx_url || './base.fbx';\n\n    // ==================== SCENE ====================\n    const scene = new THREE.Scene();\n    scene.background = new THREE.Color(0xe8e8e8); \n\n    const W = () => root.clientWidth;\n    const H = () => root.clientHeight;\n\n    // ==================== CAMERA ====================\n    const camera = new THREE.PerspectiveCamera(70, W() / H(), 0.1, 1000);\n    camera.position.set(80, 60, 70);\n    camera.lookAt(0, 30, 0);\n\n    // ==================== RENDERER ====================\n    const renderer = new THREE.WebGLRenderer({ antialias: true, preserveDrawingBuffer: true });\n    renderer.setSize(W(), H());\n    renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));\n    renderer.shadowMap.enabled = true;\n    renderer.outputColorSpace = THREE.SRGBColorSpace; \n    renderer.domElement.style.cssText = 'position:absolute;top:0;left:0;width:100%;height:100%;';\n    root.appendChild(renderer.domElement);\n\n    // ==================== ORBIT CONTROLS ====================\n    const orbit = new OrbitControls(camera, renderer.domElement);\n    orbit.target.set(0, 30, 0);\n    orbit.minDistance = 20; \n    orbit.maxDistance = 500;\n    orbit.minPolarAngle = Math.PI / 6; \n    orbit.maxPolarAngle = 0.7 * Math.PI;\n    orbit.enableDamping = true; \n    orbit.dampingFactor = 0.05;\n    orbit.update();\n\n    // ==================== LIGHTS ====================\n    const hemiLight = new THREE.HemisphereLight(0xffffff, 0x447392, 3);\n    scene.add(hemiLight);\n\n    const dirLight = new THREE.DirectionalLight(0xffffff, 3); \n    dirLight.position.set(0, 200, 0); \n    dirLight.castShadow = true; \n    scene.add(dirLight);\n\n    const dirLight2 = new THREE.DirectionalLight(0xffffff, 3); \n    dirLight2.position.set(0, 200, 100); \n    scene.add(dirLight2);\n\n    // ==================== GRID & FLOOR ====================\n    const gridHelper = new THREE.GridHelper(2000, 20, 0x000000, 0x000000);\n    gridHelper.material.opacity = 0.2; \n    gridHelper.material.transparent = true;\n    scene.add(gridHelper);\n\n    const floorGeo = new THREE.PlaneGeometry(2000, 2000);\n    const floorMat = new THREE.MeshStandardMaterial({ color: 0x787878, roughness: 0.2, metalness: 0 });\n    const floor = new THREE.Mesh(floorGeo, floorMat);\n    floor.rotation.x = -Math.PI / 2; \n    floor.receiveShadow = true;\n    scene.add(floor);\n\n    // ==================== TRANSFORM CONTROLS ====================\n    const transformControl = new TransformControls(camera, renderer.domElement);\n    transformControl.setMode('rotate'); \n    transformControl.setSpace('local');\n    scene.add(transformControl);\n    \n    transformControl.addEventListener('dragging-changed', event => { \n        orbit.enabled = !event.value; \n    });\n\n    // ==================== STATE VARIABLES ====================\n    let characterMesh = null, currentMode = 'rotate';\n    const proxyMeshes = [], boneMap = new Map();\n    let initialPoseSnapshot = null;\n    const history = [], redoStack = [], MAX_HISTORY = 50;\n\n    // ==================== COLORS ====================\n    function getBoneColor(boneName) {\n      const name = boneName.toLowerCase();\n      if (name.includes('head') || name.includes('neck')) return 0x0000ff;\n      if (name.includes('spine')) return 0x004080;\n      if (name.includes('hips'))  return 0x8000ff;\n      if (name.includes('shoulder')) return 0x8A0000;\n      if (name.includes('rightarm') || name.includes('leftarm')) return 0xF99D36;\n      if (name.includes('rightforearm') || name.includes('leftforearm')) return 0xFFFF00;\n      if (name.includes('hand')) return 0x00aaff;\n      if (name.includes('upleg') || name.includes('leg') || name.includes('knee')) {\n          return name.includes('left') ? 0x00ff88 : 0xff0088;\n      }\n      if (name.includes('rightfoot')) return 0xff0088;\n      if (name.includes('leftfoot'))  return 0x00ff88;\n      return 0x44ffaa;\n    }\n\n    function makeCircleTexture(color, selected = false) {\n      const size = 128;\n      const canvas = document.createElement('canvas');\n      canvas.width = size;\n      canvas.height = size;\n      const ctx = canvas.getContext('2d');\n      \n      const hex = '#' + color.toString(16).padStart(6, '0');\n      \n      ctx.beginPath(); \n      ctx.arc(size / 2, size / 2, size / 2 - 3, 0, Math.PI * 2);\n      ctx.fillStyle = hex; \n      ctx.fill();\n      \n      ctx.strokeStyle = selected ? 'rgba(255,255,255,1)' : 'rgba(255,255,255,0.5)';\n      ctx.lineWidth = selected ? 10 : 4; \n      ctx.stroke();\n      \n      return new THREE.CanvasTexture(canvas);\n    }\n\n    // ==================== POSE SNAPSHOTS ====================\n    function capturePose() {\n      const snapshot = {};\n      boneMap.forEach((_, bone) => { \n        snapshot[bone.uuid] = {\n            quaternion: bone.quaternion.clone(),\n            position: bone.position.clone()\n        }; \n      });\n      return snapshot;\n    }\n\n    function applySnapshot(snapshot) {\n      boneMap.forEach((_, bone) => { \n        if(snapshot[bone.uuid]){\n            bone.quaternion.copy(snapshot[bone.uuid].quaternion);\n            bone.position.copy(snapshot[bone.uuid].position);\n        } \n      });\n    }\n    \n    function captureInitialPose() { \n        initialPoseSnapshot = capturePose(); \n    }\n\n    function pushHistory() {\n      history.push(capturePose());\n      if(history.length > MAX_HISTORY) history.shift();\n      redoStack.length = 0; \n      updateUndoRedoBtns();\n    }\n    \n    function undo() { \n        if(history.length === 0) return; \n        redoStack.push(capturePose()); \n        applySnapshot(history.pop()); \n        updateUndoRedoBtns(); \n    }\n    \n    function redo() { \n        if(redoStack.length === 0) return; \n        history.push(capturePose()); \n        applySnapshot(redoStack.pop()); \n        updateUndoRedoBtns(); \n    }\n\n    function updateUndoRedoBtns() {\n      element.querySelector('#op3d-btn-undo').disabled = history.length === 0;\n      element.querySelector('#op3d-btn-redo').disabled = redoStack.length === 0;\n    }\n\n    transformControl.addEventListener('mouseDown', () => pushHistory());\n\n    // ==================== FBX LOADING ====================\n    function findMainBones(model) {\n      const ignored = ['finger', 'thumb', 'index', 'middle', 'ring', 'pinky', 'toe', '_end', 'rigneck'];\n      const wanted  = ['hips', 'spine', 'head', 'shoulder', 'arm', 'forearm', 'hand', 'upleg', 'leg', 'foot'];\n      const result  = [];\n      model.traverse(child => {\n        if(!child.isBone) return;\n        const n = child.name.toLowerCase();\n        if(ignored.some(k => n.includes(k))) return;\n        if(wanted.some(k => n.includes(k))) result.push(child);\n      });\n      return result;\n    }\n\n    function createControlPoints(bones) {\n      bones.forEach(bone => {\n        const color = getBoneColor(bone.name);\n        const texture = makeCircleTexture(color);\n        const mat = new THREE.SpriteMaterial({ map: texture, depthTest: false, transparent: true, opacity: 0.95 });\n        \n        const sprite = new THREE.Sprite(mat);\n        sprite.scale.set(10, 10, 1);\n        sprite.userData = { bone, type: 'controlPoint', region: bone.name, baseColor: color };\n        \n        scene.add(sprite); \n        proxyMeshes.push(sprite); \n        boneMap.set(bone, sprite);\n      });\n    }\n\n    function fitCameraToModel() {\n      if(!characterMesh) return;\n      const box = new THREE.Box3().setFromObject(characterMesh);\n      const center = box.getCenter(new THREE.Vector3());\n      const size = box.getSize(new THREE.Vector3());\n      const maxDim = Math.max(size.x, size.y, size.z);\n      \n      const distance = maxDim * 1.8;\n      camera.position.set(\n          center.x + distance * 0,\n          center.y + distance * 0.5,\n          center.z + distance * 1.0\n      );\n      camera.lookAt(center); \n      orbit.target.copy(center); \n      orbit.update();\n    }\n\n    function selectProxy(proxy) {\n      const bone = proxy.userData.bone;\n      transformControl.detach(); \n      transformControl.attach(bone); \n      transformControl.setMode(currentMode);\n      \n      proxyMeshes.forEach(p => { \n          p.material.opacity = 0.95;\n          p.material.map = makeCircleTexture(p.userData.baseColor); \n          p.material.needsUpdate = true; \n      });\n      proxy.material.map = makeCircleTexture(proxy.userData.baseColor, true); \n      proxy.material.needsUpdate = true;\n    }\n\n    function selectRootBone() {\n      if(proxyMeshes.length === 0) return;\n      const hip = proxyMeshes.find(p => p.userData.region.toLowerCase().includes('hips'));\n      selectProxy(hip || proxyMeshes[0]);\n    }\n\n    const loader = new FBXLoader();\n    loader.load(fbxUrl, obj => {\n      characterMesh = obj;\n      const box = new THREE.Box3().setFromObject(characterMesh);\n      const size = box.getSize(new THREE.Vector3());\n      const center = box.getCenter(new THREE.Vector3());\n      \n      characterMesh.position.set(-center.x, -box.min.y, -center.z);\n      \n      const targetHeight = 100;\n      const scale = targetHeight / size.y;\n      characterMesh.scale.setScalar(scale);\n\n      const mainBones = findMainBones(characterMesh);\n      createControlPoints(mainBones);\n\n      characterMesh.traverse(child => {\n        if(child.isMesh){\n          child.castShadow = true; \n          child.receiveShadow = true;\n        }\n      });\n      \n      scene.add(characterMesh);\n      characterMesh.updateMatrixWorld(true);\n      captureInitialPose();\n      \n      fitCameraToModel(); \n      selectRootBone();\n    }, undefined, err => console.error('FBX load error:', err));\n\n    // ==================== RAYCASTER ====================\n    const raycaster = new THREE.Raycaster();\n    const mouse = new THREE.Vector2();\n    \n    renderer.domElement.addEventListener('pointerdown', event => {\n      const rect = renderer.domElement.getBoundingClientRect();\n      mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;\n      mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;\n      \n      raycaster.setFromCamera(mouse, camera);\n      const visible = proxyMeshes.filter(p => p.visible);\n      const hits = raycaster.intersectObjects(visible, false);\n      \n      if(hits.length > 0) {\n          selectProxy(hits[0].object);\n      } else if(!transformControl.dragging) {\n        transformControl.detach();\n        proxyMeshes.forEach(p => { \n            p.material.map = makeCircleTexture(p.userData.baseColor); \n            p.material.needsUpdate = true; \n        });\n      }\n    });\n\n    // ==================== CROP BOX ====================\n    const cropBox = element.querySelector('#op3d-crop-box');\n    \n    function updateCropBox(ratioString) {\n      const [w, h] = ratioString.split(':').map(Number);\n      \n      // Calculate taking into account the UI space\n      const maxH = root.clientHeight * 0.85; \n      const maxW = root.clientWidth * 0.85;\n      \n      let boxH = Math.min(maxH, 520);\n      let boxW = (boxH * w) / h;\n      \n      if(boxW > maxW){\n          boxW = maxW; \n          boxH = (boxW * h) / w;\n      }\n      \n      cropBox.style.width = `${boxW}px`; \n      cropBox.style.height = `${boxH}px`;\n    }\n    \n    const aspectSel = element.querySelector('#op3d-aspect');\n    aspectSel.addEventListener('change', e => updateCropBox(e.target.value));\n    updateCropBox('1:1');\n\n    // ==================== UI EVENTS ====================\n    element.querySelector('#op3d-btn-rotate').addEventListener('click', () => {\n      currentMode = 'rotate'; \n      transformControl.setMode('rotate'); \n      transformControl.setSpace('local');\n      proxyMeshes.forEach(p => { p.visible = true; });\n      \n      element.querySelector('#op3d-btn-rotate').classList.add('active');\n      element.querySelector('#op3d-btn-translate').classList.remove('active');\n    });\n\n    element.querySelector('#op3d-btn-translate').addEventListener('click', () => {\n      currentMode = 'translate'; \n      transformControl.setMode('translate'); \n      transformControl.setSpace('world');\n      proxyMeshes.forEach(p => { p.visible = p.userData.region.toLowerCase().includes('hips'); });\n      selectRootBone();\n      \n      element.querySelector('#op3d-btn-translate').classList.add('active');\n      element.querySelector('#op3d-btn-rotate').classList.remove('active');\n    });\n\n    element.querySelector('#op3d-btn-undo').addEventListener('click', undo);\n    element.querySelector('#op3d-btn-redo').addEventListener('click', redo);\n\n    element.querySelector('#op3d-btn-reset').addEventListener('click', () => {\n      if(!characterMesh || !initialPoseSnapshot) return;\n      pushHistory(); \n      applySnapshot(initialPoseSnapshot);\n    });\n\n    // ==================== EXPORT TO PYTHON ====================\n    element.querySelector('#op3d-btn-export').addEventListener('click', async () => {\n      if(!characterMesh) return;\n      \n      proxyMeshes.forEach(p => { p.visible = false; });\n      transformControl.visible = false; \n      floor.visible = false; \n      gridHelper.visible = false;\n      \n      renderer.render(scene, camera);\n\n      const rect = cropBox.getBoundingClientRect();\n      const canvasRect = renderer.domElement.getBoundingClientRect();\n      const dpr = window.devicePixelRatio || 1;\n      \n      const srcX = Math.round((rect.left - canvasRect.left) * dpr);\n      const srcY = Math.round((rect.top - canvasRect.top) * dpr);\n      const srcW = Math.round(rect.width * dpr);\n      const srcH = Math.round(rect.height * dpr);\n\n      const cv = document.createElement('canvas'); \n      cv.width = srcW; \n      cv.height = srcH;\n      \n      const ctx = cv.getContext('2d');\n      ctx.drawImage(\n          renderer.domElement,\n          srcX, srcY, srcW, srcH,\n          0,    0,    srcW, srcH\n      );\n\n      proxyMeshes.forEach(p => { p.visible = true; });\n      transformControl.visible = true; \n      floor.visible = true; \n      gridHelper.visible = true;\n\n      const blob = await new Promise(res => cv.toBlob(res, 'image/png'));\n      const file = new File([blob], 'openpose.png', { type: 'image/png' });\n      try {\n        const { path } = await upload(file);\n        props.value = path;        \n        trigger('export');         \n      } catch(e) {\n        console.error('Upload error:', e);\n      }\n    });\n\n    // Keyboard Shortcuts\n    window.addEventListener('keydown', e => {\n      if(e.ctrlKey || e.metaKey){\n        if(e.key === 'z' && !e.shiftKey) { e.preventDefault(); undo(); }\n        if(e.key === 'z' && e.shiftKey)  { e.preventDefault(); redo(); }\n        if(e.key === 'y')                { e.preventDefault(); redo(); }\n        if(e.key === 'r')                { e.preventDefault(); element.querySelector('#op3d-btn-reset').click(); }\n      }\n    });\n\n    // ==================== ANIMATION LOOP ====================\n    function animate() {\n      requestAnimationFrame(animate);\n      if(characterMesh) {\n        characterMesh.updateMatrixWorld(true);\n        for(const [bone, sprite] of boneMap.entries()){\n          const wp = new THREE.Vector3(); \n          bone.getWorldPosition(wp); \n          sprite.position.copy(wp);\n          const d = camera.position.distanceTo(wp); \n          sprite.scale.set(d * 0.012, d * 0.012, 1);\n        }\n      }\n      orbit.update(); \n      renderer.render(scene, camera);\n    }\n    animate();\n\n    // ==================== RESIZE OBSERVER ====================\n    const ro = new ResizeObserver(() => {\n      camera.aspect = W() / H(); \n      camera.updateProjectionMatrix();\n      renderer.setSize(W(), H());\n      updateCropBox(aspectSel.value);\n    });\n    ro.observe(root);\n\n  } catch (error) {\n    console.error(\"Failed to initialize 3D editor:\", error);\n  }\n})();\n",
  "default_props": {
    "value": "",
    "label": "Pose Editor",
    "fbx_url": "https://huggingface.co/buckets/elismasilva/assets/resolve/base.fbx?download=true",
    "height": 500
  },
  "python_code": "class OpenPose3DEditor(gr.HTML):\n    \"\"\"\n    3D Body Pose Editor based on Three.js (r160).\n\n    Parameters\n    ----------\n    fbx_url : str\n        URL or relative path to the FBX model to load.\n    height : int\n        Component height in pixels (default 540).\n\n    Events\n    -------\n    .export(fn, outputs=...)\n        Triggered when the user clicks the save (floppy disk) button.\n        The component's `value` is updated to the generated PNG file path \n        on the Gradio server, ready to be used in Image, File, etc.\n    \"\"\"\n\n    def __init__(self, fbx_url: str = \"https://huggingface.co/buckets/elismasilva/assets/resolve/base.fbx?download=true\", height: int = 540, **kwargs):\n        super().__init__(\n            value=None,\n            fbx_url=fbx_url,\n            height=height,\n            html_template=_HTML_TEMPLATE,\n            css_template=_CSS_TEMPLATE,\n            js_on_load=_JS_ON_LOAD,\n            apply_default_css=False,\n            **kwargs,\n        )\n\n    def api_info(self):\n        # The exported value is the server-side PNG file path\n        return {\"type\": \"string\", \"description\": \"Server-side path of the exported PNG\"}\n",
  "head": "",
  "repo_url": "https://huggingface.co/spaces/elismasilva/gradio_openpose3d_editor"
}