f3d-app / f3d

Fast and minimalist 3D viewer.
https://f3d.app
BSD 3-Clause "New" or "Revised" License
2.88k stars 207 forks source link

API to read scene data #1628

Open Nokse22 opened 1 month ago

Nokse22 commented 1 month ago

Description

A method to read scene data from code, it should output a json with the available data about the loaded scene

Now when loading a scene with debug enabled it is already possible to read information

Example

Copied from the terminal

Found a reader for "/run/user/1000/doc/bf697a76/planet_reducer_animation.glb" : "GLTF"
Loading 3D scene: /run/user/1000/doc/bf697a76/planet_reducer_animation.glb

Animation(s) available in this file are:
0: Take 001

Animation(s) time range is: [0, 19.7333].
No camera available in this file

Object004__0 Primitive Geometry:
 Number of points: 624
 Number of polygons: 636
 Number of lines: 0
 Number of vertices: 0
 2 point data array(s):
   NORMAL : float : [-1, 1] [-1, 1] [-1, 1] 
   TEXCOORD_0 : float : [0.00139806, 0.283058] [0.493429, 0.950484] 
 0 cell data array(s):
 0 field data array(s):
Cylinder051__0 Primitive Geometry:
 Number of points: 810
 Number of polygons: 828
 Number of lines: 0
 Number of vertices: 0
 2 point data array(s):
   NORMAL : float : [-1, 1] [-1, 1] [-1, 1] 
   TEXCOORD_0 : float : [0.00139806, 0.283058] [0.493429, 0.950484] 
 0 cell data array(s):
 0 field data array(s):
starmed1__0 Primitive Geometry:
 Number of points: 8735
 Number of polygons: 7397
 Number of lines: 0
 Number of vertices: 0
 2 point data array(s):
   NORMAL : float : [-1, 1] [-0.999993, 0.999951] [-0.999992, 0.999999] 
   TEXCOORD_0 : float : [-0.0117864, 1.00782] [-0.03208, 1] 
 0 cell data array(s):
 0 field data array(s):
starmed3__0 Primitive Geometry:
 Number of points: 8735
 Number of polygons: 7397
 Number of lines: 0
 Number of vertices: 0
 2 point data array(s):
   NORMAL : float : [-1, 1] [-1, 1] [-1, 1] 
   TEXCOORD_0 : float : [-0.0117864, 1.00782] [-0.03208, 1] 
 0 cell data array(s):
 0 field data array(s):
starmed2__0 Primitive Geometry:
 Number of points: 8734
 Number of polygons: 7397
 Number of lines: 0
 Number of vertices: 0
 2 point data array(s):
   NORMAL : float : [-1, 1] [-1, 0.999993] [-0.999987, 0.999984] 
   TEXCOORD_0 : float : [-0.0117864, 1.00782] [-0.03208, 1] 
 0 cell data array(s):
 0 field data array(s):
starsmall__0 Primitive Geometry:
 Number of points: 4372
 Number of polygons: 3980
 Number of lines: 0
 Number of vertices: 0
 2 point data array(s):
   NORMAL : float : [-1, 1] [-0.999995, 0.999983] [-0.999981, 0.999996] 
   TEXCOORD_0 : float : [0.0011656, 0.998834] [0.00465703, 1] 
 0 cell data array(s):
 0 field data array(s):
starbig__0 Primitive Geometry:
 Number of points: 6318
 Number of polygons: 5670
 Number of lines: 0
 Number of vertices: 0
 2 point data array(s):
   NORMAL : float : [-1, 1] [-0.999996, 0.999992] [-0.999991, 0.999994] 
   TEXCOORD_0 : float : [0.988328, 0.999277] [0, 0] 
 0 cell data array(s):
 0 field data array(s):

Scene bounding box: 205.729,331.206,-97.0925,99.6823,-150.93,43.1112

Camera position: 268.468,1.29489,626.074
Camera focal point: 268.468,1.29489,-53.9092
Camera view up: 0,1,0
Camera view angle: 30

Using grid unit square size = 10
Grid origin set to [268.468, -97.1023, -53.9092]

It could be formatted something like this (made with LLM)

{
  "file": {
    "path": "/run/user/1000/doc/bf697a76/planet_reducer_animation.glb",
    "type": "GLTF",
    "3D_scene_loading": true,
    "animations": [
      {
        "index": 0,
        "name": "Take 001",
        "time_range": [0, 19.7333]
      }
    ],
    "camera": {
      "available": false
    },
    "objects": [
      {
        "name": "Object004__0",
        "primitive_geometry": {
          "points": 624,
          "polygons": 636,
          "lines": 0,
          "vertices": 0,
          "point_data_arrays": [
            {
              "name": "NORMAL",
              "type": "float",
              "values": [[-1, 1], [-1, 1], [-1, 1]]
            },
            {
              "name": "TEXCOORD_0",
              "type": "float",
              "values": [[0.00139806, 0.283058], [0.493429, 0.950484]]
            }
          ],
          "cell_data_arrays": [],
          "field_data_arrays": []
        }
      },
      {
        "name": "Cylinder051__0",
        "primitive_geometry": {
          "points": 810,
          "polygons": 828,
          "lines": 0,
          "vertices": 0,
          "point_data_arrays": [
            {
              "name": "NORMAL",
              "type": "float",
              "values": [[-1, 1], [-1, 1], [-1, 1]]
            },
            {
              "name": "TEXCOORD_0",
              "type": "float",
              "values": [[0.00139806, 0.283058], [0.493429, 0.950484]]
            }
          ],
          "cell_data_arrays": [],
          "field_data_arrays": []
        }
      },
      {
        "name": "starmed1__0",
        "primitive_geometry": {
          "points": 8735,
          "polygons": 7397,
          "lines": 0,
          "vertices": 0,
          "point_data_arrays": [
            {
              "name": "NORMAL",
              "type": "float",
              "values": [[-1, 1], [-0.999993, 0.999951], [-0.999992, 0.999999]]
            },
            {
              "name": "TEXCOORD_0",
              "type": "float",
              "values": [[-0.0117864, 1.00782], [-0.03208, 1]]
            }
          ],
          "cell_data_arrays": [],
          "field_data_arrays": []
        }
      },
      {
        "name": "starmed3__0",
        "primitive_geometry": {
          "points": 8735,
          "polygons": 7397,
          "lines": 0,
          "vertices": 0,
          "point_data_arrays": [
            {
              "name": "NORMAL",
              "type": "float",
              "values": [[-1, 1], [-1, 1], [-1, 1]]
            },
            {
              "name": "TEXCOORD_0",
              "type": "float",
              "values": [[-0.0117864, 1.00782], [-0.03208, 1]]
            }
          ],
          "cell_data_arrays": [],
          "field_data_arrays": []
        }
      },
      {
        "name": "starmed2__0",
        "primitive_geometry": {
          "points": 8734,
          "polygons": 7397,
          "lines": 0,
          "vertices": 0,
          "point_data_arrays": [
            {
              "name": "NORMAL",
              "type": "float",
              "values": [[-1, 1], [-1, 0.999993], [-0.999987, 0.999984]]
            },
            {
              "name": "TEXCOORD_0",
              "type": "float",
              "values": [[-0.0117864, 1.00782], [-0.03208, 1]]
            }
          ],
          "cell_data_arrays": [],
          "field_data_arrays": []
        }
      },
      {
        "name": "starsmall__0",
        "primitive_geometry": {
          "points": 4372,
          "polygons": 3980,
          "lines": 0,
          "vertices": 0,
          "point_data_arrays": [
            {
              "name": "NORMAL",
              "type": "float",
              "values": [[-1, 1], [-0.999995, 0.999983], [-0.999981, 0.999996]]
            },
            {
              "name": "TEXCOORD_0",
              "type": "float",
              "values": [[0.0011656, 0.998834], [0.00465703, 1]]
            }
          ],
          "cell_data_arrays": [],
          "field_data_arrays": []
        }
      },
      {
        "name": "starbig__0",
        "primitive_geometry": {
          "points": 6318,
          "polygons": 5670,
          "lines": 0,
          "vertices": 0,
          "point_data_arrays": [
            {
              "name": "NORMAL",
              "type": "float",
              "values": [[-1, 1], [-0.999996, 0.999992], [-0.999991, 0.999994]]
            },
            {
              "name": "TEXCOORD_0",
              "type": "float",
              "values": [[0.988328, 0.999277], [0, 0]]
            }
          ],
          "cell_data_arrays": [],
          "field_data_arrays": []
        }
      }
    ],
    "scene_bounding_box": {
      "x_min": 205.729,
      "x_max": 331.206,
      "y_min": -97.0925,
      "y_max": 99.6823,
      "z_min": -150.93,
      "z_max": 43.1112
    },
    "camera_position": [268.468, 1.29489, 626.074],
    "camera_focal_point": [268.468, 1.29489, -53.9092],
    "camera_view_up": [0, 1, 0],
    "camera_view_angle": 30,
    "grid": {
      "unit_square_size": 10,
      "origin": [268.468, -97.1023, -53.9092]
    }
  }
}
mwestphal commented 1 month ago

This requires quite a bit of work but the will be possible in the middle term future.