Is there a way to determine the size and position of the model, and then the auto center and scale the model so that it is located at the beginning and at the point of view of the camera? I find that when I import a Collada model from Sketchup, if the model was not centered at the origin in Sketchup, then it is not centered on three .js. Although this makes sense, it would be nice to automatically autocenter your original position after import.
I saw some discussion in different file downloaders about getting the boundaries of the imported model, but I could not find any links to this.
The scaling issue is less important, but I feel it is related to the border function, so I asked it too.
EDIT:
Additional information after the game a little and a few more Google searches ...
The code for my callback function when loading the collada file now looks like this:
loader.load(mURL, function colladaReady( collada ) { dae = collada.scene; skin = collada.skins[ 0 ]; dae.scale.x = dae.scale.y = dae.scale.z = 1; dae.updateMatrix(); //set arbitrary min and max for comparison var minX = 100000; var minY = 100000; var minZ = 100000; var maxX = 0; var maxY = 0; var maxZ = 0; var geometries = collada.dae.geometries; for(var propName in geometries){ if(geometries.hasOwnProperty(propName) && geometries[propName].mesh){ dae.geometry = geometries[propName].mesh.geometry3js; dae.geometry.computeBoundingBox(); bBox = dae.geometry.boundingBox; if(bBox.min.x < minX) minX = bBox.min.x; if(bBox.min.y < minY) minY = bBox.min.x; if(bBox.min.z < minZ) minZ = bBox.min.z; if(bBox.max.x > maxX) maxX = bBox.max.x; if(bBox.max.y > maxY) maxY = bBox.max.x; if(bBox.max.z > maxZ) maxZ = bBox.max.z; } } //rest of function....
This generates some interesting model data. I can get the general extreme coordinate for the model, which I suppose (possibly incorrectly) to be close to the general bounding box for the model. But an attempt to do something with these coordinates (for example, averaging and moving the model to average values) gives rise to inconsistent results.
In addition, it seems that it is inefficient to punch every geometry for the model, is there a better way? If not, can this logic apply to other bootloaders?
source share