Files
PozzettiAndrea-ComfyUI-Geom…/javascript/js/viewer/loaders/OBJLoader.js
T
PozzettiAndrea 414f759791 Vendor frontend JS into javascript/; drop the prestartup copy dance
The viewer JS/HTML/bundles are now committed in javascript/ (declared via
pyproject [tool.comfy] web = "javascript") instead of being copied from the
shared comfy-3d-viewers pip package at prestartup. Consequences:

- requirements.txt is now just comfy-env (host env installs nothing else,
  per the never-touch-the-host-env principle)
- prestartup_script.py no longer copies viewers or web_src; it keeps only
  setup_env() and the input-asset copies
- WEB_DIRECTORY attribute removed; the pyproject declaration is the single
  source (served at /extensions/comfyui-geometrypack/, keyed by project name)
- web_src/ deleted; its 6 widgets now live in javascript/js/ as the tracked
  source, edited directly
- viewer_pbr.html hardcoded-fallback URL updated to the new mount name

Iframe URLs auto-detect the mount from import.meta.url, so the folder rename
and mount-name change are transparent at runtime.
2026-08-12 17:37:09 +02:00

64 lines
1.7 KiB
JavaScript

/**
* OBJLoader - OBJ mesh file loader
*
* Loads Wavefront OBJ files using VTK.js vtkOBJReader.
* Includes normals computation for proper shading.
*/
/**
* Load an OBJ file and return polydata
* @param {ArrayBuffer} arrayBuffer - File data as ArrayBuffer
* @param {Object} vtk - VTK.js global object
* @returns {Object} Result object with polyData and metadata
*/
export async function loadOBJ(arrayBuffer, vtk) {
const vtkOBJReader = vtk.IO.Misc.vtkOBJReader;
const vtkPolyDataNormals = vtk.Filters.Core.vtkPolyDataNormals;
const reader = vtkOBJReader.newInstance();
// OBJ files are text-based
const text = new TextDecoder().decode(arrayBuffer);
reader.parseAsText(text);
const rawPolyData = reader.getOutputData();
if (!rawPolyData) {
throw new Error('Failed to parse OBJ data');
}
// Apply normals filter for proper shading
const normalsFilter = vtkPolyDataNormals.newInstance();
normalsFilter.setInputConnection(reader.getOutputPort());
normalsFilter.update();
const polyData = normalsFilter.getOutputData();
return {
polyData,
reader,
normalsFilter,
outputPort: normalsFilter.getOutputPort(),
metadata: {
format: 'OBJ',
numPoints: polyData.getNumberOfPoints(),
numPolys: polyData.getNumberOfPolys(),
bounds: polyData.getBounds()
}
};
}
/**
* Check if a filepath is an OBJ file
* @param {string} filepath - File path or URL
* @returns {boolean}
*/
export function canLoadOBJ(filepath) {
return filepath.toLowerCase().includes('.obj');
}
export default {
load: loadOBJ,
canLoad: canLoadOBJ,
format: 'OBJ'
};