tiny_obj 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cb4b288a4c32292401439d4431e618b20db9feb501536521dfc73df992c9297
4
- data.tar.gz: 83dc33eeb7db6cd9c80da7cbfe2bac6fcd89a714e802f50e827046a1ec74830b
3
+ metadata.gz: 1cb16c82d54588fd6f63383314bd351e4f908d093f0330f72d81f6aa76e826cb
4
+ data.tar.gz: baed73918e0f7f90fb05192940a28457d4e14e282f5616eaecf28f37f8b7b2d6
5
5
  SHA512:
6
- metadata.gz: 9433112c3fa3db15ac7d8aa80cfda608d6959f979dc6b957e9e44a7c0c4045794ad1e94eb55b9371070907691df3c42678693d95993243b9d97ade144baf9bd2
7
- data.tar.gz: fb56c01fbfb2ffa382b2b2ddba6d36a87e65e468787bc253ddfda15a69be6f8aa787bb14c01416dbcb5f6f342a20494a85c8811c36b1373b7ac3270e82cae498
6
+ metadata.gz: 5b3548ab188a5ecec6b902cd14c5a59c6fd19a17ae35e17050e09fcf378a321e8b7721912f666418b224666251297ff890ccd09b869d29973079931668f98af4
7
+ data.tar.gz: 132f5624215350be97b4f4b13e87f7f7577820fce2198b26541a1e1d5e91aca0557ecf574f10b4f979506c71aa9b998ed9d5148ca47cc75d43cc3abc62318f37
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tiny_obj (0.2.0)
4
+ tiny_obj (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -24,10 +24,46 @@ Or install it yourself as:
24
24
  require 'tiny_obj'
25
25
  obj = TinyOBJ.load("path/to/file.obj") # finds materials in /path/to
26
26
  obj = TinyOBJ.load("path/to/file.obj", "path/to/materials/dir")
27
- #=> obj is a hash containing :materials, :vertices, :shapes, and other
27
+
28
+ hash = obj.to_hash
29
+ #=> hash is a hash containing :materials, :vertices, :shapes, and other
28
30
  # goodness.
29
31
  ```
30
32
 
33
+ Converting the OBJ into a hash is convenient but not performant. If you are
34
+ dealing with a large object, you may wish to fill a buffer with data without
35
+ having to convert it into Ruby hashes, arrays and numbers. You can do that
36
+ with TinyOBJ#fill_buffers. Below is a complete example, which uses Fiddle to
37
+ allocate the buffer.
38
+
39
+ **Note** that using Fiddle is not required (but is convenient since it ships
40
+ with Ruby). Only knowing the memory address of the buffer is necessary. Be
41
+ aware that using the wrong address or not a real (or adequately-sized) buffer
42
+ can lead to undefined behavior and program crashes.
43
+
44
+ ```ruby
45
+ vertex_stride = Fiddle::SIZEOF_FLOAT * (
46
+ 3 + # 3 floats for each position (x, y, z)
47
+ 3 + # 3 floats for each normal (x, y, z)
48
+ 2 # 2 floats for each texture coord (u, v)
49
+ )
50
+
51
+ index_stride = 2 # each index will be one uint16, or two 8-bit bytes
52
+ vertex_buffer = Fiddle::Pointer.malloc(@obj.num_distinct_vertices * vertex_stride)
53
+ index_buffer = Fiddle::Pointer.malloc(@obj.num_indices * index_stride)
54
+
55
+ @obj.fill_buffers(positions: vertex_buffer,
56
+ normals: vertex_buffer + Fiddle::SIZEOF_FLOAT * 3,
57
+ texcoords: vertex_buffer + Fiddle::SIZEOF_FLOAT * 6,
58
+ indices: index_buffer,
59
+ vertex_stride: vertex_stride,
60
+ index_stride: index_stride,
61
+ index_type: :uint16)
62
+
63
+ # vertex_buffer now contains interleaved vertex data, and
64
+ # index_buffer now contains index data.
65
+ ```
66
+
31
67
  ## Development
32
68
 
33
69
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,3 +1,3 @@
1
1
  module TinyOBJ
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_obj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin MacKenzie IV
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-17 00:00:00.000000000 Z
11
+ date: 2018-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler