Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node x3d support #212

Merged
merged 4 commits into from
Jan 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,169 changes: 2,166 additions & 3 deletions dist/cli.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cli.js.map

Large diffs are not rendered by default.

2,269 changes: 2,206 additions & 63 deletions dist/index.js

Large diffs are not rendered by default.

2,169 changes: 2,166 additions & 3 deletions dist/module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/module.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"openscad-openjscad-translator": "0.0.7",
"sax": "^1.2.1",
"underscore": "^1.8.3",
"webworkify": "^1.4.0"
"webworkify": "^1.4.0",
"xmldom": "^0.1.27"
},
"devDependencies": {
"ava": "^0.15.2",
Expand Down
9 changes: 7 additions & 2 deletions src/io/writers/CSGToX3D.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import makeBlob from '../../utils/Blob'
const Blob = makeBlob()

import xmldom from 'xmldom'
const XMLSerializer = xmldom.XMLSerializer
// NOTE: might be useful :https://github.com/jindw/xmldom/pull/152/commits/be5176ece6fa1591daef96a5f361aaacaa445175

export default function toX3D (CSG) {
const DOMImplementation = typeof document !== 'undefined' ? document.implementation : new xmldom.DOMImplementation()
// materialPolygonLists
// key: a color string (e.g. "0 1 1" for yellow)
// value: an array of strings specifying polygons of this color
Expand Down Expand Up @@ -48,9 +53,9 @@ export default function toX3D (CSG) {
})

// create output document
var docType = document.implementation.createDocumentType('X3D',
var docType = DOMImplementation.createDocumentType('X3D',
'ISO//Web3D//DTD X3D 3.1//EN', 'http://www.web3d.org/specifications/x3d-3.1.dtd')
var exportDoc = document.implementation.createDocument(null, 'X3D', docType)
var exportDoc = DOMImplementation.createDocument(null, 'X3D', docType)
exportDoc.insertBefore(
exportDoc.createProcessingInstruction('xml', 'version="1.0" encoding="UTF-8"'),
exportDoc.doctype)
Expand Down
16 changes: 16 additions & 0 deletions src/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,19 @@ test('generateOutput(amf)', t => {
t.is(size, 385246)// FIXME: verify: original value was 385255
})
})

test('generateOutput(x3d)', t => {
const {generateOutput} = openjscad
// FIXME : create a fake csgObject rather than using output from another function
const inputPath = path.resolve(__dirname, '../examples/logo.jscad')
const script = fs.readFileSync(inputPath, 'UTF8')

return openjscad.compile(script, {})
.then(function (input) {
const output = generateOutput('x3d', input)
const {type, encoding, size} = output // FIXME for some reason this fails ?t.is(output.encoding, 'foo' when falsy)
t.is(type, 'model/x3d+xml')
t.is(encoding, 'utf8')
t.is(size, 44384)
})
})