Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c6cb66b42a | |||
| 8cf35dd34d | |||
| 691f3ccc97 | |||
| 2d660efb78 | |||
| a8a5303f7b | |||
| 3b3db58a20 | |||
| bcffc1b1e3 | |||
| 9ba90f1bd5 |
@@ -121,7 +121,7 @@ img.save('mikunyan.png')
|
||||
|
||||
Mikunyan cannot decode ASTC with HDR data. Use `Mikunyan::ImageDecoder.create_astc_file` instead.
|
||||
|
||||
### Json / YAML Outputer
|
||||
### Json / YAML Outputter
|
||||
|
||||
`mikunyan-json` is an executable command for converting unity3d to json.
|
||||
|
||||
@@ -130,9 +130,96 @@ Mikunyan cannot decode ASTC with HDR data. Use `Mikunyan::ImageDecoder.create_as
|
||||
Available options:
|
||||
|
||||
- `--as-asset` (`-a`): interpret input file as not AssetBudnle but Asset
|
||||
- `--pretty` (`-p`): prettify output json (`mikunyan-json` only)
|
||||
- `--pretty` (`-p`): prettify output json
|
||||
- `--yaml` (`-y`): YAML mode
|
||||
|
||||
### Image Outputter
|
||||
|
||||
`mikunyan-image` is an executable command for unpacking images from unity3d.
|
||||
|
||||
$ mikunyan-image bundle.unity3d
|
||||
|
||||
The console log is json data of output textures as below.
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"name": "bg_b",
|
||||
"width": 1024,
|
||||
"height": 1024,
|
||||
"path_id": -744818715421265689
|
||||
},
|
||||
{
|
||||
"name": "bg_a",
|
||||
"width": 1024,
|
||||
"height": 1024,
|
||||
"path_id": 5562124901460497987
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
If the option `--sprite` specified, `mikunyan-image` will output sprites. The log json also contains sprite information.
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"name": "bg_a",
|
||||
"width": 1024,
|
||||
"height": 1024,
|
||||
"path_id": 5562124901460497987,
|
||||
"sprites": [
|
||||
{
|
||||
"name": "bg_a_0",
|
||||
"x": 1.0,
|
||||
"y": 303.0,
|
||||
"width": 1022.0,
|
||||
"height": 720.0,
|
||||
"path_id": -7546240288260780845
|
||||
},
|
||||
{
|
||||
"name": "bg_a_1",
|
||||
"x": 1.0,
|
||||
"y": 1.0,
|
||||
"width": 720.0,
|
||||
"height": 258.0,
|
||||
"path_id": -5293490190204738553
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bg_b",
|
||||
"width": 1024,
|
||||
"height": 1024,
|
||||
"path_id": -744818715421265689,
|
||||
"sprites": [
|
||||
{
|
||||
"name": "bg_b_1",
|
||||
"x": 1.0,
|
||||
"y": 1.0,
|
||||
"width": 720.0,
|
||||
"height": 258.0,
|
||||
"path_id": 4884595733995530103
|
||||
},
|
||||
{
|
||||
"name": "bg_b_0",
|
||||
"x": 1.0,
|
||||
"y": 303.0,
|
||||
"width": 1022.0,
|
||||
"height": 720.0,
|
||||
"path_id": 7736251300187116441
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
Available options:
|
||||
|
||||
- `--as-asset` (`-a`): interpret input file as not AssetBudnle but Asset
|
||||
- `--outputdir` (`-o`): output directory (default is a basename of input file without an extention)
|
||||
- `--sprite` (`-s`): output sprites instead of textures
|
||||
- `--pretty` (`-p`): prettify output json
|
||||
|
||||
## Dependencies
|
||||
|
||||
- [json](https://rubygems.org/gems/json)
|
||||
|
||||
Executable
+92
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'mikunyan'
|
||||
require 'mikunyan/decoders'
|
||||
require 'fileutils'
|
||||
require 'json'
|
||||
|
||||
opts = {:as_asset => false, :outputdir => nil, :sprite => false, :pretty => false}
|
||||
arg = nil
|
||||
i = 0
|
||||
while i < ARGV.count
|
||||
if ARGV[i].start_with?('-')
|
||||
case ARGV[i]
|
||||
when '--as-asset', '-a'
|
||||
opts[:as_asset] = true
|
||||
when '--outputdir', '-o'
|
||||
i += 1
|
||||
opts[:outputdir] = ARGV[i]
|
||||
when '--sprite', '-s'
|
||||
opts[:sprite] = true
|
||||
when '--pretty', '-p'
|
||||
opts[:pretty] = true
|
||||
else
|
||||
warn("Unknown option: #{ARGV[i]}")
|
||||
end
|
||||
else
|
||||
arg = ARGV[i] unless arg
|
||||
end
|
||||
i += 1
|
||||
end
|
||||
|
||||
unless arg
|
||||
warn("Input file is not specified")
|
||||
exit(1)
|
||||
end
|
||||
|
||||
unless File.file?(arg)
|
||||
warn("File not found: #{arg}")
|
||||
exit(1)
|
||||
end
|
||||
|
||||
assets = []
|
||||
|
||||
if opts[:as_asset]
|
||||
assets = [Mikunyan::Asset.file(arg, File.basename(arg, '.*'))]
|
||||
else
|
||||
assets = Mikunyan::AssetBundle.file(arg).assets
|
||||
end
|
||||
|
||||
outdir = opts[:outputdir] || File.basename(arg, '.*')
|
||||
FileUtils.mkpath(outdir)
|
||||
|
||||
assets.each do |asset|
|
||||
if opts[:sprite]
|
||||
json = {}
|
||||
textures = {}
|
||||
|
||||
asset.path_ids.select{|path_id| asset.object_type(path_id) == 'Sprite'}.each do |path_id|
|
||||
obj = asset.parse_object(path_id)
|
||||
name = obj.m_Name.value
|
||||
tex_id = obj.m_RD.texture.m_PathID.value
|
||||
|
||||
unless textures[tex_id]
|
||||
tex_obj = asset.parse_object(tex_id)
|
||||
textures[tex_id] = Mikunyan::ImageDecoder.decode_object(tex_obj) if tex_obj
|
||||
json[tex_id] = {:name => tex_obj.m_Name.value, :width => textures[tex_id].width, :height => textures[tex_id].height, :path_id => tex_id, :sprites => []}
|
||||
end
|
||||
|
||||
if textures[tex_id]
|
||||
x = obj.m_Rect.x.value
|
||||
y = obj.m_Rect.y.value
|
||||
width = obj.m_Rect.width.value
|
||||
height = obj.m_Rect.height.value
|
||||
|
||||
json[tex_id][:sprites] << {:name => name, :x => x, :y => y, :width => width, :height => height, :path_id => path_id}
|
||||
textures[tex_id].crop(x.round, (textures[tex_id].height - height - y).round, width.round, height.round).save("#{outdir}/#{name}.png")
|
||||
end
|
||||
end
|
||||
puts opts[:pretty] ? JSON.pretty_generate(json.values) : JSON.generate(json.values)
|
||||
else
|
||||
json = []
|
||||
asset.path_ids.select{|path_id| asset.object_type(path_id) == 'Texture2D'}.each do |path_id|
|
||||
obj = asset.parse_object(path_id)
|
||||
name = obj.m_Name.value
|
||||
image = Mikunyan::ImageDecoder.decode_object(obj)
|
||||
if image
|
||||
json << {:name => name, :width => image.width, :height => image.height, :path_id => path_id}
|
||||
image.save("#{outdir}/#{name}.png")
|
||||
end
|
||||
end
|
||||
puts opts[:pretty] ? JSON.pretty_generate(json) : JSON.generate(json)
|
||||
end
|
||||
end
|
||||
@@ -97,7 +97,7 @@ module Mikunyan
|
||||
c = ((c & 0xf000) << 12) | ((c & 0x0f00) << 8) | ((c & 0x00f0) << 4) | (c & 0x000f)
|
||||
BinUtils.append_int32_be!(mem, c << 4 | c)
|
||||
end
|
||||
ChunkyPNG::Image.from_rgba_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgba_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from ARGB4444 binary
|
||||
@@ -113,7 +113,7 @@ module Mikunyan
|
||||
c = ((c & 0x0f00) << 16) | ((c & 0x00f0) << 12) | ((c & 0x000f) << 8) | ((c & 0xf000) >> 12)
|
||||
BinUtils.append_int32_be!(mem, c << 4 | c)
|
||||
end
|
||||
ChunkyPNG::Image.from_rgba_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgba_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from RGB565 binary
|
||||
@@ -131,7 +131,7 @@ module Mikunyan
|
||||
b = (c & 0x001f) << 3
|
||||
BinUtils.append_int8!(mem, r | r >> 5, g | g >> 6, b | b >> 5)
|
||||
end
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from A8 binary
|
||||
@@ -145,7 +145,7 @@ module Mikunyan
|
||||
c = BinUtils.get_int8(bin, i)
|
||||
BinUtils.append_int8!(mem, c, c, c)
|
||||
end
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from R8 binary
|
||||
@@ -154,7 +154,7 @@ module Mikunyan
|
||||
# @param [String] bin binary to decode
|
||||
# @return [ChunkyPNG::Image] decoded image
|
||||
def self.decode_r8(width, height, bin)
|
||||
decode_a8(width, height, bin)
|
||||
decode_a8(width, height, bin).flip
|
||||
end
|
||||
|
||||
# Decode image from RG16 binary
|
||||
@@ -167,7 +167,7 @@ module Mikunyan
|
||||
(width * height).times do |i|
|
||||
BinUtils.append_int16_int8_be!(mem, BinUtils.get_int16_be(bin, i*2), 0)
|
||||
end
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from RGB24 binary
|
||||
@@ -176,7 +176,7 @@ module Mikunyan
|
||||
# @param [String] bin binary to decode
|
||||
# @return [ChunkyPNG::Image] decoded image
|
||||
def self.decode_rgb24(width, height, bin)
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, bin)
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, bin).flip
|
||||
end
|
||||
|
||||
# Decode image from RGBA32 binary
|
||||
@@ -185,7 +185,7 @@ module Mikunyan
|
||||
# @param [String] bin binary to decode
|
||||
# @return [ChunkyPNG::Image] decoded image
|
||||
def self.decode_rgba32(width, height, bin)
|
||||
ChunkyPNG::Image.from_rgba_stream(width, height, bin)
|
||||
ChunkyPNG::Image.from_rgba_stream(width, height, bin).flip
|
||||
end
|
||||
|
||||
# Decode image from ARGB32 binary
|
||||
@@ -199,7 +199,7 @@ module Mikunyan
|
||||
c = BinUtils.get_int32_be(bin, i*4)
|
||||
BinUtils.append_int32_be!(mem, ((c & 0x00ffffff) << 8) | ((c & 0xff000000) >> 24))
|
||||
end
|
||||
ChunkyPNG::Image.from_rgba_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgba_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from BGRA32 binary
|
||||
@@ -213,7 +213,7 @@ module Mikunyan
|
||||
c = BinUtils.get_int32_le(bin, i*4)
|
||||
BinUtils.append_int32_be!(mem, ((c & 0x00ffffff) << 8) | ((c & 0xff000000) >> 24))
|
||||
end
|
||||
ChunkyPNG::Image.from_rgba_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgba_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from R16 binary
|
||||
@@ -229,7 +229,7 @@ module Mikunyan
|
||||
c = f2i(r / 65535.0)
|
||||
BinUtils.append_int8!(mem, c, c, c)
|
||||
end
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from RGB9e5 binary
|
||||
@@ -251,7 +251,7 @@ module Mikunyan
|
||||
b = (b / 512r + 1) * (2**(e-15))
|
||||
BinUtils.append_int8!(mem, f2i(r), f2i(g), f2i(b))
|
||||
end
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from R Half-float binary
|
||||
@@ -266,7 +266,7 @@ module Mikunyan
|
||||
c = f2i(n2f(endian == :little ? BinUtils.get_int16_le(bin, i*2) : BinUtils.get_int16_be(bin, i*2)))
|
||||
BinUtils.append_int8!(mem, c, c, c)
|
||||
end
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from RG Half-float binary
|
||||
@@ -282,7 +282,7 @@ module Mikunyan
|
||||
g = f2i(n2f(endian == :little ? BinUtils.get_int16_le(bin, i*4+2) : BinUtils.get_int16_be(bin, i*4+2)))
|
||||
BinUtils.append_int8!(mem, r, g, 0)
|
||||
end
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from RGBA Half-float binary
|
||||
@@ -300,7 +300,7 @@ module Mikunyan
|
||||
a = f2i(n2f(endian == :little ? BinUtils.get_int16_le(bin, i*8+6) : BinUtils.get_int16_be(bin, i*8+6)))
|
||||
BinUtils.append_int8!(mem, r, g, b, a)
|
||||
end
|
||||
ChunkyPNG::Image.from_rgba_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgba_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from R float binary
|
||||
@@ -316,7 +316,7 @@ module Mikunyan
|
||||
c = f2i(bin.byteslice(i*4, 4).unpack(unpackstr)[0])
|
||||
BinUtils.append_int8!(mem, c, c, c)
|
||||
end
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from RG float binary
|
||||
@@ -332,7 +332,7 @@ module Mikunyan
|
||||
r, g = bin.byteslice(i*8, 8).unpack(unpackstr)
|
||||
BinUtils.append_int8!(mem, f2i(r), f2i(g), 0)
|
||||
end
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgb_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from RGBA float binary
|
||||
@@ -348,7 +348,7 @@ module Mikunyan
|
||||
r, g, b, a = bin.byteslice(i*16, 16).unpack(unpackstr)
|
||||
BinUtils.append_int8!(mem, f2i(r), f2i(g), f2i(b), f2i(a))
|
||||
end
|
||||
ChunkyPNG::Image.from_rgba_stream(width, height, mem)
|
||||
ChunkyPNG::Image.from_rgba_stream(width, height, mem).flip
|
||||
end
|
||||
|
||||
# Decode image from ETC1 compressed binary
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module Mikunyan
|
||||
# version string
|
||||
VERSION = "3.9.3"
|
||||
VERSION = "3.9.4"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user