{"id":9,"date":"2009-01-22T00:54:01","date_gmt":"2009-01-21T22:54:01","guid":{"rendered":"http:\/\/blog.teleranek.org\/?p=9"},"modified":"2025-06-29T12:29:29","modified_gmt":"2025-06-29T10:29:29","slug":"very-efficient-dae-parser-in-papervision","status":"publish","type":"post","link":"https:\/\/blog.teleranek.org\/?p=9","title":{"rendered":"Very &#8220;efficient&#8221; DAE parser in papervision 3d"},"content":{"rendered":"<p>I&#8217;m currently workin on some bigger project, and I needed to load DAE file. It&#8217;s known, that papervision3d has DAE parser &#8211; so I used it. But when I tried to load a little bigger file ( only 400KB model ), flash thrown 15 seconds timeout exception. The exception was thrown during unpack process. &#8220;Wow, flash is so slow, that it can&#8217;t unpack 400KB zip in 15 seconds? This sucks&#8221; I thought. But later I looked deeper into DAE parser&#8217;s code. DAE parser uses KMZ parser, to unpack DAE&#8217;s content ( like textures and models ), and then parses XML ( or rather KMZ unpacks and then uses DAE to read model&#8230; ). I followed the code ( just like Dexter does ), and studied KMZ parser&#8217;s code. And it appears, that KMZ&#8217;s parser code, isn&#8217;t the most efficient code I&#8217;ve ever seen.<\/p>\n<p>Just look @ it:<\/p>\n<p><span><a class=\"linkifyplus\" href=\"http:\/\/papervision3d.googlecode.com\/svn\/trunk\/as3\/trunk\/src\/org\/papervision3d\/objects\/parsers\/KMZ.as\">http:\/\/papervision3d.googlecode.com\/svn\/trunk\/as3\/trunk\/src\/org\/papervision3d\/objects\/parsers\/KMZ.as<\/a><\/span><\/p>\n<p>After loading the zip file, it calls &#8220;parse&#8221; function, which calls &#8220;getColladaFromZip&#8221;. getColladaFromZip unopacks the zip file:<\/p>\n<pre><span>private function getColladaFromZip( zipFile : ZipFile ) : ByteArray  {\r\n\tfor(var i:int = 0; i &lt; zipFile.entries.length; i++) {\r\n\t    var entry:ZipEntry = zipFile.entries[i];\r\n\r\n\t    \/\/ extract the entry's data from the zip\r\n\t    var data:ByteArray = zipFile.getInput(entry);\r\n\r\n\t\tif(entry.name.toLowerCase().indexOf(\".dae\") != -1) {\r\n\t\t\treturn data;\r\n\t\t}\r\n\t}\r\n\treturn null;\r\n}\r\n<\/span><\/pre>\n<p>It unpacks entire file, just to get the &#8220;dae&#8221; file, and then returns. More &#8211; it extracts content ( function &#8220;getInput&#8221; ) , and then checks if unpacked content is &#8220;dae&#8221; file, despite the fact, that to check it, we don&#8217;t need to unpack anything to check it.<\/p>\n<p>It gets worse later &#8211; it unpacks entire file to check how many textures we have in the zip:<\/p>\n<pre><span>private function numTexturesInZip( zipFile : ZipFile ) : uint {\r\n\tvar count : uint = 0;\r\n\tfor(var i:int = 0; i &lt; zipFile.entries.length; i++) {\r\n\t    var entry:ZipEntry = zipFile.entries[i];\r\n\r\n\t    \/\/ extract the entry's data from the zip\r\n\t    var data:ByteArray = zipFile.getInput(entry);\r\n\r\n\t    if(entry.name.toLowerCase().indexOf(\".png\") != -1 || entry.name.toLowerCase().indexOf(\".jpg\") != -1) {\r\n\t\tcount++;\r\n\t }\r\n\t }\r\n\treturn count;\r\n}\r\n\r\n<\/span><\/pre>\n<p>Ok, and at the end, in the &#8220;parse&#8221; function, every file in archive is extracted again, only for purpose of loading textures from this archive.<\/p>\n<p>Reassuming, if you have 1 meg model and several 200 KB textures, KMZ parser extracts geometry 3 times &#8211; second time, to count number of textures (?!?) and third, to load textures. Every texture is extrated 3 times too &#8211; first time &#8211; to ensure that the texture isn&#8217;t a model, second &#8211; to count it, and finally third time &#8211; to load texture. I think that somebody pasted the code of loading zip file from some tutorial and repasted it 3 times :)<\/p>\n<p>I would paste here my code of better KMZ parser, but it&#8217;s too integrated with my project, so you&#8217;ll have to wait ; p<\/p>\n<p>And I wrote this post, to enlight you people, that when you are using pv3d&#8217;s KMZ parser to load zipped DAE, it isn&#8217;t the best parser to use.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m currently workin on some bigger project, and I needed to load DAE file. It&#8217;s known, that papervision3d has DAE parser &#8211; so I used it. But when I tried to load a little bigger file ( only 400KB model ), flash thrown 15 seconds timeout exception. The exception was thrown during unpack process. &#8220;Wow, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[13,16,14,12,15,11,17],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-flash-experiments","tag-bug","tag-bugs","tag-kmz","tag-papervision","tag-parser","tag-pv3d","tag-timeout-exception"],"_links":{"self":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9"}],"version-history":[{"count":1,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":364,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions\/364"}],"wp:attachment":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}