Upload preprocess_manual.js
Browse files- preprocess_manual.js +241 -217
preprocess_manual.js
CHANGED
|
@@ -113,25 +113,73 @@ function createManualUI(scene, camera, renderer) {
|
|
| 113 |
• Scroll: Zoom in/out
|
| 114 |
</div>
|
| 115 |
|
| 116 |
-
<!-- Step 0: PLY
|
| 117 |
<div id="position-adjustment-section" style="display: none; margin-top: 20px;">
|
| 118 |
-
<h3>Step 0: Adjust
|
| 119 |
<p style="font-size: 12px; color: #aaa;">
|
| 120 |
-
|
| 121 |
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
<div style="margin: 10px 0;">
|
| 123 |
-
<label>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
<input type="range" id="ply-x" min="-10.0" max="10.0" step="0.1" value="0.0" style="width: 100%;">
|
| 125 |
</div>
|
| 126 |
<div style="margin: 10px 0;">
|
| 127 |
-
<label>Y
|
| 128 |
<input type="range" id="ply-y" min="-10.0" max="10.0" step="0.1" value="0.0" style="width: 100%;">
|
| 129 |
</div>
|
| 130 |
<div style="margin: 10px 0;">
|
| 131 |
-
<label>Z
|
| 132 |
<input type="range" id="ply-z" min="-10.0" max="10.0" step="0.1" value="0.0" style="width: 100%;">
|
| 133 |
</div>
|
| 134 |
-
|
|
|
|
| 135 |
margin-top: 10px;
|
| 136 |
padding: 8px 15px;
|
| 137 |
background: #FF9800;
|
|
@@ -141,8 +189,8 @@ function createManualUI(scene, camera, renderer) {
|
|
| 141 |
cursor: pointer;
|
| 142 |
width: 48%;
|
| 143 |
margin-right: 2%;
|
| 144 |
-
">Reset
|
| 145 |
-
<button id="confirm-
|
| 146 |
margin-top: 10px;
|
| 147 |
padding: 8px 15px;
|
| 148 |
background: #4CAF50;
|
|
@@ -151,9 +199,8 @@ function createManualUI(scene, camera, renderer) {
|
|
| 151 |
border-radius: 5px;
|
| 152 |
cursor: pointer;
|
| 153 |
width: 48%;
|
| 154 |
-
"
|
| 155 |
</div>
|
| 156 |
-
|
| 157 |
|
| 158 |
<!-- Step 1: Box Adjustment -->
|
| 159 |
<div id="manual-controls" style="margin-top: 20px; display: none;">
|
|
@@ -838,144 +885,70 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
|
|
| 838 |
// Keyboard Controls for Camera Movement: Deleted 12/13 13:50
|
| 839 |
// ========================================
|
| 840 |
|
| 841 |
-
|
| 842 |
|
| 843 |
-
// ========================================
|
| 844 |
-
// Step 0: PLY Position Adjustment
|
| 845 |
-
// ========================================
|
| 846 |
-
ui.setStatus('Step 0: Adjust PLY position if needed');
|
| 847 |
-
ui.showPositionAdjustment();
|
| 848 |
-
|
| 849 |
-
let plyOffset = { x: 0, y: 0, z: 0 };
|
| 850 |
-
const gsScene = gs.viewer.splatMesh.scenes[0];
|
| 851 |
-
|
| 852 |
-
// Position sliders setup
|
| 853 |
-
const setupPositionSlider = (id, valueId, axis) => {
|
| 854 |
-
const slider = document.getElementById(id);
|
| 855 |
-
const valueDisplay = document.getElementById(valueId);
|
| 856 |
-
|
| 857 |
-
if (slider && valueDisplay) {
|
| 858 |
-
slider.addEventListener('input', (e) => {
|
| 859 |
-
const value = parseFloat(e.target.value);
|
| 860 |
-
valueDisplay.textContent = value.toFixed(1);
|
| 861 |
-
plyOffset[axis] = value;
|
| 862 |
-
|
| 863 |
-
gsScene.position[axis] = value;
|
| 864 |
-
gsScene.updateMatrixWorld();
|
| 865 |
-
// No need to call renderer.render here - animation loop handles it
|
| 866 |
-
});
|
| 867 |
-
}
|
| 868 |
-
};
|
| 869 |
-
|
| 870 |
-
setupPositionSlider('ply-x', 'ply-x-value', 'x');
|
| 871 |
-
setupPositionSlider('ply-y', 'ply-y-value', 'y');
|
| 872 |
-
setupPositionSlider('ply-z', 'ply-z-value', 'z');
|
| 873 |
-
|
| 874 |
-
// Reset position button
|
| 875 |
-
const resetPosBtn = document.getElementById('reset-position-btn');
|
| 876 |
-
if (resetPosBtn) {
|
| 877 |
-
resetPosBtn.addEventListener('click', () => {
|
| 878 |
-
plyOffset = { x: 0, y: 0, z: 0 };
|
| 879 |
-
document.getElementById('ply-x').value = 0;
|
| 880 |
-
document.getElementById('ply-y').value = 0;
|
| 881 |
-
document.getElementById('ply-z').value = 0;
|
| 882 |
-
document.getElementById('ply-x-value').textContent = '0.0';
|
| 883 |
-
document.getElementById('ply-y-value').textContent = '0.0';
|
| 884 |
-
document.getElementById('ply-z-value').textContent = '0.0';
|
| 885 |
-
|
| 886 |
-
gsScene.position.set(0, 0, 0);
|
| 887 |
-
gsScene.updateMatrixWorld();
|
| 888 |
-
// No need to call renderer.render here - animation loop handles it
|
| 889 |
-
});
|
| 890 |
-
}
|
| 891 |
-
|
| 892 |
-
// Confirm position button
|
| 893 |
-
const confirmPosBtn = document.getElementById('confirm-position-btn');
|
| 894 |
-
if (confirmPosBtn) {
|
| 895 |
-
confirmPosBtn.addEventListener('click', async () => {
|
| 896 |
-
console.log('[preprocessManual] PLY position confirmed:', plyOffset);
|
| 897 |
-
|
| 898 |
-
// ★★★ STOP ANIMATION LOOP ★★★
|
| 899 |
-
cleanupAnimation();
|
| 900 |
-
|
| 901 |
-
// Apply offset to PLY data if needed
|
| 902 |
-
if (plyOffset.x !== 0 || plyOffset.y !== 0 || plyOffset.z !== 0) {
|
| 903 |
-
plyData.vertices.forEach(vertex => {
|
| 904 |
-
vertex.x += plyOffset.x;
|
| 905 |
-
vertex.y += plyOffset.y;
|
| 906 |
-
vertex.z += plyOffset.z;
|
| 907 |
-
});
|
| 908 |
-
|
| 909 |
-
// Dispose old GS
|
| 910 |
-
await gs.viewer.dispose();
|
| 911 |
-
|
| 912 |
-
// Create new PLY
|
| 913 |
-
const newHeader = plyData.header;
|
| 914 |
-
const newPlyData = parser.createPLYFile(newHeader, plyData.vertices, plyData.vertexSize);
|
| 915 |
-
const blob = new Blob([newPlyData], { type: 'application/octet-stream' });
|
| 916 |
-
const adjustedPlyUrl = URL.createObjectURL(blob);
|
| 917 |
-
|
| 918 |
-
// Reload GS
|
| 919 |
-
gs = await GVRM.initGS(adjustedPlyUrl, undefined, undefined, scene);
|
| 920 |
-
console.log('[preprocessManual] GS reloaded with adjusted position');
|
| 921 |
-
}
|
| 922 |
-
|
| 923 |
-
ui.hidePositionAdjustment();
|
| 924 |
-
ui.setStatus('Step 1: Adjust the bounding box');
|
| 925 |
-
ui.showControls();
|
| 926 |
-
|
| 927 |
// ========================================
|
| 928 |
-
// Step
|
| 929 |
// ========================================
|
| 930 |
-
|
| 931 |
-
// ★★★ RESTART ANIMATION FOR BOX ADJUSTMENT ★★★
|
| 932 |
-
function animateBoxAdjustment() {
|
| 933 |
-
animationId = requestAnimationFrame(animateBoxAdjustment);
|
| 934 |
-
updateCameraFromKeys(camera, cameraControls);
|
| 935 |
-
cameraControls.controls.update();
|
| 936 |
-
renderer.render(scene, camera);
|
| 937 |
-
}
|
| 938 |
-
animateBoxAdjustment();
|
| 939 |
-
|
| 940 |
-
///////////////////////////////////// 12/13 15:40 START
|
| 941 |
|
| 942 |
-
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
ui.createBoundingBox(boxSize, boxPosition);
|
| 946 |
|
| 947 |
-
|
| 948 |
-
|
| 949 |
-
|
| 950 |
-
|
| 951 |
-
|
| 952 |
-
|
| 953 |
-
|
| 954 |
-
|
| 955 |
-
|
| 956 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 957 |
}
|
| 958 |
-
|
| 959 |
-
|
| 960 |
-
|
| 961 |
-
|
| 962 |
-
|
| 963 |
-
|
| 964 |
-
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
if (boxYPosSlider && boxYPosValue) {
|
| 969 |
-
boxYPosSlider.min = (defaultBoxPosition.y - defaultBoxSize.y).toFixed(1);
|
| 970 |
-
boxYPosSlider.max = (defaultBoxPosition.y + defaultBoxSize.y).toFixed(1);
|
| 971 |
-
boxYPosSlider.value = boxPosition.y.toFixed(1);
|
| 972 |
-
boxYPosValue.textContent = boxPosition.y.toFixed(1);
|
| 973 |
-
}
|
| 974 |
|
| 975 |
-
|
|
|
|
| 976 |
|
| 977 |
-
// Box sliders
|
| 978 |
-
const
|
| 979 |
const slider = document.getElementById(id);
|
| 980 |
const valueDisplay = document.getElementById(valueId);
|
| 981 |
|
|
@@ -983,49 +956,138 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
|
|
| 983 |
slider.addEventListener('input', (e) => {
|
| 984 |
const value = parseFloat(e.target.value);
|
| 985 |
valueDisplay.textContent = value.toFixed(1);
|
| 986 |
-
|
| 987 |
-
if (isPosition) {
|
| 988 |
-
boxPosition[property] = value;
|
| 989 |
-
} else {
|
| 990 |
-
boxSize[property] = value;
|
| 991 |
-
}
|
| 992 |
-
|
| 993 |
ui.updateBoundingBox(boxSize, boxPosition);
|
| 994 |
});
|
| 995 |
}
|
| 996 |
};
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1008 |
|
| 1009 |
-
// ★★★ STOP ANIMATION LOOP BEFORE HEAVY PROCESSING ★★★
|
| 1010 |
cleanupAnimation();
|
| 1011 |
|
| 1012 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1013 |
|
| 1014 |
-
// Filter splats
|
| 1015 |
const filteredVertices = filterSplatsByBox(plyData, boxSize, boxPosition);
|
| 1016 |
|
| 1017 |
if (filteredVertices.length === 0) {
|
| 1018 |
-
alert('No splats found in the box! Please adjust the box size/position.');
|
| 1019 |
-
|
| 1020 |
-
animateBoxAdjustment();
|
| 1021 |
return;
|
| 1022 |
}
|
| 1023 |
|
| 1024 |
-
|
|
|
|
|
|
|
| 1025 |
const filteredPlyUrl = createFilteredPLY(
|
| 1026 |
-
parser,
|
| 1027 |
-
plyData.header,
|
| 1028 |
-
filteredVertices,
|
| 1029 |
plyData.vertexSize
|
| 1030 |
);
|
| 1031 |
|
|
@@ -1046,75 +1108,37 @@ export function preprocessManual(vrmPath, gsPath, scene, camera, renderer, stage
|
|
| 1046 |
// Create GVRM instance
|
| 1047 |
const gvrm = new GVRM(character, filteredGs);
|
| 1048 |
|
| 1049 |
-
ui.showBoneAssignment();
|
| 1050 |
ui.setStatus('Step 2: Assign splats to bones');
|
|
|
|
| 1051 |
|
| 1052 |
// ========================================
|
| 1053 |
// Step 2: Bone Assignment
|
| 1054 |
// ========================================
|
| 1055 |
const promise2 = setupBoneAssignment(
|
| 1056 |
-
ui, scene, camera, renderer,
|
| 1057 |
gvrm, character, filteredGs, filteredPlyUrl,
|
| 1058 |
vrmPath, useGPU, savePly, fileName,
|
| 1059 |
-
{ vertices: filteredVertices, header: plyData.header, vertexSize: plyData.vertexSize },
|
| 1060 |
-
plyData
|
| 1061 |
);
|
| 1062 |
|
| 1063 |
-
// Resolve main promise
|
| 1064 |
resolve({
|
| 1065 |
gvrm: gvrm,
|
| 1066 |
promise2: promise2,
|
| 1067 |
error: null,
|
| 1068 |
ui: ui
|
| 1069 |
});
|
| 1070 |
-
|
| 1071 |
});
|
| 1072 |
}
|
| 1073 |
-
});
|
| 1074 |
-
}
|
| 1075 |
-
|
| 1076 |
-
}).catch(err => {
|
| 1077 |
-
console.error('[preprocessManual] GS init error:', err);
|
| 1078 |
-
ui.setStatus('Error loading GS: ' + err.message);
|
| 1079 |
-
resolve({
|
| 1080 |
-
gvrm: null,
|
| 1081 |
-
promise2: Promise.resolve(),
|
| 1082 |
-
error: 'GS initialization failed: ' + err.message
|
| 1083 |
-
});
|
| 1084 |
-
});
|
| 1085 |
-
|
| 1086 |
-
}).catch(err => {
|
| 1087 |
-
console.error('[preprocessManual] PLY parse error:', err);
|
| 1088 |
-
loadingSpinner.removeTask(task);
|
| 1089 |
-
resolve({
|
| 1090 |
-
gvrm: null,
|
| 1091 |
-
promise2: Promise.resolve(),
|
| 1092 |
-
error: 'Failed to load PLY: ' + err.message
|
| 1093 |
-
});
|
| 1094 |
-
});
|
| 1095 |
-
|
| 1096 |
|
| 1097 |
|
|
|
|
|
|
|
|
|
|
| 1098 |
|
| 1099 |
-
|
| 1100 |
-
|
| 1101 |
-
|
| 1102 |
-
gvrm: null,
|
| 1103 |
-
promise2: Promise.resolve(),
|
| 1104 |
-
error: 'UI initialization failed: ' + err.message
|
| 1105 |
-
});
|
| 1106 |
-
});
|
| 1107 |
-
|
| 1108 |
-
} catch (err) {
|
| 1109 |
-
console.error('[preprocessManual] Exception:', err);
|
| 1110 |
-
resolve({
|
| 1111 |
-
gvrm: null,
|
| 1112 |
-
promise2: Promise.resolve(),
|
| 1113 |
-
error: 'Exception: ' + err.message
|
| 1114 |
-
});
|
| 1115 |
-
}
|
| 1116 |
-
});
|
| 1117 |
-
}
|
| 1118 |
|
| 1119 |
// ========================================
|
| 1120 |
// Bone Assignment Setup Function
|
|
|
|
| 113 |
• Scroll: Zoom in/out
|
| 114 |
</div>
|
| 115 |
|
| 116 |
+
<!-- Step 0: Adjust PLY and Box -->
|
| 117 |
<div id="position-adjustment-section" style="display: none; margin-top: 20px;">
|
| 118 |
+
<h3>Step 0: Adjust Position and Bounding Box</h3>
|
| 119 |
<p style="font-size: 12px; color: #aaa;">
|
| 120 |
+
First adjust the bounding box to frame your object, then fine-tune position if needed
|
| 121 |
</p>
|
| 122 |
+
|
| 123 |
+
<!-- Bounding Box Info Display -->
|
| 124 |
+
<div id="bbox-info" style="
|
| 125 |
+
margin: 10px 0;
|
| 126 |
+
padding: 10px;
|
| 127 |
+
background: #1a1a2e;
|
| 128 |
+
border-radius: 5px;
|
| 129 |
+
font-size: 11px;
|
| 130 |
+
color: #aaa;
|
| 131 |
+
">
|
| 132 |
+
<strong>Scene Bounds:</strong><br>
|
| 133 |
+
Size: <span id="scene-size">-</span><br>
|
| 134 |
+
Center: <span id="scene-center">-</span>
|
| 135 |
+
</div>
|
| 136 |
+
|
| 137 |
+
<!-- Bounding Box Controls -->
|
| 138 |
+
<h4 style="margin: 15px 0 10px 0; color: #4CAF50;">📦 Bounding Box</h4>
|
| 139 |
+
|
| 140 |
+
<div style="margin: 10px 0;">
|
| 141 |
+
<label>Box X Size: <span id="box-x-value-step0">3.0</span>m</label><br>
|
| 142 |
+
<input type="range" id="box-x-step0" min="0.5" max="50.0" step="0.1" value="3.0" style="width: 100%;">
|
| 143 |
+
</div>
|
| 144 |
+
<div style="margin: 10px 0;">
|
| 145 |
+
<label>Box Y Size: <span id="box-y-value-step0">3.0</span>m</label><br>
|
| 146 |
+
<input type="range" id="box-y-step0" min="0.5" max="50.0" step="0.1" value="3.0" style="width: 100%;">
|
| 147 |
+
</div>
|
| 148 |
+
<div style="margin: 10px 0;">
|
| 149 |
+
<label>Box Z Size: <span id="box-z-value-step0">3.0</span>m</label><br>
|
| 150 |
+
<input type="range" id="box-z-step0" min="0.5" max="50.0" step="0.1" value="3.0" style="width: 100%;">
|
| 151 |
+
</div>
|
| 152 |
+
|
| 153 |
+
<div style="margin: 10px 0;">
|
| 154 |
+
<label>Box X Position: <span id="box-x-pos-value-step0">0.0</span>m</label><br>
|
| 155 |
+
<input type="range" id="box-x-pos-step0" min="-25.0" max="25.0" step="0.1" value="0.0" style="width: 100%;">
|
| 156 |
+
</div>
|
| 157 |
+
<div style="margin: 10px 0;">
|
| 158 |
+
<label>Box Y Position: <span id="box-y-pos-value-step0">1.0</span>m</label><br>
|
| 159 |
+
<input type="range" id="box-y-pos-step0" min="-25.0" max="25.0" step="0.1" value="1.0" style="width: 100%;">
|
| 160 |
+
</div>
|
| 161 |
<div style="margin: 10px 0;">
|
| 162 |
+
<label>Box Z Position: <span id="box-z-pos-value-step0">0.0</span>m</label><br>
|
| 163 |
+
<input type="range" id="box-z-pos-step0" min="-25.0" max="25.0" step="0.1" value="0.0" style="width: 100%;">
|
| 164 |
+
</div>
|
| 165 |
+
|
| 166 |
+
<!-- PLY Offset Controls (Optional Fine-Tuning) -->
|
| 167 |
+
<h4 style="margin: 15px 0 10px 0; color: #2196F3;">🎯 Fine-tune PLY Position (Optional)</h4>
|
| 168 |
+
|
| 169 |
+
<div style="margin: 10px 0;">
|
| 170 |
+
<label>PLY X Offset: <span id="ply-x-value">0.0</span>m</label><br>
|
| 171 |
<input type="range" id="ply-x" min="-10.0" max="10.0" step="0.1" value="0.0" style="width: 100%;">
|
| 172 |
</div>
|
| 173 |
<div style="margin: 10px 0;">
|
| 174 |
+
<label>PLY Y Offset: <span id="ply-y-value">0.0</span>m</label><br>
|
| 175 |
<input type="range" id="ply-y" min="-10.0" max="10.0" step="0.1" value="0.0" style="width: 100%;">
|
| 176 |
</div>
|
| 177 |
<div style="margin: 10px 0;">
|
| 178 |
+
<label>PLY Z Offset: <span id="ply-z-value">0.0</span>m</label><br>
|
| 179 |
<input type="range" id="ply-z" min="-10.0" max="10.0" step="0.1" value="0.0" style="width: 100%;">
|
| 180 |
</div>
|
| 181 |
+
|
| 182 |
+
<button id="reset-all-btn" style="
|
| 183 |
margin-top: 10px;
|
| 184 |
padding: 8px 15px;
|
| 185 |
background: #FF9800;
|
|
|
|
| 189 |
cursor: pointer;
|
| 190 |
width: 48%;
|
| 191 |
margin-right: 2%;
|
| 192 |
+
">Reset All</button>
|
| 193 |
+
<button id="confirm-box-btn" style="
|
| 194 |
margin-top: 10px;
|
| 195 |
padding: 8px 15px;
|
| 196 |
background: #4CAF50;
|
|
|
|
| 199 |
border-radius: 5px;
|
| 200 |
cursor: pointer;
|
| 201 |
width: 48%;
|
| 202 |
+
">✓ Confirm & Filter</button>
|
| 203 |
</div>
|
|
|
|
| 204 |
|
| 205 |
<!-- Step 1: Box Adjustment -->
|
| 206 |
<div id="manual-controls" style="margin-top: 20px; display: none;">
|
|
|
|
| 885 |
// Keyboard Controls for Camera Movement: Deleted 12/13 13:50
|
| 886 |
// ========================================
|
| 887 |
|
| 888 |
+
////////////////////////////12/13 16:20 START
|
| 889 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 890 |
// ========================================
|
| 891 |
+
// Step 0: PLY Position Adjustment
|
| 892 |
// ========================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 893 |
|
| 894 |
+
// ========================================
|
| 895 |
+
// Step 0: Box and PLY Position Adjustment
|
| 896 |
+
// ========================================
|
|
|
|
| 897 |
|
| 898 |
+
ui.setStatus('Step 0: Adjust bounding box to frame your object');
|
| 899 |
+
ui.showPositionAdjustment();
|
| 900 |
+
|
| 901 |
+
// Calculate and display scene bounds
|
| 902 |
+
let minX = Infinity, minY = Infinity, minZ = Infinity;
|
| 903 |
+
let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
| 904 |
+
|
| 905 |
+
plyData.vertices.forEach(vertex => {
|
| 906 |
+
minX = Math.min(minX, vertex.x);
|
| 907 |
+
minY = Math.min(minY, vertex.y);
|
| 908 |
+
minZ = Math.min(minZ, vertex.z);
|
| 909 |
+
maxX = Math.max(maxX, vertex.x);
|
| 910 |
+
maxY = Math.max(maxY, vertex.y);
|
| 911 |
+
maxZ = Math.max(maxZ, vertex.z);
|
| 912 |
+
});
|
| 913 |
+
|
| 914 |
+
const sceneSize = {
|
| 915 |
+
x: maxX - minX,
|
| 916 |
+
y: maxY - minY,
|
| 917 |
+
z: maxZ - minZ
|
| 918 |
+
};
|
| 919 |
+
const sceneCenter = {
|
| 920 |
+
x: (maxX + minX) / 2,
|
| 921 |
+
y: (maxY + minY) / 2,
|
| 922 |
+
z: (maxZ + minZ) / 2
|
| 923 |
+
};
|
| 924 |
+
|
| 925 |
+
console.log('[preprocessManual] Scene bounds:', {
|
| 926 |
+
size: sceneSize,
|
| 927 |
+
center: sceneCenter
|
| 928 |
+
});
|
| 929 |
+
|
| 930 |
+
// Display scene info in UI
|
| 931 |
+
const sceneSizeEl = document.getElementById('scene-size');
|
| 932 |
+
const sceneCenterEl = document.getElementById('scene-center');
|
| 933 |
+
if (sceneSizeEl) {
|
| 934 |
+
sceneSizeEl.textContent = `${sceneSize.x.toFixed(1)}m × ${sceneSize.y.toFixed(1)}m × ${sceneSize.z.toFixed(1)}m`;
|
| 935 |
}
|
| 936 |
+
if (sceneCenterEl) {
|
| 937 |
+
sceneCenterEl.textContent = `(${sceneCenter.x.toFixed(1)}, ${sceneCenter.y.toFixed(1)}, ${sceneCenter.z.toFixed(1)})`;
|
| 938 |
+
}
|
| 939 |
+
|
| 940 |
+
// Initial box settings (conservative defaults)
|
| 941 |
+
let boxSize = { x: 3, y: 3, z: 3 };
|
| 942 |
+
let boxPosition = { x: 0, y: 1, z: 0 };
|
| 943 |
+
let plyOffset = { x: 0, y: 0, z: 0 };
|
| 944 |
+
|
| 945 |
+
const gsScene = gs.viewer.splatMesh.scenes[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 946 |
|
| 947 |
+
// Create initial bounding box
|
| 948 |
+
ui.createBoundingBox(boxSize, boxPosition);
|
| 949 |
|
| 950 |
+
// Box size sliders
|
| 951 |
+
const setupBoxSizeSlider = (id, valueId, axis) => {
|
| 952 |
const slider = document.getElementById(id);
|
| 953 |
const valueDisplay = document.getElementById(valueId);
|
| 954 |
|
|
|
|
| 956 |
slider.addEventListener('input', (e) => {
|
| 957 |
const value = parseFloat(e.target.value);
|
| 958 |
valueDisplay.textContent = value.toFixed(1);
|
| 959 |
+
boxSize[axis] = value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 960 |
ui.updateBoundingBox(boxSize, boxPosition);
|
| 961 |
});
|
| 962 |
}
|
| 963 |
};
|
| 964 |
+
|
| 965 |
+
// Box position sliders
|
| 966 |
+
const setupBoxPosSlider = (id, valueId, axis) => {
|
| 967 |
+
const slider = document.getElementById(id);
|
| 968 |
+
const valueDisplay = document.getElementById(valueId);
|
| 969 |
+
|
| 970 |
+
if (slider && valueDisplay) {
|
| 971 |
+
slider.addEventListener('input', (e) => {
|
| 972 |
+
const value = parseFloat(e.target.value);
|
| 973 |
+
valueDisplay.textContent = value.toFixed(1);
|
| 974 |
+
boxPosition[axis] = value;
|
| 975 |
+
ui.updateBoundingBox(boxSize, boxPosition);
|
| 976 |
+
});
|
| 977 |
+
}
|
| 978 |
+
};
|
| 979 |
+
|
| 980 |
+
// PLY offset sliders
|
| 981 |
+
const setupPlyOffsetSlider = (id, valueId, axis) => {
|
| 982 |
+
const slider = document.getElementById(id);
|
| 983 |
+
const valueDisplay = document.getElementById(valueId);
|
| 984 |
+
|
| 985 |
+
if (slider && valueDisplay) {
|
| 986 |
+
slider.addEventListener('input', (e) => {
|
| 987 |
+
const value = parseFloat(e.target.value);
|
| 988 |
+
valueDisplay.textContent = value.toFixed(1);
|
| 989 |
+
plyOffset[axis] = value;
|
| 990 |
+
gsScene.position[axis] = value;
|
| 991 |
+
gsScene.updateMatrixWorld();
|
| 992 |
+
});
|
| 993 |
+
}
|
| 994 |
+
};
|
| 995 |
+
|
| 996 |
+
// Setup all sliders
|
| 997 |
+
setupBoxSizeSlider('box-x-step0', 'box-x-value-step0', 'x');
|
| 998 |
+
setupBoxSizeSlider('box-y-step0', 'box-y-value-step0', 'y');
|
| 999 |
+
setupBoxSizeSlider('box-z-step0', 'box-z-value-step0', 'z');
|
| 1000 |
+
|
| 1001 |
+
setupBoxPosSlider('box-x-pos-step0', 'box-x-pos-value-step0', 'x');
|
| 1002 |
+
setupBoxPosSlider('box-y-pos-step0', 'box-y-pos-value-step0', 'y');
|
| 1003 |
+
setupBoxPosSlider('box-z-pos-step0', 'box-z-pos-value-step0', 'z');
|
| 1004 |
+
|
| 1005 |
+
setupPlyOffsetSlider('ply-x', 'ply-x-value', 'x');
|
| 1006 |
+
setupPlyOffsetSlider('ply-y', 'ply-y-value', 'y');
|
| 1007 |
+
setupPlyOffsetSlider('ply-z', 'ply-z-value', 'z');
|
| 1008 |
+
|
| 1009 |
+
// Reset button
|
| 1010 |
+
const resetAllBtn = document.getElementById('reset-all-btn');
|
| 1011 |
+
if (resetAllBtn) {
|
| 1012 |
+
resetAllBtn.addEventListener('click', () => {
|
| 1013 |
+
// Reset box
|
| 1014 |
+
boxSize = { x: 3, y: 3, z: 3 };
|
| 1015 |
+
boxPosition = { x: 0, y: 1, z: 0 };
|
| 1016 |
+
document.getElementById('box-x-step0').value = 3;
|
| 1017 |
+
document.getElementById('box-y-step0').value = 3;
|
| 1018 |
+
document.getElementById('box-z-step0').value = 3;
|
| 1019 |
+
document.getElementById('box-x-value-step0').textContent = '3.0';
|
| 1020 |
+
document.getElementById('box-y-value-step0').textContent = '3.0';
|
| 1021 |
+
document.getElementById('box-z-value-step0').textContent = '3.0';
|
| 1022 |
+
|
| 1023 |
+
document.getElementById('box-x-pos-step0').value = 0;
|
| 1024 |
+
document.getElementById('box-y-pos-step0').value = 1;
|
| 1025 |
+
document.getElementById('box-z-pos-step0').value = 0;
|
| 1026 |
+
document.getElementById('box-x-pos-value-step0').textContent = '0.0';
|
| 1027 |
+
document.getElementById('box-y-pos-value-step0').textContent = '1.0';
|
| 1028 |
+
document.getElementById('box-z-pos-value-step0').textContent = '0.0';
|
| 1029 |
+
|
| 1030 |
+
// Reset PLY offset
|
| 1031 |
+
plyOffset = { x: 0, y: 0, z: 0 };
|
| 1032 |
+
document.getElementById('ply-x').value = 0;
|
| 1033 |
+
document.getElementById('ply-y').value = 0;
|
| 1034 |
+
document.getElementById('ply-z').value = 0;
|
| 1035 |
+
document.getElementById('ply-x-value').textContent = '0.0';
|
| 1036 |
+
document.getElementById('ply-y-value').textContent = '0.0';
|
| 1037 |
+
document.getElementById('ply-z-value').textContent = '0.0';
|
| 1038 |
+
|
| 1039 |
+
gsScene.position.set(0, 0, 0);
|
| 1040 |
+
gsScene.updateMatrixWorld();
|
| 1041 |
+
ui.updateBoundingBox(boxSize, boxPosition);
|
| 1042 |
+
});
|
| 1043 |
+
}
|
| 1044 |
+
|
| 1045 |
+
// Confirm button
|
| 1046 |
+
const confirmBoxBtn = document.getElementById('confirm-box-btn');
|
| 1047 |
+
if (confirmBoxBtn) {
|
| 1048 |
+
confirmBoxBtn.addEventListener('click', async () => {
|
| 1049 |
+
console.log('[preprocessManual] Box confirmed:', { boxSize, boxPosition, plyOffset });
|
| 1050 |
|
|
|
|
| 1051 |
cleanupAnimation();
|
| 1052 |
|
| 1053 |
+
// Apply PLY offset if any
|
| 1054 |
+
if (plyOffset.x !== 0 || plyOffset.y !== 0 || plyOffset.z !== 0) {
|
| 1055 |
+
plyData.vertices.forEach(vertex => {
|
| 1056 |
+
vertex.x += plyOffset.x;
|
| 1057 |
+
vertex.y += plyOffset.y;
|
| 1058 |
+
vertex.z += plyOffset.z;
|
| 1059 |
+
});
|
| 1060 |
+
|
| 1061 |
+
await gs.viewer.dispose();
|
| 1062 |
+
|
| 1063 |
+
const newHeader = plyData.header;
|
| 1064 |
+
const newPlyData = parser.createPLYFile(newHeader, plyData.vertices, plyData.vertexSize);
|
| 1065 |
+
const blob = new Blob([newPlyData], { type: 'application/octet-stream' });
|
| 1066 |
+
const adjustedPlyUrl = URL.createObjectURL(blob);
|
| 1067 |
+
|
| 1068 |
+
gs = await GVRM.initGS(adjustedPlyUrl, undefined, undefined, scene);
|
| 1069 |
+
console.log('[preprocessManual] GS reloaded with adjusted position');
|
| 1070 |
+
}
|
| 1071 |
+
|
| 1072 |
+
ui.hidePositionAdjustment();
|
| 1073 |
+
ui.setStatus('Filtering splats with bounding box...');
|
| 1074 |
|
| 1075 |
+
// Filter splats immediately
|
| 1076 |
const filteredVertices = filterSplatsByBox(plyData, boxSize, boxPosition);
|
| 1077 |
|
| 1078 |
if (filteredVertices.length === 0) {
|
| 1079 |
+
alert('No splats found in the box! Please adjust the box size/position and try again.');
|
| 1080 |
+
ui.showPositionAdjustment();
|
|
|
|
| 1081 |
return;
|
| 1082 |
}
|
| 1083 |
|
| 1084 |
+
console.log(`[preprocessManual] Filtered ${filteredVertices.length}/${plyData.vertices.length} splats`);
|
| 1085 |
+
|
| 1086 |
+
// Create filtered PLY
|
| 1087 |
const filteredPlyUrl = createFilteredPLY(
|
| 1088 |
+
parser,
|
| 1089 |
+
plyData.header,
|
| 1090 |
+
filteredVertices,
|
| 1091 |
plyData.vertexSize
|
| 1092 |
);
|
| 1093 |
|
|
|
|
| 1108 |
// Create GVRM instance
|
| 1109 |
const gvrm = new GVRM(character, filteredGs);
|
| 1110 |
|
|
|
|
| 1111 |
ui.setStatus('Step 2: Assign splats to bones');
|
| 1112 |
+
ui.showBoneAssignment();
|
| 1113 |
|
| 1114 |
// ========================================
|
| 1115 |
// Step 2: Bone Assignment
|
| 1116 |
// ========================================
|
| 1117 |
const promise2 = setupBoneAssignment(
|
| 1118 |
+
ui, scene, camera, renderer,
|
| 1119 |
gvrm, character, filteredGs, filteredPlyUrl,
|
| 1120 |
vrmPath, useGPU, savePly, fileName,
|
| 1121 |
+
{ vertices: filteredVertices, header: plyData.header, vertexSize: plyData.vertexSize },
|
| 1122 |
+
plyData
|
| 1123 |
);
|
| 1124 |
|
|
|
|
| 1125 |
resolve({
|
| 1126 |
gvrm: gvrm,
|
| 1127 |
promise2: promise2,
|
| 1128 |
error: null,
|
| 1129 |
ui: ui
|
| 1130 |
});
|
|
|
|
| 1131 |
});
|
| 1132 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1133 |
|
| 1134 |
|
| 1135 |
+
// ========================================
|
| 1136 |
+
// Step 1: Bounding Box Adjustment Deleted
|
| 1137 |
+
// ========================================
|
| 1138 |
|
| 1139 |
+
////////////////////////////12/13 16:20 END
|
| 1140 |
+
|
| 1141 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1142 |
|
| 1143 |
// ========================================
|
| 1144 |
// Bone Assignment Setup Function
|