cgltf-cr
cgltf-cr
Crystal bindings CGltf
Installation
-
Add the dependency to your
shard.yml:dependencies: cgltf: github: guidipolito/cgltf-cr -
Run
shards install
Usage
require "cgltf"
filepath = "./src/example/test3.glb"
obj = Cgltf.load_file(filepath)
primitive = obj.meshes.first.primitives.first
p primitive.positions.not_nil! # Print vertice positions
p primitive.normals.not_nil! # print vertice normals
p primitive.texcoords(0) # print UVs
example making an array for a Vertex Buffer Object
pri = obj.meshes.first.primitives.first
positions = pri.positions.not_nil!.map(&.to_f32).each_slice(3).to_a # make an array of vertices [ [x, y, z] ...]
normals = pri.normals.not_nil!.map(&.to_f32).each_slice(3).to_a # same thing for normals
uv = pri.texcoords(0).not_nil!.map(&.to_f32).each_slice(2).to_a # uvs [ [x, y], [x, y]]
vertices = [] of Float32
(0...positions.size).each do |i|
vertices << positions[i][0]
vertices << positions[i][1]
vertices << positions[i][2]
vertices << normals[i][0]
vertices << normals[i][1]
vertices << normals[i][2]
vertices << uv[i][0]
vertices << uv[i][1]
end
# vertice array for passing to opengl with [ px, py, pz, nx, ny, nz, uvx, uvy]

Contributing
- Fork it (https://github.com/guidipolito/cgltf-cr/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- guidipolito - creator and maintainer
Repository
cgltf-cr
Owner
Statistic
- 0
- 0
- 0
- 0
- 0
- about 3 hours ago
- July 12, 2026
License
MIT License
Links
Synced at
Sun, 12 Jul 2026 19:00:40 GMT
Languages