collada-dae-parser
Advanced tools
Comparing version 0.6.1 to 0.7.0
{ | ||
"name": "collada-dae-parser", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "Parse collada .dae 3d animation files into json", | ||
@@ -55,4 +55,4 @@ "main": "src/parse-collada.js", | ||
"gl-mat4": "^1.1.4", | ||
"xml2js": "^0.4.16" | ||
"xml-parser": "^1.2.1" | ||
} | ||
} |
@@ -59,2 +59,4 @@ collada-dae-parser [![npm version](https://badge.fury.io/js/collada-dae-parser.svg)](http://badge.fury.io/js/collada-dae-parser) [![Build Status](https://travis-ci.org/chinedufn/collada-dae-parser.svg?branch=master)](https://travis-ci.org/chinedufn/collada-dae-parser) | ||
This function returns the parsed collada object. | ||
#### xmlFile | ||
@@ -70,3 +72,3 @@ | ||
*Required* | ||
*Optional* | ||
@@ -73,0 +75,0 @@ Type: `function` |
@@ -1,2 +0,2 @@ | ||
var parseXML = require('xml2js').parseString | ||
var xmlparser = require('xml-parser') | ||
var parseLibraryGeometries = require('./library_geometries/parse-library-geometries.js') | ||
@@ -14,42 +14,59 @@ var parseLibraryVisualScenes = require('./library_visual_scenes/parse-visual-scenes.js') | ||
function ParseCollada (colladaXML, callback) { | ||
parseXML(colladaXML, function (err, result) { | ||
if (err) { return callback(err) } | ||
var result = compactXML({}, xmlparser(colladaXML.toString()).root) | ||
result = { COLLADA: result.COLLADA[0] } | ||
var parsedObject = {} | ||
var parsedLibraryGeometries = parseLibraryGeometries(result.COLLADA.library_geometries) | ||
var parsedObject = {} | ||
var parsedLibraryGeometries = parseLibraryGeometries(result.COLLADA.library_geometries) | ||
var visualSceneData = parseLibraryVisualScenes(result.COLLADA.library_visual_scenes) | ||
var visualSceneData = parseLibraryVisualScenes(result.COLLADA.library_visual_scenes) | ||
var jointBindPoses | ||
if (result.COLLADA.library_controllers) { | ||
var controllerData = parseLibraryControllers(result.COLLADA.library_controllers) | ||
if (controllerData.vertexJointWeights && Object.keys(controllerData.vertexJointWeights) .length > 0) { | ||
parsedObject.vertexJointWeights = controllerData.vertexJointWeights | ||
jointBindPoses = controllerData.jointBindPoses | ||
} | ||
var jointBindPoses | ||
if (result.COLLADA.library_controllers) { | ||
var controllerData = parseLibraryControllers(result.COLLADA.library_controllers) | ||
if (controllerData.vertexJointWeights && Object.keys(controllerData.vertexJointWeights) .length > 0) { | ||
parsedObject.vertexJointWeights = controllerData.vertexJointWeights | ||
jointBindPoses = controllerData.jointBindPoses | ||
} | ||
} | ||
// TODO: Also parse interpolation/intangent/outtangent | ||
if (result.COLLADA.library_animations) { | ||
parsedObject.keyframes = parseLocRotScaleAnim(result.COLLADA.library_animations[0].animation) | ||
if (Object.keys(parsedObject.keyframes).length === 0) { | ||
delete parsedObject.keyframes | ||
} | ||
var keyframes = parseSkeletalAnimations(result.COLLADA.library_animations, jointBindPoses, visualSceneData) | ||
if (Object.keys(keyframes).length > 0) { | ||
parsedObject.keyframes = keyframes | ||
} | ||
// TODO: Also parse interpolation/intangent/outtangent | ||
if (result.COLLADA.library_animations) { | ||
parsedObject.keyframes = parseLocRotScaleAnim(result.COLLADA.library_animations[0].animation) | ||
if (Object.keys(parsedObject.keyframes).length === 0) { | ||
delete parsedObject.keyframes | ||
} | ||
var keyframes = parseSkeletalAnimations(result.COLLADA.library_animations, jointBindPoses, visualSceneData) | ||
if (Object.keys(keyframes).length > 0) { | ||
parsedObject.keyframes = keyframes | ||
} | ||
} | ||
// Return our parsed collada object | ||
parsedObject.vertexNormalIndices = parsedLibraryGeometries.vertexNormalIndices | ||
parsedObject.vertexNormals = parsedLibraryGeometries.vertexNormals | ||
parsedObject.vertexPositionIndices = parsedLibraryGeometries.vertexPositionIndices | ||
parsedObject.vertexPositions = parsedLibraryGeometries.vertexPositions | ||
if (parsedLibraryGeometries.vertexUVs.length > 0) { | ||
parsedObject.vertexUVIndices = parsedLibraryGeometries.vertexUVIndices | ||
parsedObject.vertexUVs = parsedLibraryGeometries.vertexUVs | ||
} | ||
callback(null, parsedObject) | ||
}) | ||
// Return our parsed collada object | ||
parsedObject.vertexNormalIndices = parsedLibraryGeometries.vertexNormalIndices | ||
parsedObject.vertexNormals = parsedLibraryGeometries.vertexNormals | ||
parsedObject.vertexPositionIndices = parsedLibraryGeometries.vertexPositionIndices | ||
parsedObject.vertexPositions = parsedLibraryGeometries.vertexPositions | ||
if (parsedLibraryGeometries.vertexUVs.length > 0) { | ||
parsedObject.vertexUVIndices = parsedLibraryGeometries.vertexUVIndices | ||
parsedObject.vertexUVs = parsedLibraryGeometries.vertexUVs | ||
} | ||
if (callback) callback(null, parsedObject) | ||
return parsedObject | ||
} | ||
function compactXML (res, xml) { | ||
var txt = Object.keys(xml.attributes).length === 0 && xml.children.length === 0 | ||
var r = {} | ||
if (!res[xml.name]) res[xml.name] = [] | ||
if (txt) { | ||
r = xml.content || '' | ||
} else { | ||
r.$ = xml.attributes | ||
r._ = xml.content || '' | ||
xml.children.forEach(function (ch) { | ||
compactXML(r, ch) | ||
}) | ||
} | ||
res[xml.name].push(r) | ||
return res | ||
} |
@@ -37,2 +37,8 @@ var fs = require('fs') | ||
test('Parse a default blender cube with an added texture without a callback', function (t) { | ||
t.plan(1) | ||
var parsedCube = parseCollada(tbdcColladaXML) | ||
t.deepEqual(parsedCube, expectedTBDC) | ||
}) | ||
test('Parse a default blender cube with an animation', function (t) { | ||
@@ -39,0 +45,0 @@ t.plan(1) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3252060
1201
127
+ Addedxml-parser@^1.2.1
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)
+ Addedxml-parser@1.2.1(transitive)
- Removedxml2js@^0.4.16
- Removedsax@1.4.1(transitive)
- Removedxml2js@0.4.23(transitive)
- Removedxmlbuilder@11.0.1(transitive)