11package collada
22
3- import com.sun.org.apache.xpath.internal.SourceTree
43import f
54import i
65import org.w3c.dom.Document
@@ -15,19 +14,25 @@ import AiColor4D
1514import AI_MAX_NUMBER_OF_TEXTURECOORDS
1615import AI_MAX_NUMBER_OF_COLOR_SETS
1716import b
17+ import com.sun.beans.decoder.ElementHandler
1818import com.sun.xml.internal.stream.events.StartElementEvent
1919import elementChildren
2020import get
2121import lc
22+ import org.xml.sax.helpers.DefaultHandler
2223import words
2324import java.io.FileReader
2425import javax.xml.namespace.QName
26+ import javax.xml.parsers.SAXParserFactory
2527import javax.xml.stream.XMLEventReader
2628import javax.xml.stream.XMLInputFactory
2729import javax.xml.stream.events.Characters
2830import javax.xml.stream.events.EndElement
2931import javax.xml.stream.events.StartElement
3032import javax.xml.stream.events.XMLEvent
33+ import javax.xml.parsers.DocumentBuilder
34+ import org.w3c.dom.traversal.DocumentTraversal
35+ import org.w3c.dom.traversal.NodeFilter
3136
3237
3338/* *
@@ -107,7 +112,7 @@ class ColladaParser(pFile: URI) {
107112 private var mRootNode: Node ? = null
108113
109114 /* * Root animation container */
110- private var mAnims: Animation ? = null
115+ private var mAnims = Animation ()
111116
112117 /* * Size unit: how large compared to a meter */
113118 private var mUnitSize = 1f
@@ -127,6 +132,23 @@ class ColladaParser(pFile: URI) {
127132 if (! file.exists())
128133 throw Error (" Failed to open file: $pFile " )
129134
135+ // val dbFactory = DocumentBuilderFactory.newInstance()
136+ // val dBuilder = dbFactory.newDocumentBuilder()
137+ // val doc = dBuilder.parse(file)
138+ // doc.getDocumentElement().normalize()
139+ //
140+ // val traversal = doc as DocumentTraversal
141+ //
142+ // val walker = traversal.createTreeWalker(
143+ // doc.getDocumentElement(),
144+ // NodeFilter.SHOW_ELEMENT, null, true)
145+ //
146+ // var n = walker.nextNode()
147+ // while(n!=null) {
148+ // println(n.nodeName)
149+ // n = n.nextSibling
150+ // }
151+
130152 // generate a XML reader for it
131153 val factory = XMLInputFactory .newInstance()
132154
@@ -231,7 +253,7 @@ class ColladaParser(pFile: URI) {
231253
232254 else -> skipElement()
233255 }
234- else if (event is EndElement )
256+ else if (event is EndElement )
235257 break
236258 }
237259 postProcessRootAnimations()
@@ -337,9 +359,9 @@ class ColladaParser(pFile: URI) {
337359 }
338360
339361 /* * Re-build animations from animation clip library, if present, otherwise combine single-channel animations */
340- private fun postProcessRootAnimations () {
362+ private fun postProcessRootAnimations () {
341363
342- if (mAnimationClipLibrary.size > 0 ) {
364+ if (mAnimationClipLibrary.size > 0 ) {
343365
344366 val temp = Animation ()
345367
@@ -352,21 +374,16 @@ class ColladaParser(pFile: URI) {
352374 temp.mSubAnims.add(clip)
353375
354376 it.second.forEach {
355-
356- mAnimationLibrary[it]?.let {
357-
358- it.collectChannelsRecursively(clip.mChannels)
359- }
377+ mAnimationLibrary[it]?.collectChannelsRecursively(clip.mChannels)
360378 }
361379 }
362380
363381 mAnims = temp
364382
365383 // Ensure no double deletes.
366384 temp.mSubAnims.clear()
367- }
368- else
369- mAnims!! .combineSingleChannelAnimations()
385+ } else
386+ mAnims.combineSingleChannelAnimations()
370387 }
371388
372389 /* * Reads the animation library */
@@ -2177,7 +2194,8 @@ class ColladaParser(pFile: URI) {
21772194
21782195 readSceneNode(node)
21792196
2180- } else skipElement()
2197+ } else
2198+ skipElement() // ignore the rest
21812199
21822200 } else if (event is EndElement ) {
21832201 if (endElement.name_ == " library_visual_scenes" )
@@ -2189,7 +2207,7 @@ class ColladaParser(pFile: URI) {
21892207
21902208 /* * Reads a scene node's contents including children and stores it in the given node */
21912209 private fun readSceneNode (pNode : Node ? ) {
2192-
2210+ println ( " readSceneNode in " )
21932211 // quit immediately on <bla/> elements
21942212 if (isEmptyElement())
21952213 return
@@ -2280,6 +2298,7 @@ class ColladaParser(pFile: URI) {
22802298 pNode.mLights.add(LightInstance ())
22812299 pNode.mLights.last().mLight = url.substring(1 )
22822300 }
2301+ testClosing(" instance_light" )
22832302 }
22842303 " instance_camera" -> {
22852304 // Reference to a camera, name given in 'url' attribute
@@ -2294,11 +2313,14 @@ class ColladaParser(pFile: URI) {
22942313 pNode.mCameras.add(CameraInstance ())
22952314 pNode.mCameras.last().mCamera = url.substring(1 )
22962315 }
2316+ testClosing(" instance_camera" )
22972317 }
22982318 else -> skipElement() // skip everything else for the moment
22992319 }
2300- } else if (event is EndElement )
2320+ } else if (event is EndElement ) {
2321+ println (" readSceneNode out" )
23012322 break
2323+ }
23022324 }
23032325
23042326 /* * Reads a node transformation entry of the given type and adds it to the given node's transformation list. */
@@ -2490,7 +2512,14 @@ class ColladaParser(pFile: URI) {
24902512 }
24912513
24922514 /* * Returns if an element is an empty element, like <foo /> */
2493- private fun isEmptyElement () = mReader.peek().isEndElement
2515+ private fun isEmptyElement (): Boolean {
2516+ if (mReader.peek().isEndElement)
2517+ if (element.name_ == mReader.peek().asEndElement().name_) {
2518+ mReader.nextEvent()
2519+ return true
2520+ }
2521+ return false
2522+ }
24942523
24952524 /* * Skips all data until the end node of the current element */
24962525 private fun skipElement () {
0 commit comments