MCPcopy Create free account
hub / github.com/microsoft/SandDance / parseModel

Function parseModel

docs/tests/v2/es6/js/sanddance.js:36007–36034  ·  view source on GitHub ↗
(gl)

Source from the content-addressed store, hash-verified

36005}
36006
36007function parseModel(gl) {
36008 var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
36009 var file = opts.file,
36010 _opts$program = opts.program,
36011 program = _opts$program === void 0 ? new _webgl.Program(gl) : _opts$program;
36012 var json = typeof file === 'string' ? parseJSON(file) : file; // Remove any attributes so that we can create a geometry
36013 // TODO - change format to put these in geometry sub object?
36014
36015 var attributes = {};
36016 var modelOptions = {};
36017
36018 for (var key in json) {
36019 var value = json[key];
36020
36021 if (Array.isArray(value)) {
36022 attributes[key] = key === 'indices' ? new Uint16Array(value) : new Float32Array(value);
36023 } else {
36024 modelOptions[key] = value;
36025 }
36026 }
36027
36028 return new _core.Model(gl, Object.assign({
36029 program: program,
36030 geometry: new _geometry.Geometry({
36031 attributes: attributes
36032 })
36033 }, modelOptions, opts));
36034}
36035
36036function parseJSON(file) {
36037 try {

Callers 1

loadModelFunction · 0.85

Calls 1

parseJSONFunction · 0.70

Tested by

no test coverage detected