Skip to content

How to fit camera to model #74

Answered by jnsmalm
goldenratio asked this question in Q&A
Discussion options

You must be logged in to vote

Hey,

First you need to calculate the bounds of the model.

const getMeshBounds = (mesh) => {
    let min = PIXI3D.Vec3.transformMat4(
      mesh.geometry.positions.min, mesh.worldTransform.array)
    let max = PIXI3D.Vec3.transformMat4(
      mesh.geometry.positions.max, mesh.worldTransform.array)
    for (let i = 0; i < 3; i++) {
      let temp = min[i]
      min[i] = Math.min(min[i], max[i])
      max[i] = Math.max(temp, max[i])
    }
    return { min, max }
  }

  const getModelBounds = (model) => {
    model.updateTransform()
    let modelBounds = getMeshBounds(model.meshes[0])
    for (let i = 1; i < model.meshes.length; i++) {
      let meshBounds = getMeshBounds(model.meshes[i])
      

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jnsmalm
Comment options

@goldenratio
Comment options

Answer selected by goldenratio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants