MCPcopy
hub / github.com/g3n/engine / LoadCamera

Method LoadCamera

loader/gltf/loader.go:395–428  ·  view source on GitHub ↗

LoadCamera creates and returns a Camera Node from the specified GLTF.Cameras index.

(camIdx int)

Source from the content-addressed store, hash-verified

393// LoadCamera creates and returns a Camera Node
394// from the specified GLTF.Cameras index.
395func (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.

Callers 1

LoadNodeMethod · 0.95

Calls 3

NewPerspectiveFunction · 0.92
NewOrthographicFunction · 0.92
DebugMethod · 0.80

Tested by

no test coverage detected