Offsetting the model in canvas without changing perspective

Abierto
#4,993 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 4 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
30/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
three.js, typescript

Línea de trabajo

Comienza examinando el comportamiento de la cámara de model-viewer descrito en el issue y la discusión relacionada en https://github.com/google/model-viewer/discussions/4733. El trabajo estará completo cuando se integre el desplazamiento horizontal del modelo sin cambiar la perspectiva, dar un salto al cargar ni romper los orbit controls, incluidos los casos de zoom y panning indicados.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

In my very specific use case, I had a model view with a specific perspective I could not change, which caused a visually asymmetric alignment. I wanted to offset the model in the canvas to make it look centered initially. I tried many things before finding the working solution I am sharing here. Specifically, I could not find a responsive CSS solution. Also it is quite difficult to trigger a view update without resetting the frame (tried e.g. updateProjectionMatrix, queueRender, requestUpdate, updateBoundingBox... nothing worked). I would like to see a more integrated way to do this. My solution has the issue of showing the model jumping on load, it requires zoom control to be enabled, and i did not test it with panning. But it is minimal, responsive, and preserve user orbit control. BTW, my solution is only for horizontal offset... Replace the .07 with your desired horizontal shift fraction.

Image

<model-viewer onload="align(this, .07)" ...

function align(mv, dx) {
    const scene = mv[Object.getOwnPropertySymbols(mv).find(e => e.description == 'scene')]
    new ResizeObserver(() => {
        scene.camera.filmOffset = scene.camera.getFilmWidth() * dx
        mv.zoom(.001 * Math.sign(mv.zoomSensitivity))  // Trigger a view update without resetting the framing. Requires zoom to not be disabled and not be at maximum zoom-in
    }).observe(mv)
}

Edit: Multiplying by the sign of the zoom sensitivity is for the edge case where you set the zoom sensitivity to be negative and you start at maximum zoom-out

Might be related:
https://github.com/google/model-viewer/discussions/4733

Lenguaje dominante
TypeScript
Estrellas
8.4k
Forks
964
Merge medio
5 d 11 h
PR fusionados (30 d)
8

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de google/model-viewer

Todos los issues de google/model-viewer

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.