blender-3d 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d7d79e2019e79e977ccb17593901bcb29bf7055
4
- data.tar.gz: fcc968c990a9f9dd4c058bad499a74353b53871e
3
+ metadata.gz: 1f04890774ad4700938bc6cde6cda8e66bd6a1e0
4
+ data.tar.gz: 9b15e351eccc16ada3c3cd8a07fe569588b11b9e
5
5
  SHA512:
6
- metadata.gz: e6ac870573118372878c50209d112ab916881b808e5f8d179b26aaa8f75851b5d1fba62e3d373d2cc06e050d488299a9a1260106ac2ff412f0525e9c939cf655
7
- data.tar.gz: 7305fb6e8a4ae54796491fccc2322a76b64c7e5041c776e57fbacfa16db93be6f9379f7c3fb0af9016e5b77d71e96eebfcfdc3e206e7cedece561abf5a9cc475
6
+ metadata.gz: 3ef9f4d0b8d6c6e4af8930db64f5ff3aafa568c3d6a3dc12de8da7f08f837f7b494c99bd0b5e22898c7f6e30e4bab4535a40da3692f38ae57e62b4eaa33499f6
7
+ data.tar.gz: 18245b3390d0b575184838e2c35a6003bc05b349a4e47c7895a2e21030a7bdeb0bf7121490598d04f284b35cce532e78ac4dec3ef88be8ed0a7d71652db29766
@@ -1,167 +1,6 @@
1
- module Blender3d
2
- class SimpleType
3
- attr_reader :name
4
-
5
- def initialize(name)
6
- @name = name
7
- end
8
-
9
- def to_s
10
- @name
11
- end
12
-
13
- def inspect
14
- @name
15
- end
16
-
17
- def read(reader)
18
- case @name
19
- when 'char' then reader.read(1)
20
- when 'double' then reader.read_double
21
- when 'float' then reader.read_float
22
- when 'int' then reader.read_int32
23
- when 'int64_t' then reader.read_int64
24
- when 'long' then reader.read_int32
25
- when 'short' then reader.read_int16
26
- when 'uchar' then reader.read_uint8
27
- when 'uint64_t' then reader.read_uint64
28
- when 'ulong' then reader.read_uint32
29
- when 'ushort' then reader.read_uint16
30
- else
31
- dna = reader.model.dna_block.data
32
- name = @name[0].upcase + @name[1..-1]
33
- struct = dna.structures.find { |struct| struct.name == name }
34
- return struct.read(reader) if struct
35
- length = dna.types.find { |name, _size| name == @name }&.last
36
- return reader.read(length) if length
37
- raise 'type not found'
38
- end
39
- end
40
- end
41
-
42
- class PointerType
43
- attr_reader :type
44
-
45
- def initialize(type)
46
- @type = type
47
- end
48
-
49
- def to_s
50
- "Pointer(#@type)"
51
- end
52
-
53
- def inspect
54
- "#{@type.inspect}*"
55
- end
56
-
57
- def read(reader)
58
- pointer = Pointer.new(reader.read_pointer)
59
-
60
- model = reader.model
61
- block = model.pointers[pointer]
62
- if block && block.data.is_a?(String) && !block.type
63
-
64
- if block.count == 1
65
- size = if @type.is_a?(PointerType)
66
- model.header.pointer_size
67
- else
68
- model.dna_block.data.types.find { |type, _| type == @type.name }.last
69
- end
70
-
71
- if block.size > size && block.size % size == 0
72
- block.type = ArrayType.new(@type, block.size / size)
73
- else
74
- block.type = @type
75
- end
76
-
77
- else
78
- block.type = @type
79
- end
80
-
81
- block.parse_data(reader.model)
82
- end
83
-
84
- pointer
85
- end
86
- end
87
-
88
- class FunctionPointerType
89
- attr_reader :return_type
90
-
91
- def initialize(return_type)
92
- @return_type = return_type
93
- end
94
-
95
- def to_s
96
- "Function(#@return_type)"
97
- end
98
-
99
- def inspect
100
- "#{@return_type.inspect} (*)()"
101
- end
102
-
103
- def read(reader)
104
- Pointer.new(reader.read_pointer)
105
- end
106
- end
107
-
108
- # equivalent to PointerType<SimpleType<char>> (char*)
109
- class NullTerminatedStringType
110
- def to_s
111
- "NullTerminatedString"
112
- end
113
-
114
- def inspect
115
- 'char*'
116
- end
117
-
118
- def read(reader)
119
- reader.read_string.chop
120
- end
121
- end
122
-
123
- # equivalent to ArrayType<SimpleType<char>, length> (char[length])
124
- class FixedLengthStringType
125
- attr_reader :length
126
-
127
- def initialize(length)
128
- @length = length
129
- end
130
-
131
- def to_s
132
- "FixedLengthString(#@length)"
133
- end
134
-
135
- def inspect
136
- "char[#@length]"
137
- end
138
-
139
- def read(reader)
140
- reader.read(@length).gsub(/\0.*$/, '')
141
- end
142
- end
143
-
144
- class ArrayType
145
- attr_reader :type, :size
146
-
147
- def initialize(type, size)
148
- @type, @size = type, size
149
- end
150
-
151
- def dimensions
152
- @sizes.size
153
- end
154
-
155
- def to_s
156
- "Array[#@size](#@type)"
157
- end
158
-
159
- def inspect
160
- "#{@type.inspect}[#@size]"
161
- end
162
-
163
- def read(reader)
164
- @size.times.map { @type.read(reader) }
165
- end
166
- end
167
- end
1
+ require_relative 'types/array_type'
2
+ require_relative 'types/fixed_length_string_type'
3
+ require_relative 'types/function_pointer_type'
4
+ require_relative 'types/null_terminated_string_type'
5
+ require_relative 'types/pointer_type'
6
+ require_relative 'types/simple_type'
@@ -0,0 +1,25 @@
1
+ module Blender3d
2
+ class ArrayType
3
+ attr_reader :type, :size
4
+
5
+ def initialize(type, size)
6
+ @type, @size = type, size
7
+ end
8
+
9
+ def dimensions
10
+ @sizes.size
11
+ end
12
+
13
+ def to_s
14
+ "Array[#@size](#@type)"
15
+ end
16
+
17
+ def inspect
18
+ "#{@type.inspect}[#@size]"
19
+ end
20
+
21
+ def read(reader)
22
+ @size.times.map { @type.read(reader) }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ module Blender3d
2
+ # equivalent to ArrayType<SimpleType<char>, length> (char[length])
3
+ class FixedLengthStringType
4
+ attr_reader :length
5
+
6
+ def initialize(length)
7
+ @length = length
8
+ end
9
+
10
+ def to_s
11
+ "FixedLengthString(#@length)"
12
+ end
13
+
14
+ def inspect
15
+ "char[#@length]"
16
+ end
17
+
18
+ def read(reader)
19
+ reader.read(@length).gsub(/\0.*$/, '')
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module Blender3d
2
+ class FunctionPointerType
3
+ attr_reader :return_type
4
+
5
+ def initialize(return_type)
6
+ @return_type = return_type
7
+ end
8
+
9
+ def to_s
10
+ "Function(#@return_type)"
11
+ end
12
+
13
+ def inspect
14
+ "#{@return_type.inspect} (*)()"
15
+ end
16
+
17
+ def read(reader)
18
+ Pointer.new(reader.read_pointer)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ module Blender3d
2
+ # equivalent to PointerType<SimpleType<char>> (char*)
3
+ class NullTerminatedStringType
4
+ def to_s
5
+ 'NullTerminatedString'
6
+ end
7
+
8
+ def inspect
9
+ 'char*'
10
+ end
11
+
12
+ def read(reader)
13
+ reader.read_string.chop
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,47 @@
1
+ module Blender3d
2
+ class PointerType
3
+ attr_reader :type
4
+
5
+ def initialize(type)
6
+ @type = type
7
+ end
8
+
9
+ def to_s
10
+ "Pointer(#@type)"
11
+ end
12
+
13
+ def inspect
14
+ "#{@type.inspect}*"
15
+ end
16
+
17
+ def read(reader)
18
+ pointer = Pointer.new(reader.read_pointer)
19
+
20
+ model = reader.model
21
+ block = model.pointers[pointer]
22
+ if block && block.data.is_a?(String) && !block.type
23
+ block.type = get_type(block, model)
24
+ block.parse_data(reader.model)
25
+ end
26
+
27
+ pointer
28
+ end
29
+
30
+ private
31
+
32
+ def get_type(block, model)
33
+ return @type if block.count > 1
34
+ size = get_size(model)
35
+ return @type unless size > 0 && block.size > size && block.size % size == 0
36
+ ArrayType.new(@type, block.size / size)
37
+ end
38
+
39
+ def get_size(model)
40
+ if @type.is_a?(PointerType)
41
+ model.header.pointer_size
42
+ else
43
+ model.dna_block.data.types.find { |type, _| type == @type.name }.last
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,41 @@
1
+ module Blender3d
2
+ class SimpleType
3
+ attr_reader :name
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ end
8
+
9
+ def to_s
10
+ @name
11
+ end
12
+
13
+ def inspect
14
+ @name
15
+ end
16
+
17
+ def read(reader)
18
+ case @name
19
+ when 'char' then reader.read(1)
20
+ when 'double' then reader.read_double
21
+ when 'float' then reader.read_float
22
+ when 'int' then reader.read_int32
23
+ when 'int64_t' then reader.read_int64
24
+ when 'long' then reader.read_int32
25
+ when 'short' then reader.read_int16
26
+ when 'uchar' then reader.read_uint8
27
+ when 'uint64_t' then reader.read_uint64
28
+ when 'ulong' then reader.read_uint32
29
+ when 'ushort' then reader.read_uint16
30
+ else
31
+ dna = reader.model.dna_block.data
32
+ name = @name[0].upcase + @name[1..-1]
33
+ struct = dna.structures.find { |struct| struct.name == name }
34
+ return struct.read(reader) if struct
35
+ length = dna.types.find { |name, _size| name == @name }&.last
36
+ return reader.read(length) if length
37
+ raise 'type not found'
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module Blender3d
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blender-3d
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SilverPhoenix99
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-02 00:00:00.000000000 Z
11
+ date: 2016-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: facets
@@ -46,6 +46,12 @@ files:
46
46
  - lib/blender-3d/structure.rb
47
47
  - lib/blender-3d/structure_definition.rb
48
48
  - lib/blender-3d/types.rb
49
+ - lib/blender-3d/types/array_type.rb
50
+ - lib/blender-3d/types/fixed_length_string_type.rb
51
+ - lib/blender-3d/types/function_pointer_type.rb
52
+ - lib/blender-3d/types/null_terminated_string_type.rb
53
+ - lib/blender-3d/types/pointer_type.rb
54
+ - lib/blender-3d/types/simple_type.rb
49
55
  - lib/blender-3d/version.rb
50
56
  homepage:
51
57
  licenses:
@@ -67,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
73
  version: '0'
68
74
  requirements: []
69
75
  rubyforge_project:
70
- rubygems_version: 2.6.7
76
+ rubygems_version: 2.6.8
71
77
  signing_key:
72
78
  specification_version: 4
73
79
  summary: Blender 3d file parser.