collada 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,211 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
3
+ <asset>
4
+ <contributor>
5
+ <author>Blender User</author>
6
+ <authoring_tool>Blender 2.64.0 r51026</authoring_tool>
7
+ </contributor>
8
+ <created>2012-11-02T18:13:46</created>
9
+ <modified>2012-11-02T18:13:46</modified>
10
+ <unit name="meter" meter="1"/>
11
+ <up_axis>Z_UP</up_axis>
12
+ </asset>
13
+ <library_cameras>
14
+ <camera id="Camera-camera" name="Camera">
15
+ <optics>
16
+ <technique_common>
17
+ <perspective>
18
+ <xfov sid="xfov">49.13434</xfov>
19
+ <aspect_ratio>1.777778</aspect_ratio>
20
+ <znear sid="znear">0.1</znear>
21
+ <zfar sid="zfar">100</zfar>
22
+ </perspective>
23
+ </technique_common>
24
+ </optics>
25
+ </camera>
26
+ </library_cameras>
27
+ <library_lights>
28
+ <light id="Lamp-light" name="Lamp">
29
+ <technique_common>
30
+ <point>
31
+ <color sid="color">1 1 1</color>
32
+ <constant_attenuation>1</constant_attenuation>
33
+ <linear_attenuation>0</linear_attenuation>
34
+ <quadratic_attenuation>0.00111109</quadratic_attenuation>
35
+ </point>
36
+ </technique_common>
37
+ <extra>
38
+ <technique profile="blender">
39
+ <adapt_thresh>0.000999987</adapt_thresh>
40
+ <area_shape>0</area_shape>
41
+ <area_size>1</area_size>
42
+ <area_sizey>1</area_sizey>
43
+ <area_sizez>1</area_sizez>
44
+ <atm_distance_factor>1</atm_distance_factor>
45
+ <atm_extinction_factor>1</atm_extinction_factor>
46
+ <atm_turbidity>2</atm_turbidity>
47
+ <att1>0</att1>
48
+ <att2>1</att2>
49
+ <backscattered_light>1</backscattered_light>
50
+ <bias>1</bias>
51
+ <blue>1</blue>
52
+ <buffers>1</buffers>
53
+ <bufflag>0</bufflag>
54
+ <bufsize>2880</bufsize>
55
+ <buftype>2</buftype>
56
+ <clipend>30.002</clipend>
57
+ <clipsta>1.000799</clipsta>
58
+ <compressthresh>0.04999995</compressthresh>
59
+ <dist sid="blender_dist">29.99998</dist>
60
+ <energy sid="blender_energy">1</energy>
61
+ <falloff_type>2</falloff_type>
62
+ <filtertype>0</filtertype>
63
+ <flag>0</flag>
64
+ <gamma sid="blender_gamma">1</gamma>
65
+ <green>1</green>
66
+ <halo_intensity sid="blnder_halo_intensity">1</halo_intensity>
67
+ <horizon_brightness>1</horizon_brightness>
68
+ <mode>8192</mode>
69
+ <ray_samp>1</ray_samp>
70
+ <ray_samp_method>1</ray_samp_method>
71
+ <ray_samp_type>0</ray_samp_type>
72
+ <ray_sampy>1</ray_sampy>
73
+ <ray_sampz>1</ray_sampz>
74
+ <red>1</red>
75
+ <samp>3</samp>
76
+ <shadhalostep>0</shadhalostep>
77
+ <shadow_b sid="blender_shadow_b">0</shadow_b>
78
+ <shadow_g sid="blender_shadow_g">0</shadow_g>
79
+ <shadow_r sid="blender_shadow_r">0</shadow_r>
80
+ <shadspotsize>45</shadspotsize>
81
+ <sky_colorspace>0</sky_colorspace>
82
+ <sky_exposure>1</sky_exposure>
83
+ <skyblendfac>1</skyblendfac>
84
+ <skyblendtype>1</skyblendtype>
85
+ <soft>3</soft>
86
+ <spotblend>0.15</spotblend>
87
+ <spotsize>75</spotsize>
88
+ <spread>1</spread>
89
+ <sun_brightness>1</sun_brightness>
90
+ <sun_effect_type>0</sun_effect_type>
91
+ <sun_intensity>1</sun_intensity>
92
+ <sun_size>1</sun_size>
93
+ <type>0</type>
94
+ </technique>
95
+ </extra>
96
+ </light>
97
+ </library_lights>
98
+ <library_images/>
99
+ <library_effects>
100
+ <effect id="Material-effect">
101
+ <profile_COMMON>
102
+ <technique sid="common">
103
+ <phong>
104
+ <emission>
105
+ <color sid="emission">0 0 0 1</color>
106
+ </emission>
107
+ <ambient>
108
+ <color sid="ambient">0 0 0 1</color>
109
+ </ambient>
110
+ <diffuse>
111
+ <color sid="diffuse">0.64 0.64 0.64 1</color>
112
+ </diffuse>
113
+ <specular>
114
+ <color sid="specular">0.5 0.5 0.5 1</color>
115
+ </specular>
116
+ <shininess>
117
+ <float sid="shininess">50</float>
118
+ </shininess>
119
+ <index_of_refraction>
120
+ <float sid="index_of_refraction">1</float>
121
+ </index_of_refraction>
122
+ </phong>
123
+ </technique>
124
+ <extra>
125
+ <technique profile="GOOGLEEARTH">
126
+ <double_sided>1</double_sided>
127
+ </technique>
128
+ </extra>
129
+ </profile_COMMON>
130
+ <extra><technique profile="MAX3D"><double_sided>1</double_sided></technique></extra>
131
+ </effect>
132
+ </library_effects>
133
+ <library_materials>
134
+ <material id="Material-material" name="Material-material">
135
+ <instance_effect url="#Material-effect"/>
136
+ </material>
137
+ </library_materials>
138
+ <library_geometries>
139
+ <geometry id="Cube-mesh" name="Cube">
140
+ <mesh>
141
+ <source id="Cube-mesh-positions">
142
+ <float_array id="Cube-mesh-positions-array" count="24">1 1 -1 1 -1 -1 -1 -1 -1 -1 1 -1 1 1 1 1 -1 1 -1 -1 1 -1 1 1</float_array>
143
+ <technique_common>
144
+ <accessor source="#Cube-mesh-positions-array" count="8" stride="3">
145
+ <param name="X" type="float"/>
146
+ <param name="Y" type="float"/>
147
+ <param name="Z" type="float"/>
148
+ </accessor>
149
+ </technique_common>
150
+ </source>
151
+ <source id="Cube-mesh-normals">
152
+ <float_array id="Cube-mesh-normals-array" count="18">0 0 -1 0 0 1 1 -0 0 -0 -1 0 -1 0 0 0 1 0</float_array>
153
+ <technique_common>
154
+ <accessor source="#Cube-mesh-normals-array" count="6" stride="3">
155
+ <param name="X" type="float"/>
156
+ <param name="Y" type="float"/>
157
+ <param name="Z" type="float"/>
158
+ </accessor>
159
+ </technique_common>
160
+ </source>
161
+ <vertices id="Cube-mesh-vertices">
162
+ <input semantic="POSITION" source="#Cube-mesh-positions"/>
163
+ </vertices>
164
+ <polylist material="Material-material" count="6">
165
+ <input semantic="VERTEX" source="#Cube-mesh-vertices" offset="0"/>
166
+ <input semantic="NORMAL" source="#Cube-mesh-normals" offset="1"/>
167
+ <vcount>4 4 4 4 4 4 </vcount>
168
+ <p>0 0 1 0 2 0 3 0 4 1 7 1 6 1 5 1 0 2 4 2 5 2 1 2 1 3 5 3 6 3 2 3 2 4 6 4 7 4 3 4 4 5 0 5 3 5 7 5</p>
169
+ </polylist>
170
+ </mesh>
171
+ <extra><technique profile="MAYA"><double_sided>1</double_sided></technique></extra>
172
+ </geometry>
173
+ </library_geometries>
174
+ <library_visual_scenes>
175
+ <visual_scene id="Scene" name="Scene">
176
+ <node id="Camera" name="Camera" type="NODE">
177
+ <translate sid="location">7.481132 -6.50764 5.343665</translate>
178
+ <rotate sid="rotationZ">0 0 1 46.69194</rotate>
179
+ <rotate sid="rotationY">0 1 0 0.619768</rotate>
180
+ <rotate sid="rotationX">1 0 0 63.5593</rotate>
181
+ <scale sid="scale">1 1 1</scale>
182
+ <instance_camera url="#Camera-camera"/>
183
+ </node>
184
+ <node id="Lamp" name="Lamp" type="NODE">
185
+ <translate sid="location">4.076245 1.005454 5.903862</translate>
186
+ <rotate sid="rotationZ">0 0 1 106.9363</rotate>
187
+ <rotate sid="rotationY">0 1 0 3.163707</rotate>
188
+ <rotate sid="rotationX">1 0 0 37.26105</rotate>
189
+ <scale sid="scale">1 1 1</scale>
190
+ <instance_light url="#Lamp-light"/>
191
+ </node>
192
+ <node id="Cube" name="Cube" type="NODE">
193
+ <translate sid="location">0 0 0</translate>
194
+ <rotate sid="rotationZ">0 0 1 0</rotate>
195
+ <rotate sid="rotationY">0 1 0 0</rotate>
196
+ <rotate sid="rotationX">1 0 0 0</rotate>
197
+ <scale sid="scale">1 1 1</scale>
198
+ <instance_geometry url="#Cube-mesh">
199
+ <bind_material>
200
+ <technique_common>
201
+ <instance_material symbol="Material-material" target="#Material-material"/>
202
+ </technique_common>
203
+ </bind_material>
204
+ </instance_geometry>
205
+ </node>
206
+ </visual_scene>
207
+ </library_visual_scenes>
208
+ <scene>
209
+ <instance_visual_scene url="#Scene"/>
210
+ </scene>
211
+ </COLLADA>
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'pathname'
24
+ require 'test/unit'
25
+ require 'stringio'
26
+
27
+ require 'collada/parser'
28
+ require 'collada/conversion/skeleton'
29
+
30
+ class TestParsingGeometry < Test::Unit::TestCase
31
+ def setup
32
+ @path = File.expand_path("../animation.dae", __FILE__)
33
+ @doc = REXML::Document.new(File.open(@path))
34
+ @library = Collada::Parser::Library.parse(@doc)
35
+ end
36
+
37
+ Attribute = Collada::Parser::Attribute
38
+
39
+ # We are going to load the animation file and check that it has some bones.
40
+ def test_library_animation
41
+ library = @library
42
+
43
+ assert_equal 1, library[:animations].size
44
+
45
+ # Extract out the animations that transform the bones:
46
+ channels = {}
47
+ library[:animations].each do |animation|
48
+ animation.channels.each do |channel|
49
+ channels[channel.target] = channel
50
+ end
51
+ end
52
+
53
+ # We have some animation attached to the secondary bone:
54
+ assert channels['Secondary-Bone/transform']
55
+
56
+ # Are there three matricies?
57
+ assert_equal 3, channels['Secondary-Bone/transform'].source.count
58
+
59
+ # Extract the bones from the visual scene:
60
+ bone_a = library[:visual_scenes].first.nodes['Armature'].children.first
61
+ bone_b = bone_a.children.first
62
+
63
+ # This tells us the position of the bone in the scene:
64
+ assert_equal "Primary-Bone", bone_a.id
65
+ assert_equal :joint, bone_a.type
66
+ puts bone_a.transform_matrix
67
+
68
+ # ... but it doesn't tell us anything about how its connected to any related object:
69
+ assert_equal "Secondary-Bone", bone_b.id
70
+ assert_equal :joint, bone_b.type
71
+ puts bone_b.transform_matrix
72
+
73
+ # for that, we need to inspect a controller.
74
+ controller = library[:visual_scenes].first.nodes['Cylinder'].instances.first.lookup(library)
75
+ assert controller
76
+
77
+ assert_equal Collada::Parser::Controller::Skin, controller.class
78
+
79
+ weights = [
80
+ [Attribute.joint({:JOINT=>"Primary-Bone"}), Attribute.weight({:WEIGHT=>0.9576348})],
81
+ [Attribute.joint({:JOINT=>"Secondary-Bone"}), Attribute.weight({:WEIGHT=>0.04236513})]
82
+ ]
83
+
84
+ assert_equal weights, controller.weights.to_a[159]
85
+ end
86
+
87
+ def test_skeleton
88
+ controller = @library[:controllers].first
89
+ geometry = controller.source.lookup(@library)
90
+ scene = @library[:visual_scenes].first
91
+
92
+ skeleton = Collada::Conversion::Skeleton.new(@library, scene, scene['Primary-Bone'], controller)
93
+
94
+ assert_equal geometry.mesh.vertices.size, skeleton.indexed_weights.size
95
+ end
96
+ end
@@ -0,0 +1,187 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'pathname'
24
+ require 'test/unit'
25
+ require 'stringio'
26
+
27
+ require 'collada/parser'
28
+
29
+ class TestParsingGeometry < Test::Unit::TestCase
30
+ Attribute = Collada::Parser::Attribute
31
+
32
+ def test_accessors
33
+ parameters = [
34
+ Collada::Parser::Parameter.new(:x, :float),
35
+ Collada::Parser::Parameter.new(nil, :float),
36
+ Collada::Parser::Parameter.new(:z, :float),
37
+ ]
38
+
39
+ accessor = Collada::Parser::Accessor.new(
40
+ [1, 2, 3, 4, 5, 6],
41
+ parameters, 2
42
+ )
43
+
44
+ assert_equal [[:x, 1], [:z, 3]], accessor[0]
45
+ assert_equal [[:x, 4], [:z, 6]], accessor[1]
46
+
47
+ assert_equal 2, accessor.size
48
+ assert_equal [[[:x, 1], [:z, 3]], [[:x, 4], [:z, 6]]], accessor.to_a
49
+ end
50
+
51
+ def test_sources
52
+ chunk = <<-EOF
53
+ <?xml version="1.0" encoding="utf-8"?>
54
+ <mesh>
55
+ <source id="position">
56
+ <float_array id="values" count="30">
57
+ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
58
+ </float_array>
59
+ <technique_common>
60
+ <accessor source="#values" count="3" stride="10">
61
+ <param name="px" type="float"/>
62
+ <param name="py" type="float"/>
63
+ <param name="pz" type="float"/>
64
+ </accessor>
65
+ </technique_common>
66
+ </source>
67
+ <source id="normal">
68
+ <technique_common>
69
+ <accessor source="#values" offset="3" count="3" stride="10">
70
+ <param name="nx" type="float"/>
71
+ <param name="ny" type="float"/>
72
+ <param name="nz" type="float"/>
73
+ </accessor>
74
+ </technique_common>
75
+ </source>
76
+ <source id="mapping">
77
+ <technique_common>
78
+ <accessor source="#values" offset="6" count="3" stride="10">
79
+ <param name="mu" type="float"/>
80
+ <param name="mv" type="float"/>
81
+ </accessor>
82
+ </technique_common>
83
+ </source>
84
+
85
+ <triangles count="1">
86
+ <input semantic="POSITION" source="#position" offset="0"/>
87
+ <input semantic="NORMAL" source="#normal" offset="0"/>
88
+ <input semantic="TEXCOORD" source="#mapping" offset="0"/>
89
+ <p>0 1 2</p>
90
+ </triangles>
91
+ </mesh>
92
+ EOF
93
+
94
+ doc = REXML::Document.new(chunk)
95
+ mesh = Collada::Parser::Geometry::Mesh.parse(doc, doc.elements['mesh'])
96
+
97
+ expected = [
98
+ [
99
+ Attribute.position(:px => 1.0, :py => 2.0, :pz => 3.0),
100
+ Attribute.normal(:nx => 4.0, :ny => 5.0, :nz => 6.0),
101
+ Attribute.texcoord(:mu => 7.0, :mv => 8.0)
102
+ ],
103
+ [
104
+ Attribute.position(:px => 11.0, :py => 12.0, :pz => 13.0),
105
+ Attribute.normal(:nx => 14.0, :ny => 15.0, :nz => 16.0),
106
+ Attribute.texcoord(:mu => 17.0, :mv => 18.0)
107
+ ],
108
+ [
109
+ Attribute.position(:px => 21.0, :py => 22.0, :pz => 23.0),
110
+ Attribute.normal(:nx => 24.0, :ny => 25.0, :nz => 26.0),
111
+ Attribute.texcoord(:mu => 27.0, :mv => 28.0)
112
+ ],
113
+ ]
114
+
115
+ assert_equal expected[0], mesh.polygons.vertex(0)
116
+ assert_equal expected[1], mesh.polygons.vertex(1)
117
+ assert_equal expected[2], mesh.polygons.vertex(2)
118
+ end
119
+
120
+ def test_sources_skipping
121
+ chunk = <<-EOF
122
+ <?xml version="1.0" encoding="utf-8"?>
123
+ <mesh>
124
+ <source id="test1">
125
+ <float_array id="values" count="9">
126
+ 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0
127
+ </float_array>
128
+ <technique_common>
129
+ <accessor source="#values" count="3" stride="3">
130
+ <param name='px' type="float"/>
131
+ <param type="float"/>
132
+ <param name='pz' type="float"/>
133
+ </accessor>
134
+ </technique_common>
135
+ </source>
136
+
137
+ <triangles count="1">
138
+ <input semantic="POSITION" source="#test1" offset="0"/>
139
+ <p>0 1 2</p>
140
+ </triangles>
141
+ </mesh>
142
+ EOF
143
+
144
+ doc = REXML::Document.new(chunk)
145
+ mesh = Collada::Parser::Geometry::Mesh.parse(doc, doc.elements['mesh'])
146
+
147
+ expected = [
148
+ [Attribute.position(:px => 1.0, :pz => 3.0)],
149
+ [Attribute.position(:px => 4.0, :pz => 6.0)],
150
+ [Attribute.position(:px => 7.0, :pz => 9.0)],
151
+ ]
152
+
153
+ assert_equal expected[0], mesh.polygons.vertex(0)
154
+ assert_equal expected[1], mesh.polygons.vertex(1)
155
+ assert_equal expected[2], mesh.polygons.vertex(2)
156
+ end
157
+
158
+ def test_library_geometry
159
+ # The verticies in this file present an interesting phenomenon - the vertex positions are reused, but vertex normals are not. In this case, vertices are uniquely identified by their position, but the number of unique vertices for the purposes of rendering is much larger. This means that there is not a direct correspondence between vertices as per collada data and unique verticies including all attributes (position, normal, texture coordinates, etc).
160
+ path = File.expand_path("../sample.dae", __FILE__)
161
+
162
+ doc = REXML::Document.new(File.open(path))
163
+ library = Collada::Parser::Library.parse(doc)
164
+
165
+ mesh = library[:geometries].first.mesh
166
+
167
+ expected = [
168
+ [
169
+ [Attribute.position({:X=>1.0, :Y=>1.0, :Z=>-1.0}), Attribute.vertex(index: 0), Attribute.normal({:X=>0.0, :Y=>0.0, :Z=>-1.0})],
170
+ [Attribute.position({:X=>1.0, :Y=>-1.0, :Z=>-1.0}), Attribute.vertex(index: 1), Attribute.normal({:X=>0.0, :Y=>0.0, :Z=>-1.0})],
171
+ [Attribute.position({:X=>-1.0, :Y=>-1.0, :Z=>-1.0}), Attribute.vertex(index: 2), Attribute.normal({:X=>0.0, :Y=>0.0, :Z=>-1.0})],
172
+ [Attribute.position({:X=>-1.0, :Y=>1.0, :Z=>-1.0}), Attribute.vertex(index: 3), Attribute.normal({:X=>0.0, :Y=>0.0, :Z=>-1.0})]
173
+ ],
174
+ [
175
+ [Attribute.position({:X=>1.0, :Y=>1.0, :Z=>1.0}), Attribute.vertex(index: 4), Attribute.normal({:X=>0.0, :Y=>0.0, :Z=>1.0})],
176
+ [Attribute.position({:X=>-1.0, :Y=>1.0, :Z=>1.0}), Attribute.vertex(index: 7), Attribute.normal({:X=>0.0, :Y=>0.0, :Z=>1.0})],
177
+ [Attribute.position({:X=>-1.0, :Y=>-1.0, :Z=>1.0}), Attribute.vertex(index: 6), Attribute.normal({:X=>0.0, :Y=>0.0, :Z=>1.0})],
178
+ [Attribute.position({:X=>1.0, :Y=>-1.0, :Z=>1.0}), Attribute.vertex(index: 5), Attribute.normal({:X=>0.0, :Y=>0.0, :Z=>1.0})]
179
+ ],
180
+ ]
181
+
182
+ polygons = mesh.polygons.first(2)
183
+ polygons.each_with_index do |polygon, index|
184
+ assert_equal expected[index], polygon
185
+ end
186
+ end
187
+ end