美文网首页
Mathematica 根据 .plist 分割图片

Mathematica 根据 .plist 分割图片

作者: Lohengriny | 来源:发表于2018-06-15 13:11 被阅读0次

    直接上代码好了……

    textureSplit[img_, plist_] := Module[
      {tex, xml, sprites},
      tex = Import[img];
      xml = Import[plist, "XML"];
      sprites = 
       sprites = {#[[1]], ToExpression[#[[2]]], #[[3]] == "true"} & /@ 
         SequenceCases[
          xml[[2, 3, 1, 3, 2, 3]], {XMLElement["key", {}, {path_}], 
            XMLElement[
             "dict", {}, {XMLElement["key", {}, {"aliases"}], 
              XMLElement["array", {}, {}], 
              XMLElement["key", {}, {"spriteOffset"}], 
              XMLElement["string", {}, {_}], 
              XMLElement["key", {}, {"spriteSize"}], 
              XMLElement["string", {}, {_}], 
              XMLElement["key", {}, {"spriteSourceSize"}], 
              XMLElement["string", {}, {_}], 
              XMLElement["key", {}, {"textureRect"}], 
              XMLElement["string", {}, {rect_}], 
              XMLElement["key", {}, {"textureRotated"}], 
              XMLElement[rotated_, {}, {}]}]} :> {path, rect, rotated}, 
          Infinity];
      
      {#[[1]], (ImageRotate[
             ImageTake @@ (Join[{tex}, ({{#[[1, 1]], #[[1, 2]] - 1}, {#[[
                      2, 1]], #[[2, 2]] - 1}} &)@
                 Reverse@
                  Transpose[{#[[1]], #[[1]] + 
                     If[#2, Reverse[#[[2]]], #[[2]]]}]]), 
             If[#2, 90 Degree, 0]] &)[#[[2]], #[[3]]]} & /@ sprites
      ]
    textureSplit[img_] := 
     textureSplit[img, 
      DirectoryName[img] <> FileBaseName[img] <> ".plist"]
    

    相关文章

      网友评论

          本文标题:Mathematica 根据 .plist 分割图片

          本文链接:https://www.haomeiwen.com/subject/mdtmeftx.html