@@ -140,7 +140,7 @@ document.addEventListener('DOMContentLoaded', async function() {
140
140
}
141
141
142
142
// Clamp zoom limits
143
- zoomFactor = Math . max ( 1 , Math . min ( 20 , zoomFactor ) ) ;
143
+ zoomFactor = Math . max ( 0.001 , Math . min ( 50 , zoomFactor ) ) ;
144
144
145
145
// Apply the new zoom level
146
146
updateOrthoCamera ( ) ;
@@ -166,16 +166,16 @@ document.addEventListener('DOMContentLoaded', async function() {
166
166
camera . panningAxis = new BABYLON . Vector3 ( 1 , 1 , 0 ) ; // Only allow panning in X and Y
167
167
168
168
// Create a simple ground
169
- const ground = BABYLON . MeshBuilder . CreateGround ( 'ground' , { width : 50 , height : 50 } , scene ) ;
170
- const groundMaterial = new BABYLON . StandardMaterial ( 'groundMat' , scene ) ;
171
- groundMaterial . diffuseColor = new BABYLON . Color3 ( 0.2 , 0.2 , 0.2 ) ;
172
- groundMaterial . specularColor = new BABYLON . Color3 ( 0 , 0 , 0 ) ;
173
- groundMaterial . alpha = 0 ; // Make the ground transparent
174
- ground . material = groundMaterial ;
175
- ground . position . y = 0 ;
169
+ // const ground = BABYLON.MeshBuilder.CreateGround('ground', {width: 50, height: 50}, scene);
170
+ // const groundMaterial = new BABYLON.StandardMaterial('groundMat', scene);
171
+ // groundMaterial.diffuseColor = new BABYLON.Color3(0.2, 0.2, 0.2);
172
+ // groundMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
173
+ // groundMaterial.alpha = 0; // Make the ground transparent
174
+ // ground.material = groundMaterial;
175
+ // ground.position.y = 0;
176
176
177
177
// Try to load the character model
178
- await loadCharacterModel ( ) ;
178
+ // await loadCharacterModel();
179
179
180
180
// Create camera adjustment UI
181
181
createCameraControls ( ) ;
@@ -186,6 +186,67 @@ document.addEventListener('DOMContentLoaded', async function() {
186
186
return scene ;
187
187
} ;
188
188
189
+ // Add this after the createScene function but before the event listeners
190
+
191
+ function replaceCharacter ( container ) {
192
+ if ( ! scene ) return ;
193
+
194
+ // Clear previous character completely
195
+ if ( window . currentCharacter ) {
196
+ // Stop and dispose all animations
197
+ scene . animationGroups . slice ( ) . forEach ( group => {
198
+ group . stop ( ) ;
199
+ group . dispose ( ) ;
200
+ } ) ;
201
+
202
+ // Remove all meshes related to current character
203
+ scene . meshes . slice ( ) . forEach ( mesh => {
204
+ if ( mesh !== scene . ground ) { // Keep the ground
205
+ mesh . dispose ( ) ;
206
+ }
207
+ } ) ;
208
+
209
+ // Clear any skeletons
210
+ scene . skeletons . slice ( ) . forEach ( skeleton => {
211
+ skeleton . dispose ( ) ;
212
+ } ) ;
213
+
214
+ window . currentCharacter = null ;
215
+ window . currentAnimationGroup = null ;
216
+ }
217
+
218
+ // Add new meshes and animations
219
+ container . addAllToScene ( ) ;
220
+ window . currentCharacter = container . meshes [ 0 ] ;
221
+ window . animationGroups = container . animationGroups ;
222
+
223
+ // Position the new character
224
+ window . currentCharacter . position = new BABYLON . Vector3 ( 0 , 0 , 0 ) ;
225
+ window . currentCharacter . rotation = new BABYLON . Vector3 ( 0 , Math . PI / 2 , 0 ) ;
226
+ window . currentCharacter . scaling = new BABYLON . Vector3 ( 1 , 1 , 1 ) ;
227
+
228
+ // Update animation list
229
+ const animationList = document . getElementById ( 'animationList' ) ;
230
+ animationList . innerHTML = '' ;
231
+ container . animationGroups . forEach ( ( group , index ) => {
232
+ const option = document . createElement ( 'option' ) ;
233
+ option . value = index ;
234
+ option . text = group . name ;
235
+ animationList . appendChild ( option ) ;
236
+ } ) ;
237
+
238
+ // Play first animation if available
239
+ if ( container . animationGroups . length > 0 ) {
240
+ window . currentAnimationGroup = container . animationGroups [ 0 ] ;
241
+ window . currentAnimationGroup . start ( true ) ;
242
+ }
243
+
244
+ return window . currentCharacter ;
245
+ }
246
+
247
+ // Make the function globally accessible
248
+ window . replaceCharacter = replaceCharacter ;
249
+
189
250
// Function to try loading the character model with fallbacks
190
251
async function loadCharacterModel ( ) {
191
252
showStatus ( "Loading character model..." ) ;
0 commit comments