collada 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDZkOGNmM2E0ZDBkMjE5MzA1MDBkNWZjZTc4YmNmZWQ2ZDVkOWMxZA==
4
+ OTJlZDlkNTNiNmRjYTYxZGE3OGNmZjFiODhmNjA2YmM2OTIzMjdmMw==
5
5
  data.tar.gz: !binary |-
6
- M2Y0YTUwZTQ1NjU0MThmNjMwMzhkOWYyYTVmZmJiYmE5ODY0MGM4ZQ==
6
+ YmUzNjhjY2UxMGZkYmNjYzhjM2ZkZWMxNTIyMTU4NjhiZWRkNjI0Mg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OTY4YzFjNDRmYjhlMDJmYmQ2YjQ1NzgxMDdmZjE4NTVmZjM1Y2FlMjM0ODRh
10
- ZDRkODA3ZjUzY2ZhZWNjZTAyNjYxNjk0YWUyNjNkN2E0Y2RlN2Q5MjIzM2Ji
11
- NzUyNmQ3YzBlZmRjM2QwOTFkOGI2OWJkZGU4ZTY2Zjk5ODlhOWI=
9
+ ZDdhYmU5NjdhYTQyZWQxYmE5NTVhYTJiNzIzYjJlNDFlZmFiNWNjNThlMDEz
10
+ ZDRkMmE3MTcyMGViZGYxMWZjYWQ3MTc2MjA0NjNiMTU0OWRhZWQxOTk5OGQ3
11
+ ZDNmOGY5NGZiMmNjOTk1NWQ1MTA1YjBmMGRmODhlNmY2MmE0NmM=
12
12
  data.tar.gz: !binary |-
13
- YTBkMTc3ZjZiZWEyN2I4ZTgzNzY0ZDUyZjhkNTY2NDFkMjUyNWU1YzZkYWEy
14
- Mzc2NTE0MDNmNDY5ZmNkMzcyZTk3YmI3NGNiYTc0MjkwNjAxM2U5MDRkODE1
15
- NmExOTk5YTcxYTMzZjE2ZDkxNzFkMjZlZGRmM2E0MzBlZDBiNGQ=
13
+ OTg3OTAzNGRkNmM3NmZiZmNkMzcyYTRiMWViMTRmNjBkZTdlZjNhZWFkMjg3
14
+ NjVkNjhlYjQyODE3NzJmZTNiMzkzYTYzMDE3NjkxMDA2OTQ3YzM5ODAyZjM1
15
+ ZjY2YmJhZmI5ZmRkYzUwZDA2ZjVjNzcwY2I1ZWFhODQ2ODllYjU=
@@ -2,13 +2,18 @@
2
2
  module Collada
3
3
  module Conversion
4
4
  class TaggedFormat
5
+ class GeometryError < StandardError
6
+ end
7
+
8
+ TEXCOORD = lambda {|value| [value[:S], -value[:T] + 1.0]}
9
+
5
10
  VERTEX_FORMATS = {
6
11
  "p3n3" => VertexFormat[position: [:X, :Y, :Z], normal: [:X, :Y, :Z]],
7
- "p3n3m2" => VertexFormat[position: [:X, :Y, :Z], normal: [:X, :Y, :Z], texcoord: [:S, :T]],
8
- "p3n3m2b2" => VertexFormat[position: [:X, :Y, :Z], normal: [:X, :Y, :Z], texcoord: [:S, :T], bones: WeightFormat[4]],
9
- "p3n3m2b4" => VertexFormat[position: [:X, :Y, :Z], normal: [:X, :Y, :Z], texcoord: [:S, :T], bones: WeightFormat[4]],
12
+ "p3n3m2" => VertexFormat[position: [:X, :Y, :Z], normal: [:X, :Y, :Z], texcoord: TEXCOORD],
13
+ "p3n3m2b2" => VertexFormat[position: [:X, :Y, :Z], normal: [:X, :Y, :Z], texcoord: TEXCOORD, bones: WeightFormat[4]],
14
+ "p3n3m2b4" => VertexFormat[position: [:X, :Y, :Z], normal: [:X, :Y, :Z], texcoord: TEXCOORD, bones: WeightFormat[4]],
10
15
  }
11
-
16
+
12
17
  def initialize(options, library, output = nil)
13
18
  @options = options
14
19
  @library = library
@@ -20,7 +25,13 @@ module Collada
20
25
  @top = {}
21
26
  @nodes = {}
22
27
  end
23
-
28
+
29
+ def extract_axes(scene, node, instance)
30
+ node.children.collect do |child|
31
+ [child.name, *Transforms.extract_axis(child.local_transform_matrix)]
32
+ end
33
+ end
34
+
24
35
  def dump_geometry(scene, node, instance, skeleton = nil)
25
36
  vertex_format = @output_vertex_format.with_vertex_index
26
37
  geometry = instance.lookup(@library)
@@ -30,6 +41,10 @@ module Collada
30
41
  weights = skeleton.indexed_weights if skeleton
31
42
 
32
43
  geometry.mesh.polygons.each do |polygon|
44
+ if polygon.count != 3
45
+ raise GeometryError.new("Non-triangular surfaces ")
46
+ end
47
+
33
48
  polygon.each do |vertex_attributes|
34
49
  vertex = Collada::Conversion::Vertex.new(vertex_attributes, vertex_format)
35
50
 
@@ -38,9 +53,9 @@ module Collada
38
53
  mesh << vertex
39
54
  end
40
55
  end
41
-
56
+
42
57
  @output.puts "#{geometry.id}: mesh triangles"
43
-
58
+
44
59
  @output.puts " indices: array index16"
45
60
  mesh.indices.each_slice(12) do |indices|
46
61
  @output.puts " #{indices.flatten.collect{|i| i.to_s.rjust(5)}.join}"
@@ -54,6 +69,14 @@ module Collada
54
69
  end
55
70
  @output.puts " end"
56
71
 
72
+ axes = extract_axes(scene, node, instance)
73
+
74
+ @output.puts " axes: array axis"
75
+ axes.each do |axis|
76
+ @output.puts " #{axis.collect{|i| i.to_s.rjust(12)}.join(' ')}"
77
+ end
78
+ @output.puts " end"
79
+
57
80
  @output.puts "end"
58
81
 
59
82
  @top[geometry.name || geometry.id] = geometry.id
@@ -67,8 +67,9 @@ module Collada
67
67
  ]
68
68
 
69
69
  class Node
70
- def initialize(id, type, transforms, instances, children, attributes = {})
70
+ def initialize(id, name, type, transforms, instances, children, attributes = {})
71
71
  @id = id
72
+ @name = name
72
73
  @type = type
73
74
 
74
75
  @transforms = transforms
@@ -88,6 +89,7 @@ module Collada
88
89
  attr :parent
89
90
 
90
91
  attr :id
92
+ attr :name
91
93
  attr :type
92
94
 
93
95
  attr :transforms
@@ -158,13 +160,14 @@ module Collada
158
160
 
159
161
  def self.parse(doc, element)
160
162
  id = element.attributes['id']
163
+ name = element.attributes['name']
161
164
  type = (element.attributes['type'] || 'node').downcase.to_sym
162
165
 
163
166
  transforms = parse_transforms(doc, element)
164
167
  instances = parse_instances(doc, element)
165
168
  children = parse_children(doc, element)
166
169
 
167
- self.new(id, type, transforms, instances, children, element.attributes)
170
+ self.new(id, name, type, transforms, instances, children, element.attributes)
168
171
  end
169
172
  end
170
173
 
@@ -107,5 +107,10 @@ module Collada
107
107
 
108
108
  return product
109
109
  end
110
+
111
+ def self.extract_axis(matrix)
112
+ # Transform [x, y, z], Rotation [x, y, z, w]
113
+ [matrix[0, 3], matrix[1, 3], matrix[2, 3], *rotation_matrix_to_quaternion(matrix)]
114
+ end
110
115
  end
111
116
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Collada
22
- VERSION = "0.2.0"
22
+ VERSION = "0.2.1"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collada
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
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-15 00:00:00.000000000 Z
11
+ date: 2013-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow