LoadCamera creates and returns a Camera Node from the specified GLTF.Cameras index.
(camIdx int)
| 393 | // LoadCamera creates and returns a Camera Node |
| 394 | // from the specified GLTF.Cameras index. |
| 395 | func (g *GLTF) LoadCamera(camIdx int) (core.INode, error) { |
| 396 | |
| 397 | // Check if provided camera index is valid |
| 398 | if camIdx < 0 || camIdx >= len(g.Cameras) { |
| 399 | return nil, fmt.Errorf("invalid camera index") |
| 400 | } |
| 401 | log.Debug("Loading Camera %d", camIdx) |
| 402 | camData := g.Cameras[camIdx] |
| 403 | |
| 404 | aspect := float32(2) // TODO how to get the current aspect ratio of the viewport from here ? |
| 405 | |
| 406 | if camData.Type == "perspective" { |
| 407 | desc := camData.Perspective |
| 408 | fov := 360 * (desc.Yfov) / 2 * math32.Pi |
| 409 | if desc.AspectRatio != nil { |
| 410 | aspect = *desc.AspectRatio |
| 411 | } |
| 412 | far := float32(2e6) |
| 413 | if desc.Zfar != nil { |
| 414 | far = *desc.Zfar |
| 415 | } |
| 416 | cam := camera.NewPerspective(aspect, desc.Znear, far, fov, camera.Vertical) |
| 417 | return cam, nil |
| 418 | } |
| 419 | |
| 420 | if camData.Type == "orthographic" { |
| 421 | desc := camData.Orthographic |
| 422 | cam := camera.NewOrthographic(aspect, desc.Znear, desc.Zfar, desc.Ymag, camera.Vertical) |
| 423 | return cam, nil |
| 424 | |
| 425 | } |
| 426 | |
| 427 | return nil, fmt.Errorf("unsupported camera type: %s", camData.Type) |
| 428 | } |
| 429 | |
| 430 | // LoadMesh creates and returns a Graphic Node (graphic.Mesh, graphic.Lines, graphic.Points, etc) |
| 431 | // from the specified GLTF.Meshes index. |
no test coverage detected