From fa7017494bdf8a139fd733dc15a4fd3c26dac31c Mon Sep 17 00:00:00 2001 From: gouarin Date: Sun, 28 Jan 2018 07:00:16 +0100 Subject: [PATCH 1/5] cpp generator for enums --- js/scripts/generate-enums.js | 37 +++++++++++++++++++++++++ js/scripts/templates/cpp_enums.mustache | 23 +++++++++++++++ js/src/_base/enums.js | 1 + 3 files changed, 61 insertions(+) create mode 100644 js/scripts/templates/cpp_enums.mustache diff --git a/js/scripts/generate-enums.js b/js/scripts/generate-enums.js index 308c60ae..c2aacacf 100644 --- a/js/scripts/generate-enums.js +++ b/js/scripts/generate-enums.js @@ -12,12 +12,14 @@ const baseDir = path.resolve(scriptDir, '..'); const jsSrcDir = path.resolve(baseDir, 'src/'); const pySrcDir = path.resolve(baseDir, '..', 'pythreejs'); +const cppSrcDir = path.resolve(baseDir, '..', 'xthreejs/include/xthreejs'); const templateDir = path.resolve(scriptDir, 'templates'); const threeSrcDir = path.resolve(baseDir, 'node_modules', 'three', 'src'); const jsEnumDst = path.resolve(jsSrcDir, '_base', 'enums.js'); const pyEnumDst = path.resolve(pySrcDir, 'enums.py'); +const cppEnumDst = path.resolve(cppSrcDir, 'base', 'xenums.hpp'); // // Actual THREE constants: @@ -47,6 +49,7 @@ function compileTemplate(templateName) { var jsEnumTemplate = compileTemplate('js_enums'); var pyEnumTemplate = compileTemplate('py_enums'); +var cppEnumTemplate = compileTemplate('cpp_enums'); // @@ -150,11 +153,45 @@ function createPythonFiles() { }); } +function writeCppFile() { + // Here we generate lists of enum keys + + var categories = []; + + _.keys(enumConfigs).map(category => { + var categoryObj = {key: category, enums: []}; + categories.push(categoryObj); + enumConfigs[category].forEach(function(enumKey) { + if (Array.isArray(enumKey)) { + // Several keys share the same value, use the first one. + enumKey = enumKey[0]; + } + categoryObj.enums.push({ key: enumKey, value: threeEnums[enumKey] }); + }, this); + }, this); + + var content = cppEnumTemplate({ + now: new Date(), + generatorScriptName: path.basename(__filename), + + categories: categories + }); + + return fse.outputFile(cppEnumDst, content); +} + +function createCppFiles() { + return new Promise(function(resolve) { + resolve(writeCppFile()); + }); +} + function generateFiles() { return Promise.all([ createJavascriptFiles(), createPythonFiles(), + createCppFiles(), checkUnused(), ]); diff --git a/js/scripts/templates/cpp_enums.mustache b/js/scripts/templates/cpp_enums.mustache new file mode 100644 index 00000000..b5c419a8 --- /dev/null +++ b/js/scripts/templates/cpp_enums.mustache @@ -0,0 +1,23 @@ +#ifndef XTHREE_ENUMS_HPP +#define XTHREE_ENUMS_HPP + +// +// This file auto-generated with {{ generatorScriptName }} +// Date: {{ now }} +// + +#include "xwidgets/xeither.hpp" + +namespace xthree{ + namespace xenums{ + {{#each categories as |category|}} + + auto {{ category.key }} = XEITHER( + {{#each category.enums as |enum|}} + "{{ enum.key }}", + {{/each}} + ); + {{/each}} + } +} +#endif \ No newline at end of file diff --git a/js/src/_base/enums.js b/js/src/_base/enums.js index 69c611fc..b04204dd 100644 --- a/js/src/_base/enums.js +++ b/js/src/_base/enums.js @@ -1,5 +1,6 @@ // // This file auto-generated with generate-enums.js +// Date: Thu Jan 25 2018 04:46:33 GMT+0100 (CET) // From 4901f85c592baab0ad734fd5543f990cc0b86f1f Mon Sep 17 00:00:00 2001 From: gouarin Date: Sun, 28 Jan 2018 07:01:07 +0100 Subject: [PATCH 2/5] clean cpp generated files --- js/scripts/clean-generated-files.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/js/scripts/clean-generated-files.js b/js/scripts/clean-generated-files.js index 0250f154..a0a3ffbf 100644 --- a/js/scripts/clean-generated-files.js +++ b/js/scripts/clean-generated-files.js @@ -69,6 +69,11 @@ function cleanGeneratedFilesAsync() { var pyPromise = rmFileGlobAsync('../pythreejs/**/*_autogen.py'); var pyIndexPromise = rmFileGlobAsync('../pythreejs/**/__init__.py'); + var cppPromise1 = rmFileGlobAsync('../xthreejs/**/*_autogen.hpp'); + var cppPromise2 = rmFileGlobAsync('../xthreejs/include/xthreejs/*.hpp'); + var cppPromise3 = rmFileGlobAsync('../xthreejs/**/*_autogen.cpp'); + var cmakePromise = rmFileGlobAsync('../xthreejs/CMakeLists.txt'); + var docPromise = rmFileGlobAsync('../docs/source/**/*_autogen.rst'); var docIndexPromise = rmFileGlobAsync('../docs/source/api/**/index.rst'); @@ -78,6 +83,10 @@ function cleanGeneratedFilesAsync() { jsIndexPromise, pyPromise, pyIndexPromise, + cppPromise1, + cppPromise2, + cppPromise3, + cmakePromise, docPromise, docIndexPromise, ]); From 08e7d584bd949df98d392a8dbc7ea8e794567cac Mon Sep 17 00:00:00 2001 From: gouarin Date: Sun, 28 Jan 2018 07:03:40 +0100 Subject: [PATCH 3/5] add cpp generator for xthreejs autogenerates classes --- js/scripts/generate-wrappers.js | 421 +++++++++++++++++- js/scripts/prop-types.js | 196 +++++++- js/scripts/templates/cmake_wrapper.mustache | 173 +++++++ js/scripts/templates/cpp_wrapper.mustache | 131 ++++++ .../templates/cppheader_wrapper.mustache | 7 + js/scripts/templates/cppsrc_wrapper.mustache | 19 + .../cppxthreeheader_wrapper.mustache | 7 + xthreejs/xthreejsConfig.cmake.in | 13 + 8 files changed, 958 insertions(+), 9 deletions(-) create mode 100644 js/scripts/templates/cmake_wrapper.mustache create mode 100644 js/scripts/templates/cpp_wrapper.mustache create mode 100644 js/scripts/templates/cppheader_wrapper.mustache create mode 100644 js/scripts/templates/cppsrc_wrapper.mustache create mode 100644 js/scripts/templates/cppxthreeheader_wrapper.mustache create mode 100644 xthreejs/xthreejsConfig.cmake.in diff --git a/js/scripts/generate-wrappers.js b/js/scripts/generate-wrappers.js index 5114078e..da09cc41 100644 --- a/js/scripts/generate-wrappers.js +++ b/js/scripts/generate-wrappers.js @@ -13,6 +13,9 @@ const baseDir = path.resolve(scriptDir, '..'); const jsSrcDir = path.resolve(baseDir, 'src/'); const pySrcDir = path.resolve(baseDir, '..', 'pythreejs'); +const cppSrcDir = path.resolve(baseDir, '..', 'xthreejs/include/xthreejs'); +const cppcppSrcDir = path.resolve(baseDir, '..', 'xthreejs/src'); +const cmakeSrcDir = path.resolve(baseDir, '..', 'xthreejs'); const docSrcDir = path.resolve(baseDir, '..', 'docs', 'source', 'api'); const templateDir = path.resolve(scriptDir, 'templates'); @@ -97,12 +100,18 @@ function compileTemplate(templateName) { })); } -const jsWrapperTemplate = compileTemplate('js_wrapper'); -const jsIndexTemplate = compileTemplate('js_index'); -const pyWrapperTemplate = compileTemplate('py_wrapper'); -const pyTopLevelInitTemplate = compileTemplate('py_top_level_init'); -const docTemplate = compileTemplate('autodoc'); -const docIndexTemplate = compileTemplate('autodoc_index'); +const jsWrapperTemplate = compileTemplate('js_wrapper'); +const jsIndexTemplate = compileTemplate('js_index'); +const pyWrapperTemplate = compileTemplate('py_wrapper'); +const pyTopLevelInitTemplate = compileTemplate('py_top_level_init'); +const cppWrapperTemplate = compileTemplate('cpp_wrapper'); +const cppSrcTemplate = compileTemplate('cpp_src'); +const headerCppTemplate = compileTemplate('cppheader_wrapper'); +const cppSrcWrapperTemplate = compileTemplate('cppsrc_wrapper'); +const headerXthreeCppTemplate = compileTemplate('cppxthreeheader_wrapper'); +const cmakeListsTemplate = compileTemplate('cmake_wrapper'); +const docTemplate = compileTemplate('autodoc'); +const docIndexTemplate = compileTemplate('autodoc_index'); const pathSep = /\\|\//; @@ -239,6 +248,10 @@ function relativePathToPythonImportPath(relativePath) { return result; } +function camelCaseToUnderscore (str) { + return str.replace(/([a-zA-Z])(?=[A-Z])/g, '$1_').toLowerCase() +} + // Execute a function for each match to a glob query // // Parameters: @@ -1081,6 +1094,378 @@ function createTopLevelPythonModuleFile() { } +// +// Cpp wrapper writer +// + +class CppWrapper { + + constructor(modulePath, className) { + + this.modulePath = modulePath; + this.dirRelativePath = path.dirname(modulePath); + this.destDirAbsolutePath = path.resolve(cppSrcDir, this.dirRelativePath); + this.destDirSrcAbsolutePath = path.resolve(cppcppSrcDir, this.dirRelativePath); + this.destDirRelativeToBase = path.relative(this.destDirAbsolutePath, cppSrcDir); + + this.basename = path.basename(modulePath, '.js'); + + if (className) { + this.className = className; + } else { + this.className = this.basename.replace(/\./g, '_'); + const extraDefines = getExtraDefines(this.className); + extraDefines.forEach(function(extraClassName) { + createCppWrapper(modulePath, extraClassName); + }); + } + + this.cppDestPath = path.resolve(this.destDirAbsolutePath, this.getUnderscoreRep(this.className) + '.hpp'); + + this.cppAutoDestPath = path.resolve(this.destDirAbsolutePath, this.getUnderscoreRep(this.className) + '_' + AUTOGEN_EXT + '.hpp'); + this.cppSrcAutoDestPath = path.resolve(this.destDirSrcAbsolutePath, this.getUnderscoreRep(this.className) + '_' + AUTOGEN_EXT + '.cpp'); + + this.cppBaseRelativePath = path.relative(this.destDirAbsolutePath, cppSrcDir); + //this.cppBaseRelativePath = relativePathToPythonImportPath(this.cppBaseRelativePath); + + this.hppfile = path.relative(cppSrcDir, this.cppAutoDestPath); + + // check if manual file exists + this.hasOverride = fse.existsSync(this.cppDestPath); + + this.isCustom = CUSTOM_CLASSES.indexOf(modulePath) !== -1; + + this.hasParameters = false; + this.hasBuffer = false; + + this.config = getClassConfig(this.className); + + this.processSuperClass(); + this.processDependencies(); + this.processProperties(); + + if (this.hasOverride){ + this.className = this.className + 'Base'; + } + + // Template and context + this.context = { + now: new Date(), + generatorScriptName: path.basename(__filename), + threejs_docs_url: this.docsUrl, + cpp_base_relative_path: this.cppBaseRelativePath, + constructor: { + args: this.constructorArgs, + hasParameters: this.hasParameters, + }, + + className: this.getUnderscoreRep(this.className, false), + xclassName: this.getUnderscoreRep(this.className), + header: 'XTHREE_' + this.getUnderscoreRep(this.className, false).toUpperCase() + '_HPP', + hppfile: this.hppfile, + modelName: this.className + 'Model', + superClass: this.superClass, + properties: this.properties, + dependencies: this.dependencies, + hasOverride: this.hasOverride, + hasBuffer: this.hasBuffer, + isCustom: this.isCustom, + }; + + // Render template + this.output = cppWrapperTemplate(this.context); + this.outputcpp = cppSrcWrapperTemplate(this.context); + } + + getUnderscoreRep(className, with_x=true) { + const REPLACE = { + 'web_g_l': 'webgl' + }; + + let class_name; + _.mapObject(REPLACE, function(new_str, old_str) { + class_name = camelCaseToUnderscore(className); + class_name = class_name.replace(old_str, new_str); + }); + return (with_x) ? 'x' + class_name : class_name; + } + + getRequireInfoFromClassDescriptor(classDescriptor) { + + const result = {}; + + if (typeof classDescriptor === 'string') { + + if (classDescriptor in classConfigs) { + const config = getClassConfig(classDescriptor); + result.className = classDescriptor; + result.relativePath = config.relativePath; + let res = result.relativePath.split("/"); + res[res.length - 1] = this.getUnderscoreRep(res[res.length - 1]); + result.relativePath = res.join("/"); + } else { + result.className = path.basename(classDescriptor, '.js'); + result.relativePath = classDescriptor; + } + + } else { + throw new Error('invalid classDescriptor: ' + classDescriptor); + } + + // get path of dependency relative to module dir + if (result.className == 'Three') { + result.relativePath = './base/xthree'; + }; + result.absolutePath = path.resolve(cppSrcDir, result.relativePath); + + if (!fse.existsSync(result.absolutePath + '.hpp')) { + result.absolutePath += '_' + AUTOGEN_EXT; + } + + result.requirePath = path.relative(this.destDirAbsolutePath, result.absolutePath); + //result.cppRelativePath = relativePathToPythonImportPath(result.requirePath); + result.cppRelativePath = result.requirePath; + + return result; + + } + + processSuperClass() { + + this.superClass = this.getRequireInfoFromClassDescriptor(this.config.superClass); + + if (this.superClass.className === 'Three') { + this.superClass.className = 'three_widget'; + } + this.superClass.className = this.getUnderscoreRep(this.superClass.className, false); + this.superClass.xclassName = this.getUnderscoreRep(this.superClass.className); + } + + processDependencies() { + + const dependencies = {}; + + // process explicitly listed dependencies + _.reduce(this.config.dependencies, function(result, depName) { + + result[depName] = this.getRequireInfoFromClassDescriptor(depName); + return result; + + }, dependencies, this); + + // infer dependencies from any properties that reference other Three types + _.reduce(this.config.properties, function(result, prop) { + + if (prop instanceof Types.ThreeType || prop instanceof Types.InitializedThreeType || + prop instanceof Types.ThreeTypeArray || prop instanceof Types.ThreeTypeDict) { + if (prop.typeName !== 'this') { + if (typeof prop.typeName === 'string') { + let typeName = prop.typeName || './base/xthree.hpp'; + result[typeName] = this.getRequireInfoFromClassDescriptor(typeName); + if (result[typeName].className === 'Three') { + result[typeName].className = 'ThreeWidget'; + } + } else if (prop.typeName instanceof Array) { + prop.typeName.forEach(function(typeName) { + result[typeName] = this.getRequireInfoFromClassDescriptor(typeName); + }, this); + } + } + } + return result; + + }, dependencies, this); + + this.dependencies = dependencies; + + } + + processProperties() { + + this.properties = _.mapObject(this.config.properties, function(prop, key) { + if (prop.getCppProperty(key) !== 'undefined') { + if (prop.isBinaryBuffer()){ + this.hasBuffer = true; + } + return { + xproperty: prop.getCppProperty(key), + isBinaryBuffer: prop.isBinaryBuffer(), + defaultJson: prop.getCppDefaultValue(), + }; + } + }, this); + } + + getOutputFilename() { + return this.cppAutoDestPath; + } + + getOutputSrcFilename() { + return this.cppSrcAutoDestPath; + } +} + +function createCppWrapper(modulePath, className) { + + let wrapper; + try { + wrapper = new CppWrapper(modulePath, className); + } catch (e) { + console.log(e); + console.log('skipping: ' + modulePath + (className ? ':' + className : '')); + return Promise.resolve(false); + } + let fname = wrapper.getOutputFilename(); + let cppPromise = fse.outputFile(fname, wrapper.output); + + let fnameCpp = wrapper.getOutputSrcFilename(); + let cppcppPromise = fse.outputFile(fnameCpp, wrapper.outputcpp); + + // Also output documentation for the Python API + //let docfname = wrapper.getDocFilename(); + //console.log(docfname); + //let docPromise = Promise.resolve(); + //let docPromise = fse.outputFile(docfname, wrapper.getDocOutput()); + + return Promise.all([cppPromise]);//, docPromise]); +} + +function writeCMakeLists() { + + console.log('Writing CMakeLists...'); + + // Regexp's + const RE_AUTOGEN_EXT = /.hpp$/; + const RE_AUTOGEN_EXT_CPP = /.cpp$/; + + const excludes = ['build']; + + const allFilesSync = (dir, fileList = []) => { + fse.readdirSync(dir).forEach(file => { + const filePath = path.join(dir, file) + + const shouldExclude = _.any(excludes, function(testPattern) { + if (testPattern instanceof RegExp) { + return testPattern.test(file); + } else if (typeof testPattern === 'string') { + return testPattern === file; + } + }); + if (!shouldExclude) { + if (fse.statSync(filePath).isDirectory()) { + allFilesSync(filePath, fileList); + } + else { + if (filePath.match(RE_AUTOGEN_EXT)) { + fileList.push(path.relative(cppSrcDir, filePath)); + } + } + } + }) + return fileList + } + + const allFilesSyncCpp = (dir, fileList = []) => { + fse.readdirSync(dir).forEach(file => { + const filePath = path.join(dir, file) + + const shouldExclude = _.any(excludes, function(testPattern) { + if (testPattern instanceof RegExp) { + return testPattern.test(file); + } else if (typeof testPattern === 'string') { + return testPattern === file; + } + }); + if (!shouldExclude) { + if (fse.statSync(filePath).isDirectory()) { + allFilesSyncCpp(filePath, fileList); + } + else { + if (filePath.match(RE_AUTOGEN_EXT_CPP)) { + fileList.push(path.relative(cppcppSrcDir, filePath)); + } + } + } + }) + return fileList + } + + var fileList = []; + allFilesSync(cmakeSrcDir, fileList); + var fileList_cpp = []; + allFilesSyncCpp(cmakeSrcDir, fileList_cpp); + const context = { + hppfiles: fileList, + cppfiles: fileList_cpp + }; + const output = cmakeListsTemplate(context); + const outputPath = path.join(cmakeSrcDir, 'CMakeLists.txt'); + + return fse.outputFile(outputPath, output); +} + +function writeHeaderCppFiles() { + + console.log('Writing HeaderCppFiles...'); + + // Regexp's + const RE_AUTOGEN_EXT = /.hpp$/; + + const excludes = ['build']; + + const allFilesSync = (dir, fileList = []) => { + fse.readdirSync(dir).forEach(file => { + const filePath = path.join(dir, file) + + const shouldExclude = _.any(excludes, function(testPattern) { + if (testPattern instanceof RegExp) { + return testPattern.test(file); + } else if (typeof testPattern === 'string') { + return testPattern === file; + } + }); + if (!shouldExclude) { + if (fse.statSync(filePath).isDirectory()) { + allFilesSync(filePath, fileList); + } + else { + if (filePath.match(RE_AUTOGEN_EXT)) { + fileList.push(path.relative(cppSrcDir, filePath)); + } + } + } + }) + return fileList + } + + let xthree_hpp = [] + + fse.readdirSync(cppSrcDir).forEach(dir => { + const filePath = path.join(cppSrcDir, dir); + if (fse.statSync(filePath).isDirectory()) { + var fileList = []; + allFilesSync(filePath, fileList); + xthree_hpp.push(dir); + const context = { + dir: dir, + header: dir.toUpperCase(), + hppfiles: fileList + }; + + const output = headerCppTemplate(context); + const outputPath = path.join(cppSrcDir, 'x' + dir + '.hpp'); + + return fse.outputFile(outputPath, output); + } + }); + + const context = { + files: xthree_hpp + }; + const output = headerXthreeCppTemplate(context); + const outputPath = path.join(cppSrcDir, 'xthreejs.hpp'); + return fse.outputFile(outputPath, output); +} function createJavascriptFiles() { return mapPromiseFnOverThreeModules(createJavascriptWrapper) @@ -1128,6 +1513,29 @@ function createPythonFiles() { } +function createCppFiles() { + + // Prevent cpp file generation when outside dir (e.g. npm install in dependent) + if (!fse.existsSync(cppSrcDir)) { + return Promise.resolve(); + } + + return mapPromiseFnOverThreeModules( + function(relativePath) { + return createCppWrapper(relativePath); + }) + .then(function() { + return mapPromiseFnOverFileList(CUSTOM_CLASSES, function(relativePath) { + return createCppWrapper(relativePath) + }); + }) + .then(function() { + return writeHeaderCppFiles(); + }) + .then(function() { + return writeCMakeLists(); + }); +} function generateFiles() { @@ -1135,6 +1543,7 @@ function generateFiles() { return Promise.all([ createJavascriptFiles(), createPythonFiles(), + createCppFiles(), ]); } diff --git a/js/scripts/prop-types.js b/js/scripts/prop-types.js index 68a40ab6..f2a9c420 100644 --- a/js/scripts/prop-types.js +++ b/js/scripts/prop-types.js @@ -2,11 +2,16 @@ const WIDGET_SERIALIZER = '{ deserialize: widgets.unpack_models }'; +function camelCaseToUnderscore (str) { + return str.replace(/([a-zA-Z])(?=[A-Z])/g, '$1_').toLowerCase() +} + class BaseType { constructor(options) { options = options || {}; this.options = options; this.nullable = options.nullable === true; + this.is_defined = false; } getJSPropertyValue() { return JSON.stringify(this.defaultValue); @@ -14,6 +19,11 @@ class BaseType { getPropArrayName() { return null; } + + isBinaryBuffer() { + return false; + } + getPythonDefaultValue() { if (this.defaultValue === false) { return 'False'; } if (this.defaultValue === true) { return 'True'; } @@ -25,6 +35,70 @@ class BaseType { return JSON.stringify(this.defaultValue); } + getCppDefaultValue() { + if (this.defaultValue instanceof Array){ + let RE_COLOR = /\#/; + let to_str = this.defaultValue.toString(); + if (RE_COLOR.test(to_str)){ + return '{"' + to_str + '"}'; + } + return '{' + to_str + '}'; + } + if (typeof this.defaultValue === 'function'){ + return 'R"(' + this.defaultValue.toString() + ')"'; + } + + if (this.defaultValue === false) { return 'false'; } + if (this.defaultValue === true) { return 'true'; } + if (this.defaultValue === 0) { return '0'; } + if (this.defaultValue === '') { return '""'; } + if (this.defaultValue === Infinity) { return "1e15"; }//std::numeric_limits::infinity()"; } + if (this.defaultValue === -Infinity) { return "-1e15"; }//-std::numeric_limits::infinity()"; } + if (!this.defaultValue) { return 'None'; } + + return JSON.stringify(this.defaultValue); + } + _getCppProperty(propName, typeName, enumTypeName) { + const nullableStr = this.nullable ? `xtl::xoptional<${typeName}>` : typeName; + const defaultValue = this.getCppDefaultValue(); + let defaultValueStr = ''; + + if (defaultValue != 'None') { + if (this.defaultValue instanceof Array) { + defaultValueStr = `, ${nullableStr}(${defaultValue})`; + } + else { + defaultValueStr = `, ${defaultValue}`; + } + } + + if (typeName === '::xeus::xjson' && defaultValue != 'None'){ + if (defaultValue === '{}') { + defaultValueStr = ', ::xeus::xjson::object()'; + } + else { + defaultValueStr = `, ::xeus::xjson::parse(R"(${defaultValue})")`; + } + } + + let enumStr = ''; + const RE_LIST_OF_STRING = /\[.*\]/; + if (enumTypeName) { + if (RE_LIST_OF_STRING.test(enumTypeName)) { + enumStr = ', XEITHER' + enumTypeName.replace('[', '(').replace(']', ')').replace(/\'/g, '"'); + } + else { + enumStr = `, xenums::${enumTypeName}`; + } + } + + if (this.is_defined) { + return `XPROPERTY(${nullableStr}, derived_type, ${propName}${defaultValueStr}${enumStr});`; + } + } + getCppProperty(propName, typeName, enumTypeName) { + return 'undefined'; + } getPropertyConverterFn() { return null; } @@ -79,6 +153,8 @@ class ThreeType extends BaseType { this.nullable = options.nullable !== false; this.args = options.args; this.kwargs = options.kwargs; + this.is_defined = true; + } getTraitlet() { let typeName = this.typeName; @@ -92,6 +168,9 @@ class ThreeType extends BaseType { return genInstanceTraitlet( typeName, this.nullable, this.args, this.kwargs, this.getTagParts()); } + getCppProperty(propName) { + return this._getCppProperty(propName, `xw::xholder`); + } getPropArrayName() { return 'three_properties'; } @@ -115,6 +194,10 @@ class ForwardDeclaredThreeType extends ThreeType { } class InitializedThreeType extends ThreeType { + constructor(typeName, options={}) { + super(typeName, options); + this.is_defined = true; + } getJSPropertyValue() { return "'uninitialized'"; } @@ -124,6 +207,9 @@ class InitializedThreeType extends ThreeType { getTagParts() { return super.getTagParts().concat(['**unitialized_serialization']); } + getCppDefaultValue() { + return 'object3d()'; + } getTraitlet() { const typeName = this.typeName; const nullableStr = this.getNullableStr(); @@ -141,6 +227,12 @@ class InitializedThreeType extends ThreeType { ret += this.getTagString(); return ret; } + getCppProperty(propName) { + //return this._getCppProperty(propName, `xw::xholder`); + return this._getCppProperty(propName, `xw::xholder`); + //return this._getCppProperty(propName, `xw::xholder`); + } + } class ThreeTypeArray extends BaseType { @@ -152,6 +244,7 @@ class ThreeTypeArray extends BaseType { this.serializer = WIDGET_SERIALIZER; this.nullable = options.nullable !== false; this.allow_single = options.allow_single === true; + this.is_defined = true; } getTagParts() { return super.getTagParts().concat(['**widget_serialization']); @@ -172,6 +265,14 @@ class ThreeTypeArray extends BaseType { // return 'List(trait=Instance(' + this.typeName + ')).tag(sync=True, **widget_serialization)'; return baseType + this.getTagString(); } + getCppProperty(propName) { + let typeName = this.typeName; + if (this.allow_single) { + return this._getCppProperty(propName, `xw::xholder`); + } + this.nullable = false; + return this._getCppProperty(propName, `std::vector>`); + } getPropArrayName() { return 'three_nested_properties'; } @@ -186,6 +287,7 @@ class ThreeTypeDict extends BaseType { this.typeName = typeName; this.defaultValue = {}; this.serializer = WIDGET_SERIALIZER; + this.is_defined = true; } getTagParts() { return super.getTagParts().concat(['**widget_serialization']); @@ -202,6 +304,10 @@ class ThreeTypeDict extends BaseType { } return `Dict(Instance(${this.typeName}))${this.getTagString()}`; } + getCppProperty(propName) { + //this.defaultValue = 'std::map>{}'; + return this._getCppProperty(propName, 'dict'); + } getPropArrayName() { return 'three_nested_properties'; } @@ -215,6 +321,7 @@ class BufferMorphAttributes extends BaseType { super(options); this.defaultValue = {}; this.serializer = WIDGET_SERIALIZER; + this.is_defined = false; } getTagParts() { return super.getTagParts().concat(['**widget_serialization']); @@ -226,6 +333,9 @@ class BufferMorphAttributes extends BaseType { }); return 'Dict(Tuple(Union([\n' + instances.join(',\n') + '\n ])))' + this.getTagString(); } + getCppProperty(propName) { + return this._getCppProperty(propName, 'dictvec'); + } getPropArrayName() { return 'three_nested_properties'; } @@ -238,11 +348,15 @@ class Bool extends BaseType { constructor(defaultValue, options) { super(options); this.defaultValue = defaultValue; + this.is_defined = true; } getTraitlet() { const nullableStr = this.getNullableStr(); return `Bool(${this.getPythonDefaultValue()}, ${nullableStr})${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'bool'); + } getPropertyConverterFn() { return 'convertBool'; } @@ -255,6 +369,7 @@ class Int extends BaseType { this.minValue = options.minValue; this.maxValue = options.maxValue; this.defaultValue = (defaultValue === null || defaultValue === undefined) && !this.nullable ? 0 : defaultValue ; + this.is_defined = true; } getTraitlet() { const nullableStr = this.getNullableStr(); @@ -267,7 +382,9 @@ class Int extends BaseType { } return `CInt(${this.getPythonDefaultValue()}, ${nullableStr}${limits})${this.getTagString()}`; } - + getCppProperty(propName) { + return this._getCppProperty(propName, 'int'); + } } class Float extends BaseType { @@ -277,6 +394,7 @@ class Float extends BaseType { this.minValue = options.minValue; this.maxValue = options.maxValue; this.defaultValue = (defaultValue === null || defaultValue === undefined) && !this.nullable ? 0.0 : defaultValue; + this.is_defined = true; } getTraitlet() { const nullableStr = this.getNullableStr(); @@ -289,6 +407,9 @@ class Float extends BaseType { } return `CFloat(${this.getPythonDefaultValue()}, ${nullableStr}${limits})${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'double'); + } getPropertyConverterFn() { return 'convertFloat'; } @@ -299,12 +420,15 @@ class StringType extends BaseType { constructor(defaultValue, options) { super(options); this.defaultValue = defaultValue; + this.is_defined = true; } getTraitlet() { const nullableStr = this.getNullableStr(); return `Unicode(${this.getPythonDefaultValue()}, ${nullableStr})${this.getTagString()}`; } - + getCppProperty(propName) { + return this._getCppProperty(propName, 'std::string'); + } } class Enum extends BaseType { @@ -312,11 +436,15 @@ class Enum extends BaseType { super(options); this.enumTypeName = enumTypeName; this.defaultValue = defaultValue; + this.is_defined = true; } getTraitlet() { const nullableStr = this.getNullableStr(); return `Enum(${this.enumTypeName}, ${this.getPythonDefaultValue()}, ${nullableStr})${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'std::string', this.enumTypeName); + } getPropertyConverterFn() { return 'convertEnum'; } @@ -326,11 +454,15 @@ class Color extends BaseType { constructor(defaultValue, options) { super(options); this.defaultValue = defaultValue || '#ffffff'; + this.is_defined = true; } getTraitlet() { const nullableStr = this.getNullableStr(); return `Unicode(${this.getPythonDefaultValue()}, ${nullableStr})${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'xw::html_color'); + } getPropertyConverterFn() { return 'convertColor'; } @@ -340,10 +472,14 @@ class ColorArray extends BaseType { constructor(defaultValue, options) { super(options); this.defaultValue = defaultValue || ['#ffffff']; + this.is_defined = true; } getTraitlet() { return `List(trait=Unicode(), default_value=${this.getPythonDefaultValue()})${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'std::vector'); + } getPropertyConverterFn() { return 'convertColorArray'; } @@ -356,10 +492,14 @@ class ArrayType extends BaseType { constructor(options) { super(options); this.defaultValue = []; + this.is_defined = true; } getTraitlet() { return `List()${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'std::vector'); + } getPropertyAssignmentFn() { return 'assignArray'; } @@ -373,6 +513,7 @@ class ArrayBufferType extends BaseType { this.shapeConstraint = shapeConstraint; this.defaultValue = null; this.serializer = 'dataserializers.data_union_serialization'; + this.is_defined = true; } getTraitlet() { const args = []; @@ -385,6 +526,14 @@ class ArrayBufferType extends BaseType { return `WebGLDataUnion(${args.join(', ')})${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'webgldataunion'); + } + + isBinaryBuffer(){ + return true; + } + getPropertyConverterFn() { return 'convertArrayBuffer'; } @@ -397,11 +546,15 @@ class DictType extends BaseType { constructor(defaultValue={}, options) { super(options); this.defaultValue = defaultValue; + this.is_defined = true; } getTraitlet() { const nullableStr = this.getNullableStr(); return `Dict(default_value=${this.getPythonDefaultValue()}, ${nullableStr})${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, '::xeus::xjson'); + } getPropertyAssignmentFn() { return 'assignDict'; } @@ -417,10 +570,15 @@ class FunctionType extends BaseType { constructor(fn, options) { super(options); this.defaultValue = fn || function() {}; + this.is_defined = true; } getTraitlet() { return `Unicode('${this.defaultValue.toString()}')${this.getTagString()}`; } + getCppProperty(propName) { + // FIX: not sure that is what we want + return this._getCppProperty(propName, 'std::string'); + } getJSPropertyValue() { return this.defaultValue.toString(); } @@ -433,10 +591,14 @@ class Vector2 extends BaseType { constructor(x, y, options) { super(options); this.defaultValue = [ x||0, y||0 ]; + this.is_defined = true; } getTraitlet() { return `Vector2(default_value=${JSON.stringify(this.defaultValue)})${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'vector2'); + } getPropertyConverterFn() { return 'convertVector'; } @@ -449,10 +611,14 @@ class Vector3 extends BaseType { constructor(x, y, z, options) { super(options); this.defaultValue = [ x||0, y||0, z||0 ]; + this.is_defined = true; } getTraitlet() { return `Vector3(default_value=${JSON.stringify(this.defaultValue)})${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'vector3'); + } getPropertyConverterFn() { return 'convertVector'; } @@ -465,10 +631,14 @@ class Vector4 extends BaseType { constructor(x, y, z, w, options) { super(options); this.defaultValue = [ x||0, y||0, z||0, w||0 ]; + this.is_defined = true; } getTraitlet() { return `Vector4(default_value=${JSON.stringify(this.defaultValue)})${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'vector4'); + } getPropertyConverterFn() { return 'convertVector'; } @@ -481,10 +651,14 @@ class VectorArray extends BaseType { constructor(options) { super(options); this.defaultValue = []; + this.is_defined = true; } getTraitlet() { return `List(trait=List())${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'std::vector>'); + } getPropertyConverterFn() { return 'convertVectorArray'; } @@ -497,10 +671,14 @@ class FaceArray extends BaseType { constructor(options) { super(options); this.defaultValue = []; + this.is_defined = true; } getTraitlet() { return `Tuple(trait=Face3())${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'std::vector'); + } getPropertyConverterFn() { return 'convertFaceArray'; } @@ -517,10 +695,14 @@ class Matrix3 extends BaseType { 0, 1, 0, 0, 0, 1, ]; + this.is_defined = true; } getTraitlet() { return `Matrix3(default_value=${JSON.stringify(this.defaultValue)})${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'matrix3'); + } getPropertyConverterFn() { return 'convertMatrix'; } @@ -538,10 +720,14 @@ class Matrix4 extends BaseType { 0, 0, 1, 0, 0, 0, 0, 1 ]; + this.is_defined = true; } getTraitlet() { return `Matrix4(default_value=${JSON.stringify(this.defaultValue)})${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'matrix4'); + } getPropertyConverterFn() { return 'convertMatrix'; } @@ -554,12 +740,16 @@ class Matrix4 extends BaseType { class Euler extends BaseType { constructor(options) { super(options); - this.defaultValue = [0, 0, 0, 'XYZ']; + this.defaultValue = [0, 0, 0, '"XYZ"']; + this.is_defined = true; } getTraitlet() { return `Euler(default_value=${JSON.stringify(this.defaultValue)})${this.getTagString()}`; } + getCppProperty(propName) { + return this._getCppProperty(propName, 'xthree::euler'); + } getPropertyConverterFn() { return 'convertEuler'; } diff --git a/js/scripts/templates/cmake_wrapper.mustache b/js/scripts/templates/cmake_wrapper.mustache new file mode 100644 index 00000000..a8ce0972 --- /dev/null +++ b/js/scripts/templates/cmake_wrapper.mustache @@ -0,0 +1,173 @@ +cmake_minimum_required(VERSION 3.1) +project(xthreejs) + +message(STATUS "Forcing tests build type to Release") +set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) + +set(XTHREEJS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) +set(XTHREEJS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) + +# Configuration +# ============= + +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +set(XTHREEJS_INSTALL_LIBRARY_DIR "\"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\"") + +configure_file ( + "${XTHREEJS_INCLUDE_DIR}/xthreejs/xthreejs_config.hpp.in" + "${XTHREEJS_INCLUDE_DIR}/xthreejs/xthreejs_config.hpp" +) + +# Versionning +# =========== + +file(STRINGS "${XTHREEJS_INCLUDE_DIR}/xthreejs/xthreejs_config.hpp" xthreejs_version_defines + REGEX "#define XTHREEJS_VERSION_(MAJOR|MINOR|PATCH)") +foreach(ver ${xthreejs_version_defines}) + if(ver MATCHES "#define XTHREEJS_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$") + set(XTHREEJS_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") + endif() +endforeach() +set(XTHREEJS_VERSION + ${XTHREEJS_VERSION_MAJOR}.${XTHREEJS_VERSION_MINOR}.${XTHREEJS_VERSION_PATCH}) +message(STATUS "xthreejs version: v${XTHREEJS_VERSION}") + +# Binary version +# See the following URL for explanations about the binary versionning +# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info +file(STRINGS "${XTHREEJS_INCLUDE_DIR}/xthreejs/xthreejs_config.hpp" xthreejs_version_defines + REGEX "#define XTHREEJS_BINARY_(CURRENT|REVISION|AGE)") +foreach(ver ${xthreejs_version_defines}) + if(ver MATCHES "#define XTHREEJS_BINARY_(CURRENT|REVISION|AGE) +([^ ]+)$") + set(XTHREEJS_BINARY_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") + endif() +endforeach() +set(XTHREEJS_BINARY_VERSION + ${XTHREEJS_BINARY_CURRENT}.${XTHREEJS_BINARY_REVISION}.${XTHREEJS_BINARY_AGE}) +message(STATUS "xthreejs binary version: v${XTHREEJS_BINARY_VERSION}") + +# Dependencies +# ============ + +find_package(cppzmq 4.2.3 REQUIRED) +find_package(xtl 0.4 REQUIRED) +find_package(xeus 0.10.1 REQUIRED) +find_package(xwidgets 0.7 REQUIRED) +find_package(xproperty 0.7 REQUIRED) + +# Source files +# ============ + +set(XTHREEJS_HEADERS + {{#each hppfiles as |file|}} + ${XTHREEJS_INCLUDE_DIR}/xthreejs/{{{ file }}} + {{/each}} + ${XTHREEJS_INCLUDE_DIR}/xthreejs/xthreejs_config.hpp +) + +set(XTHREEJS_SOURCES + {{#each cppfiles as |file|}} + ${XTHREEJS_SOURCE_DIR}/{{{ file }}} + {{/each}} +) + +# Output +# ====== + +OPTION(XTHREEJS_PRECOMPILED "precompile xthreejs instances" ON) +if(XTHREEJS_PRECOMPILED) + add_definitions(-DXTHREEJS_PRECOMPILED) +endif() + +add_library(xthreejs SHARED ${XTHREEJS_SOURCES} ${XTHREEJS_HEADERS}) + +target_include_directories(xthreejs PUBLIC $ + $) + +target_link_libraries(xthreejs + PUBLIC xtl + PUBLIC xwidgets + PRIVATE xeus) + +set_target_properties(xthreejs PROPERTIES + PUBLIC_HEADER "${XTHREEJS_HEADERS}" + COMPILE_DEFINITIONS "XTHREEJS_EXPORTS" + PREFIX "" + VERSION ${XTHREEJS_BINARY_VERSION} + SOVERSION ${XTHREEJS_BINARY_CURRENT} + OUTPUT_NAME "libxthreejs") + +# Compilation flags +# ================= + +include(CheckCXXCompilerFlag) +string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE) +OPTION(DISABLE_ARCH_NATIVE "disable -march=native flag" OFF) + +set_target_properties(xthreejs PROPERTIES + CXX_EXTENSIONS OFF + CXX_STANDARD_REQUIRED 14) + +target_compile_features(xthreejs PRIVATE cxx_std_14) + +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel") + target_compile_options(xthreejs PUBLIC -Wunused-parameter -Wextra -Wreorder) + if (DISABLE_ARCH_NATIVE) + target_compile_options(xthreejs PUBLIC -mtune=generic) + else() + target_compile_options(xthreejs PUBLIC -march=native) + endif() + + # Enable link time optimization and set the default symbol + # visibility to hidden (very important to obtain small binaries) + if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG) + # Check for Link Time Optimization support + # (GCC/Clang) + CHECK_CXX_COMPILER_FLAG("-flto" HAS_LTO_FLAG) + if (HAS_LTO_FLAG) + target_compile_options(xthreejs PUBLIC -flto) + endif() + + # Intel equivalent to LTO is called IPO + if (CMAKE_CXX_COMPILER_ID MATCHES "Intel") + CHECK_CXX_COMPILER_FLAG("-ipo" HAS_IPO_FLAG) + if (HAS_IPO_FLAG) + target_compile_options(xthreejs PUBLIC -ipo) + endif() + endif() + endif() + message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") +endif() + +# Installation +# ============ + +set(XTHREEJS_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for xthreejsConfig.cmake") + +install(DIRECTORY ${XTHREEJS_INCLUDE_DIR}/xthreejs DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +install(TARGETS xthreejs + EXPORT ${PROJECT_NAME}-targets + #PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/xthreejs + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +# Makes the project importable from the build directory +export(EXPORT ${PROJECT_NAME}-targets + FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake") + +configure_package_config_file(${PROJECT_NAME}Config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION ${XTHREEJS_CMAKECONFIG_INSTALL_DIR}) +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + VERSION ${XTHREEJS_VERSION} + COMPATIBILITY AnyNewerVersion) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION ${XTHREEJS_CMAKECONFIG_INSTALL_DIR}) +install(EXPORT ${PROJECT_NAME}-targets + FILE ${PROJECT_NAME}Targets.cmake +DESTINATION ${XTHREEJS_CMAKECONFIG_INSTALL_DIR}) \ No newline at end of file diff --git a/js/scripts/templates/cpp_wrapper.mustache b/js/scripts/templates/cpp_wrapper.mustache new file mode 100644 index 00000000..62d62830 --- /dev/null +++ b/js/scripts/templates/cpp_wrapper.mustache @@ -0,0 +1,131 @@ +#ifndef {{ header }} +#define {{ header }} + +#include "xtl/xoptional.hpp" +#include "xwidgets/xeither.hpp" +#include "xwidgets/xwidget.hpp" + +#include "{{ cpp_base_relative_path }}/base/xenums.hpp" +#include "{{ cpp_base_relative_path }}/base/xthree_types.hpp" +#include "{{ superClass.cppRelativePath }}.hpp" +#include "{{ cpp_base_relative_path }}/base/xrender.hpp" + +namespace xthree +{ + // + // {{ className }} declaration + // + + template + class {{ xclassName }} : public {{ superClass.xclassName }} + { + public: + + using base_type = {{ superClass.xclassName }}; + using derived_type = D; + + void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const; + void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&); + + {{#each properties as |prop propName|}} + {{{ prop.xproperty }}} + {{/each}} + + {{#if hasBuffer}} + const std::vector& buffer_paths() const; + {{/if}} + + std::shared_ptr> pre = nullptr; + + protected: + + {{ xclassName }}(); + using base_type::base_type; + + private: + + void set_defaults(); + }; + + using {{ className }} = xw::xmaterialize<{{ xclassName }}>; + + using {{ className }}_generator = xw::xgenerator<{{ xclassName }}>; + + // + // {{ className }} implementation + // + + {{#if hasBuffer}} + template + inline const std::vector& {{ xclassName }}::buffer_paths() const + { + static const std::vector default_buffer_paths = { + {{#each properties as |prop propName|}} + {{#if prop.isBinaryBuffer}} + { "{{ propName }}", "buffer" }, + {{/if}} + {{/each}} + }; + return default_buffer_paths; + } + {{/if}} + + template + inline void {{ xclassName }}::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const + { + base_type::serialize_state(state, buffers); + + {{#each properties as |prop propName|}} + {{#if prop.xproperty}} + xw::set_patch_from_property({{ propName }}, state, buffers); + {{/if}} + {{/each}} + } + + template + inline void {{ xclassName }}::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers) + { + base_type::apply_patch(patch, buffers); + + {{#each properties as |prop propName|}} + {{#if prop.xproperty}} + xw::set_property_from_patch({{ propName }}, patch, buffers); + {{/if}} + {{/each}} + } + + template + inline {{ xclassName }}::{{ xclassName }}() + : base_type() + { + set_defaults(); + } + + template + inline void {{ xclassName }}::set_defaults() + { + this->_model_name() = "{{ modelName }}"; + this->_view_name() = ""; + } +} + +{{#unless hasOverride}} +xeus::xjson mime_bundle_repr(xw::xmaterialize& widget); +{{/unless}} + +/********************* + * precompiled types * + *********************/ + +#ifdef XTHREEJS_PRECOMPILED + #ifndef _WIN32 + extern template class xw::xmaterialize; + extern template xw::xmaterialize::xmaterialize(); + extern template class xw::xtransport>; + extern template class xw::xgenerator; + extern template xw::xgenerator::xgenerator(); + extern template class xw::xtransport>; + #endif +#endif + +#endif \ No newline at end of file diff --git a/js/scripts/templates/cppheader_wrapper.mustache b/js/scripts/templates/cppheader_wrapper.mustache new file mode 100644 index 00000000..4f42b15e --- /dev/null +++ b/js/scripts/templates/cppheader_wrapper.mustache @@ -0,0 +1,7 @@ +#ifndef XTHREE_{{ header }}_DIR_HPP +#define XTHREE_{{ header }}_DIR_HPP + +{{#each hppfiles as |hppfile|}} +#include "{{ hppfile }}" +{{/each}} +#endif \ No newline at end of file diff --git a/js/scripts/templates/cppsrc_wrapper.mustache b/js/scripts/templates/cppsrc_wrapper.mustache new file mode 100644 index 00000000..fd1b8a26 --- /dev/null +++ b/js/scripts/templates/cppsrc_wrapper.mustache @@ -0,0 +1,19 @@ +{{#unless hasOverride}} +#include "xthreejs/{{ hppfile }}" + +xeus::xjson mime_bundle_repr(xw::xmaterialize& widget) +{ + if (not widget.pre) + widget.pre = std::make_shared(xthree::preview(widget)); + return mime_bundle_repr(*widget.pre); +} + +#ifdef XTHREEJS_PRECOMPILED + template class xw::xmaterialize; + template xw::xmaterialize::xmaterialize(); + template class xw::xtransport>; + template class xw::xgenerator; + template xw::xgenerator::xgenerator(); + template class xw::xtransport>; +#endif +{{/unless}} diff --git a/js/scripts/templates/cppxthreeheader_wrapper.mustache b/js/scripts/templates/cppxthreeheader_wrapper.mustache new file mode 100644 index 00000000..5a7cc109 --- /dev/null +++ b/js/scripts/templates/cppxthreeheader_wrapper.mustache @@ -0,0 +1,7 @@ +#ifndef XTHREE_XTHREE_HPP +#define XTHREE_XTHREE_HPP + +{{#each files as |file|}} +#include "x{{ file }}.hpp" +{{/each}} +#endif \ No newline at end of file diff --git a/xthreejs/xthreejsConfig.cmake.in b/xthreejs/xthreejsConfig.cmake.in new file mode 100644 index 00000000..1e328fa3 --- /dev/null +++ b/xthreejs/xthreejsConfig.cmake.in @@ -0,0 +1,13 @@ +# xthreejs cmake module +# This module sets the following variables in your project:: +# +# xthreejs_FOUND - true if xthreejs found on the system +# xthreejs_INCLUDE_DIRS - the directory containing xthreejs headers +# xthreejs_LIBRARY - empty + +@PACKAGE_INIT@ + +set(PN xthreejs) +set_and_check(${PN}_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@") +set(${PN}_LIBRARY "") +check_required_components(${PN}) From 802ccc32597ed7eee469b37b5b4eb536eccd38d8 Mon Sep 17 00:00:00 2001 From: gouarin Date: Sun, 28 Jan 2018 07:05:11 +0100 Subject: [PATCH 4/5] add default cpp classes which are not generated --- .../xthreejs/animation/xanimation_action.hpp | 138 +++++++++ xthreejs/include/xthreejs/base/xenums.hpp | 212 ++++++++++++++ xthreejs/include/xthreejs/base/xrender.hpp | 262 ++++++++++++++++++ xthreejs/include/xthreejs/base/xthree.hpp | 78 ++++++ .../include/xthreejs/base/xthree_types.hpp | 72 +++++ .../xthreejs/core/xbuffer_attribute.hpp | 140 ++++++++++ .../core/xinstanced_buffer_attribute.hpp | 112 ++++++++ xthreejs/include/xthreejs/core/xobject3d.hpp | 106 +++++++ xthreejs/include/xthreejs/core/xrenderer.hpp | 117 ++++++++ .../include/xthreejs/lights/xlight_shadow.hpp | 112 ++++++++ .../include/xthreejs/materials/xmaterial.hpp | 91 ++++++ xthreejs/include/xthreejs/math/xplane.hpp | 99 +++++++ .../renderers/shaders/xuniform_lib.hpp | 255 +++++++++++++++++ .../renderers/webgl/xwebgl_shadow_map.hpp | 103 +++++++ .../xthreejs/renderers/xwebgl_renderer.hpp | 103 +++++++ .../include/xthreejs/xthreejs_config.hpp.in | 44 +++ xthreejs/src/animation/xanimation_action.cpp | 10 + xthreejs/src/base/xrender.cpp | 8 + xthreejs/src/base/xthree_types.cpp | 37 +++ xthreejs/src/core/xbuffer_attribute.cpp | 10 + .../src/core/xinstanced_buffer_attribute.cpp | 10 + xthreejs/src/core/xobject3d.cpp | 10 + xthreejs/src/core/xrenderer.cpp | 10 + xthreejs/src/lights/xlight_shadow.cpp | 17 ++ xthreejs/src/math/xplane.cpp | 10 + xthreejs/xthreejs/base/xenums.hpp | 210 ++++++++++++++ xthreejs/xthreejs/base/xrender.hpp | 219 +++++++++++++++ xthreejs/xthreejs/base/xthree.hpp | 74 +++++ xthreejs/xthreejs/base/xthree_types.hpp | 15 + xthreejs/xthreejs/core/xrenderer.hpp | 102 +++++++ 30 files changed, 2786 insertions(+) create mode 100644 xthreejs/include/xthreejs/animation/xanimation_action.hpp create mode 100644 xthreejs/include/xthreejs/base/xenums.hpp create mode 100644 xthreejs/include/xthreejs/base/xrender.hpp create mode 100644 xthreejs/include/xthreejs/base/xthree.hpp create mode 100644 xthreejs/include/xthreejs/base/xthree_types.hpp create mode 100644 xthreejs/include/xthreejs/core/xbuffer_attribute.hpp create mode 100644 xthreejs/include/xthreejs/core/xinstanced_buffer_attribute.hpp create mode 100644 xthreejs/include/xthreejs/core/xobject3d.hpp create mode 100644 xthreejs/include/xthreejs/core/xrenderer.hpp create mode 100644 xthreejs/include/xthreejs/lights/xlight_shadow.hpp create mode 100644 xthreejs/include/xthreejs/materials/xmaterial.hpp create mode 100644 xthreejs/include/xthreejs/math/xplane.hpp create mode 100644 xthreejs/include/xthreejs/renderers/shaders/xuniform_lib.hpp create mode 100644 xthreejs/include/xthreejs/renderers/webgl/xwebgl_shadow_map.hpp create mode 100644 xthreejs/include/xthreejs/renderers/xwebgl_renderer.hpp create mode 100644 xthreejs/include/xthreejs/xthreejs_config.hpp.in create mode 100644 xthreejs/src/animation/xanimation_action.cpp create mode 100644 xthreejs/src/base/xrender.cpp create mode 100644 xthreejs/src/base/xthree_types.cpp create mode 100644 xthreejs/src/core/xbuffer_attribute.cpp create mode 100644 xthreejs/src/core/xinstanced_buffer_attribute.cpp create mode 100644 xthreejs/src/core/xobject3d.cpp create mode 100644 xthreejs/src/core/xrenderer.cpp create mode 100644 xthreejs/src/lights/xlight_shadow.cpp create mode 100644 xthreejs/src/math/xplane.cpp create mode 100644 xthreejs/xthreejs/base/xenums.hpp create mode 100644 xthreejs/xthreejs/base/xrender.hpp create mode 100644 xthreejs/xthreejs/base/xthree.hpp create mode 100644 xthreejs/xthreejs/base/xthree_types.hpp create mode 100644 xthreejs/xthreejs/core/xrenderer.hpp diff --git a/xthreejs/include/xthreejs/animation/xanimation_action.hpp b/xthreejs/include/xthreejs/animation/xanimation_action.hpp new file mode 100644 index 00000000..568b4176 --- /dev/null +++ b/xthreejs/include/xthreejs/animation/xanimation_action.hpp @@ -0,0 +1,138 @@ +#ifndef XTHREE_ANIMATION_ACTION_HPP +#define XTHREE_ANIMATION_ACTION_HPP + +#include "xtl/xoptional.hpp" +#include "xwidgets/xeither.hpp" +#include "xwidgets/xwidget.hpp" +#include "xwidgets/xtransport.hpp" + +#include "../base/xenums.hpp" +#include "../base/xthree_types.hpp" +#include "../base/xthree.hpp" + +namespace xthree +{ + // + // animation_action declaration + // + + template + class xanimation_action : public xw::xwidget + { + public: + //using base_type_1 = xanimation_action_base; + using base_type = xw::xwidget; + using derived_type = D; + + void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const; + void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&); + + XPROPERTY(xtl::xoptional>, derived_type, mixer); + XPROPERTY(xtl::xoptional>, derived_type, clip); + XPROPERTY(xtl::xoptional>, derived_type, localRoot); + XPROPERTY(bool, derived_type, clampWhenFinished, false); + XPROPERTY(bool, derived_type, enabled, true); + XPROPERTY(std::string, derived_type, loop, "LoopRepeat", xenums::LoopModes); + XPROPERTY(bool, derived_type, paused, false); + XPROPERTY(int, derived_type, repititions, 1e15); + XPROPERTY(double, derived_type, time, 0); + XPROPERTY(double, derived_type, timeScale, 1); + XPROPERTY(double, derived_type, weigth, 1); + XPROPERTY(bool, derived_type, zeroSlopeAtEnd, true); + XPROPERTY(bool, derived_type, zeroSlopeAtStart, true); + + // TODO: add repetitions + + protected: + + xanimation_action(); + using base_type::base_type; + + private: + + void set_defaults(); + }; + + using animation_action = xw::xmaterialize; + + using animation_action_generator = xw::xgenerator; + + // + // animation_action implementation + // + + template + inline void xanimation_action::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const + { + base_type::serialize_state(state, buffers); + + xw::set_patch_from_property(mixer, state, buffers); + xw::set_patch_from_property(clip, state, buffers); + xw::set_patch_from_property(localRoot, state, buffers); + xw::set_patch_from_property(clampWhenFinished, state, buffers); + xw::set_patch_from_property(enabled, state, buffers); + xw::set_patch_from_property(loop, state, buffers); + xw::set_patch_from_property(paused, state, buffers); + xw::set_patch_from_property(repititions, state, buffers); + xw::set_patch_from_property(time, state, buffers); + xw::set_patch_from_property(timeScale, state, buffers); + xw::set_patch_from_property(weigth, state, buffers); + xw::set_patch_from_property(zeroSlopeAtEnd, state, buffers); + xw::set_patch_from_property(zeroSlopeAtStart, state, buffers); + } + + template + inline void xanimation_action::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers) + { + base_type::apply_patch(patch, buffers); + + xw::set_property_from_patch(mixer, patch, buffers); + xw::set_property_from_patch(clip, patch, buffers); + xw::set_property_from_patch(localRoot, patch, buffers); + xw::set_property_from_patch(clampWhenFinished, patch, buffers); + xw::set_property_from_patch(enabled, patch, buffers); + xw::set_property_from_patch(loop, patch, buffers); + xw::set_property_from_patch(paused, patch, buffers); + xw::set_property_from_patch(repititions, patch, buffers); + xw::set_property_from_patch(time, patch, buffers); + xw::set_property_from_patch(timeScale, patch, buffers); + xw::set_property_from_patch(weigth, patch, buffers); + xw::set_property_from_patch(zeroSlopeAtEnd, patch, buffers); + xw::set_property_from_patch(zeroSlopeAtStart, patch, buffers); + } + + template + inline xanimation_action::xanimation_action() + : base_type() + { + set_defaults(); + } + + template + inline void xanimation_action::set_defaults() + { + this->_model_name() = "AnimationActionModel"; + this->_model_module() = "jupyter-threejs"; + this->_model_module_version() = "1.0.0-beta.3"; + this->_view_name() = "AnimationActionView"; + this->_view_module() = "jupyter-threejs"; + this->_view_module_version() = "1.0.0-beta.3"; + } +} + +/********************* + * precompiled types * + *********************/ + +#ifdef XTHREEJS_PRECOMPILED + #ifndef _WIN32 + extern template class xw::xmaterialize; + extern template xw::xmaterialize::xmaterialize(); + extern template class xw::xtransport>; + extern template class xw::xgenerator; + extern template xw::xgenerator::xgenerator(); + extern template class xw::xtransport>; + #endif +#endif + +#endif \ No newline at end of file diff --git a/xthreejs/include/xthreejs/base/xenums.hpp b/xthreejs/include/xthreejs/base/xenums.hpp new file mode 100644 index 00000000..c170deaf --- /dev/null +++ b/xthreejs/include/xthreejs/base/xenums.hpp @@ -0,0 +1,212 @@ +#ifndef XTHREE_ENUMS_HPP +#define XTHREE_ENUMS_HPP + +// +// This file auto-generated with generate-enums.js +// Date: Fri Feb 09 2018 12:06:09 GMT+0100 (CET) +// + +#include "xwidgets/xeither.hpp" + +namespace xthree{ + namespace xenums{ + + auto Equations = XEITHER( + "AddEquation", + "SubtractEquation", + "ReverseSubtractEquation", + "MinEquation", + "MaxEquation", + ); + + auto BlendFactors = XEITHER( + "ZeroFactor", + "OneFactor", + "SrcColorFactor", + "OneMinusSrcColorFactor", + "SrcAlphaFactor", + "OneMinusSrcAlphaFactor", + "DstAlphaFactor", + "OneMinusDstAlphaFactor", + "DstColorFactor", + "OneMinusDstColorFactor", + "SrcAlphaSaturateFactor", + ); + + auto Side = XEITHER( + "FrontSide", + "BackSide", + "DoubleSide", + ); + + auto Shading = XEITHER( + "FlatShading", + "SmoothShading", + ); + + auto Colors = XEITHER( + "NoColors", + "FaceColors", + "VertexColors", + ); + + auto BlendingMode = XEITHER( + "NoBlending", + "NormalBlending", + "AdditiveBlending", + "SubtractiveBlending", + "MultiplyBlending", + "CustomBlending", + ); + + auto DepthMode = XEITHER( + "NeverDepth", + "AlwaysDepth", + "LessDepth", + "LessEqualDepth", + "EqualDepth", + "GreaterEqualDepth", + "GreaterDepth", + "NotEqualDepth", + ); + + auto Operations = XEITHER( + "MultiplyOperation", + "MixOperation", + "AddOperation", + ); + + auto MappingModes = XEITHER( + "UVMapping", + "CubeReflectionMapping", + "CubeRefractionMapping", + "EquirectangularReflectionMapping", + "EquirectangularRefractionMapping", + "SphericalReflectionMapping", + "CubeUVReflectionMapping", + "CubeUVRefractionMapping", + ); + + auto WrappingModes = XEITHER( + "RepeatWrapping", + "ClampToEdgeWrapping", + "MirroredRepeatWrapping", + ); + + auto Filters = XEITHER( + "NearestFilter", + "NearestMipMapNearestFilter", + "NearestMipMapLinearFilter", + "LinearFilter", + "LinearMipMapNearestFilter", + "LinearMipMapLinearFilter", + ); + + auto DataTypes = XEITHER( + "UnsignedByteType", + "ByteType", + "ShortType", + "UnsignedShortType", + "IntType", + "UnsignedIntType", + "FloatType", + "HalfFloatType", + ); + + auto PixelTypes = XEITHER( + "UnsignedShort4444Type", + "UnsignedShort5551Type", + "UnsignedShort565Type", + "UnsignedInt248Type", + ); + + auto PixelFormats = XEITHER( + "AlphaFormat", + "RGBFormat", + "RGBAFormat", + "LuminanceFormat", + "LuminanceAlphaFormat", + "DepthFormat", + "DepthStencilFormat", + ); + + auto DepthFormats = XEITHER( + "DepthFormat", + "DepthStencilFormat", + ); + + auto CompressedTextureFormats = XEITHER( + "RGB_S3TC_DXT1_Format", + "RGBA_S3TC_DXT1_Format", + "RGBA_S3TC_DXT3_Format", + "RGBA_S3TC_DXT5_Format", + "RGB_PVRTC_4BPPV1_Format", + "RGB_PVRTC_2BPPV1_Format", + "RGBA_PVRTC_4BPPV1_Format", + "RGBA_PVRTC_2BPPV1_Format", + "RGB_ETC1_Format", + ); + + auto TextureEncodings = XEITHER( + "LinearEncoding", + "sRGBEncoding", + "RGBEEncoding", + "LogLuvEncoding", + "RGBM7Encoding", + "RGBM16Encoding", + "RGBDEncoding", + "GammaEncoding", + ); + + auto CullFaceModes = XEITHER( + "CullFaceNone", + "CullFaceBack", + "CullFaceFront", + "CullFaceFrontBack", + ); + + auto FrontFaceDirection = XEITHER( + "FrontFaceDirectionCW", + "FrontFaceDirectionCCW", + ); + + auto ShadowTypes = XEITHER( + "BasicShadowMap", + "PCFShadowMap", + "PCFSoftShadowMap", + ); + + auto ToneMappings = XEITHER( + "NoToneMapping", + "LinearToneMapping", + "ReinhardToneMapping", + "Uncharted2ToneMapping", + "CineonToneMapping", + ); + + auto LoopModes = XEITHER( + "LoopOnce", + "LoopRepeat", + "LoopPingPong", + ); + + auto InterpolationModes = XEITHER( + "InterpolateDiscrete", + "InterpolateLinear", + "InterpolateSmooth", + ); + + auto EndingModes = XEITHER( + "ZeroCurvatureEnding", + "ZeroSlopeEnding", + "WrapAroundEnding", + ); + + auto DrawModes = XEITHER( + "TrianglesDrawMode", + "TriangleStripDrawMode", + "TriangleFanDrawMode", + ); + } +} +#endif \ No newline at end of file diff --git a/xthreejs/include/xthreejs/base/xrender.hpp b/xthreejs/include/xthreejs/base/xrender.hpp new file mode 100644 index 00000000..9be33afa --- /dev/null +++ b/xthreejs/include/xthreejs/base/xrender.hpp @@ -0,0 +1,262 @@ +#ifndef XTHREE_RENDER_HPP +#define XTHREE_RENDER_HPP + +#include + +#include "xwidgets/xmaterialize.hpp" +#include "xwidgets/xobject.hpp" +#include "xwidgets/xcolor.hpp" +#include "xwidgets/xholder.hpp" +#include "xwidgets/xtransport.hpp" + +#include "xenums.hpp" +#include "xthree.hpp" +#include "../math/xplane.hpp" +#include "../renderers/webgl/xwebgl_shadow_map.hpp" + +namespace xthree +{ + + // + // xrender_widget declaration + // + + template + class xrender_widget : public xw::xwidget + { + public: + + using base_type = xw::xwidget; + using derived_type = D; + + void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const; + void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&); + + XPROPERTY(int, derived_type, _width, 200); + XPROPERTY(int, derived_type, _height, 200); + XPROPERTY(bool, derived_type, _antialias, false); + + XPROPERTY(bool, derived_type, autoClear, true); + XPROPERTY(bool, derived_type, autoClearColor, true); + XPROPERTY(bool, derived_type, autoClearDepth, true); + XPROPERTY(bool, derived_type, autoClearStencil, true); + XPROPERTY(std::vector>, derived_type, clippingPlanes); + XPROPERTY(double, derived_type, gammaFactor, 2.0); + XPROPERTY(bool, derived_type, gammaInput, false); + XPROPERTY(bool, derived_type, gammaOutput, false); + XPROPERTY(bool, derived_type, localClippingEnabled, false); + XPROPERTY(int, derived_type, maxMorphTargets, 8); + XPROPERTY(int, derived_type, maxMorphNormals, 4); + XPROPERTY(bool, derived_type, physicallyCorrectLights, false); + XPROPERTY(xw::xholder, derived_type, shadowMap, std::move(webgl_shadow_map())); + XPROPERTY(bool, derived_type, sortObject, true); + XPROPERTY(std::string, derived_type, toneMapping, "LinearToneMapping", xenums::ToneMappings); + XPROPERTY(double, derived_type, toneMappingExposure, 1.0); + XPROPERTY(double, derived_type, toneMappingWhitePoint, 1.0); + + XPROPERTY(xw::html_color, derived_type, clearColor, "#000000"); + XPROPERTY(double, derived_type, clearOpacity, 1.0); + + protected: + + xrender_widget(); + + using base_type::base_type; + + private: + + void set_defaults(); + }; + + // + // xrender_widget implementation + // + + template + inline void xrender_widget::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const + { + base_type::serialize_state(state, buffers); + + xw::set_patch_from_property(_width, state, buffers); + xw::set_patch_from_property(_height, state, buffers); + xw::set_patch_from_property(_antialias, state, buffers); + xw::set_patch_from_property(autoClear, state, buffers); + xw::set_patch_from_property(autoClearColor, state, buffers); + xw::set_patch_from_property(autoClearDepth, state, buffers); + xw::set_patch_from_property(autoClearStencil, state, buffers); + xw::set_patch_from_property(clippingPlanes, state, buffers); + xw::set_patch_from_property(gammaFactor, state, buffers); + xw::set_patch_from_property(gammaInput, state, buffers); + xw::set_patch_from_property(gammaOutput, state, buffers); + xw::set_patch_from_property(localClippingEnabled, state, buffers); + xw::set_patch_from_property(maxMorphTargets, state, buffers); + xw::set_patch_from_property(maxMorphNormals, state, buffers); + xw::set_patch_from_property(physicallyCorrectLights, state, buffers); + xw::set_patch_from_property(shadowMap, state, buffers); + xw::set_patch_from_property(sortObject, state, buffers); + xw::set_patch_from_property(toneMapping, state, buffers); + xw::set_patch_from_property(toneMappingExposure, state, buffers); + xw::set_patch_from_property(toneMappingWhitePoint, state, buffers); + xw::set_patch_from_property(clearColor, state, buffers); + xw::set_patch_from_property(clearOpacity, state, buffers); + } + + template + inline void xrender_widget::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers) + { + base_type::apply_patch(patch, buffers); + + xw::set_property_from_patch(_width, patch, buffers); + xw::set_property_from_patch(_height, patch, buffers); + xw::set_property_from_patch(_antialias, patch, buffers); + xw::set_property_from_patch(autoClear, patch, buffers); + xw::set_property_from_patch(autoClearColor, patch, buffers); + xw::set_property_from_patch(autoClearDepth, patch, buffers); + xw::set_property_from_patch(autoClearStencil, patch, buffers); + xw::set_property_from_patch(clippingPlanes, patch, buffers); + xw::set_property_from_patch(gammaFactor, patch, buffers); + xw::set_property_from_patch(gammaInput, patch, buffers); + xw::set_property_from_patch(gammaOutput, patch, buffers); + xw::set_property_from_patch(localClippingEnabled, patch, buffers); + xw::set_property_from_patch(maxMorphTargets, patch, buffers); + xw::set_property_from_patch(maxMorphNormals, patch, buffers); + xw::set_property_from_patch(physicallyCorrectLights, patch, buffers); + xw::set_property_from_patch(shadowMap, patch, buffers); + xw::set_property_from_patch(sortObject, patch, buffers); + xw::set_property_from_patch(toneMapping, patch, buffers); + xw::set_property_from_patch(toneMappingExposure, patch, buffers); + xw::set_property_from_patch(toneMappingWhitePoint, patch, buffers); + xw::set_property_from_patch(clearColor, patch, buffers); + xw::set_property_from_patch(clearOpacity, patch, buffers); + } + + template + inline xrender_widget::xrender_widget() + : base_type() + { + set_defaults(); + } + + template + inline void xrender_widget::set_defaults() + { + this->_model_module() = "jupyter-threejs"; + this->_model_module_version() = "1.0.0-beta.3"; + this->_view_module() = "jupyter-threejs"; + this->_view_module_version() = "1.0.0-beta.3"; + + } + + // + // xpreview declaration + // + + template + class xpreview : public xrender_widget + { + public: + + using base_type = xrender_widget; + using derived_type = D; + + using child_type = xw::xholder; + + void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const; + void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&); + + XPROPERTY(bool, derived_type, _flat, false); + XPROPERTY(bool, derived_type, _wire, false); + XPROPERTY(child_type, derived_type, child); + + template + xpreview(xthree_widget&); + + template + xpreview(const xthree_widget&); + + template + xpreview(xthree_widget&&); + + private: + + void set_defaults(); + }; + + using preview = xw::xmaterialize; + using preview_generator = xw::xgenerator; + + // + // xpreview implementation + // + + template + inline void xpreview::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const + { + base_type::serialize_state(state, buffers); + + xw::set_patch_from_property(_flat, state, buffers); + xw::set_patch_from_property(_wire, state, buffers); + xw::set_patch_from_property(child, state, buffers); + } + + template + inline void xpreview::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers) + { + base_type::apply_patch(patch, buffers); + + xw::set_property_from_patch(_flat, patch, buffers); + xw::set_property_from_patch(_wire, patch, buffers); + xw::set_property_from_patch(child, patch, buffers); + } + + template + template + inline xpreview::xpreview(xthree_widget& child_) + : base_type() + { + this->child = xw::make_id_holder(child_.id()); + set_defaults(); + } + + template + template + inline xpreview::xpreview(const xthree_widget& child_) + : base_type() + { + this->child = xw::make_id_holder(child_.id()); + set_defaults(); + } + + template + template + inline xpreview::xpreview(xthree_widget&& child_) + : base_type() + { + this->child = xw::make_owning_holder(std::move(child_)); + set_defaults(); + } + + template + inline void xpreview::set_defaults() + { + this->_model_name() = "PreviewModel"; + this->_view_name() = "PreviewView"; + } +} + + + +/********************* + * precompiled types * + *********************/ + +#ifdef XTHREEJS_PRECOMPILED + #ifndef _WIN32 + extern template class xw::xmaterialize; + extern template class xw::xtransport>; + extern template class xw::xgenerator; + extern template class xw::xtransport>; + #endif +#endif + +#endif \ No newline at end of file diff --git a/xthreejs/include/xthreejs/base/xthree.hpp b/xthreejs/include/xthreejs/base/xthree.hpp new file mode 100644 index 00000000..d2dfbb2f --- /dev/null +++ b/xthreejs/include/xthreejs/base/xthree.hpp @@ -0,0 +1,78 @@ +#ifndef XTHREE_THREE_HPP +#define XTHREE_THREE_HPP + +#include + +#include "xwidgets/xmaterialize.hpp" +#include "xwidgets/xobject.hpp" + +#include "xthreejs/xthreejs_config.hpp" + +#include + +namespace xthree +{ + + // + // xthree_widget declaration + // + + template + class xthree_widget : public xw::xobject + { + public: + + using base_type = xw::xobject; + using derived_type = D; + + void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const; + void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&); + + protected: + + xthree_widget(); + + using base_type::base_type; + + private: + + bool _previewable = true; + void set_defaults(); + }; + + using three_widget = xw::xmaterialize; + using three_widget_generator = xw::xgenerator; + + // + // xthree_widget implementation + // + + template + inline void xthree_widget::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers) + { + base_type::apply_patch(patch, buffers); + } + + template + inline void xthree_widget::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const + { + return base_type::serialize_state(state, buffers); + } + + template + inline xthree_widget::xthree_widget() + : base_type() + { + set_defaults(); + } + + template + inline void xthree_widget::set_defaults() + { + this->_model_module() = "jupyter-threejs"; + this->_model_module_version() = XTHREEJS_PROTOCOL_VERSION; + this->_view_module() = ""; + this->_view_module_version() = ""; + } +} +#endif \ No newline at end of file diff --git a/xthreejs/include/xthreejs/base/xthree_types.hpp b/xthreejs/include/xthreejs/base/xthree_types.hpp new file mode 100644 index 00000000..bb7456cd --- /dev/null +++ b/xthreejs/include/xthreejs/base/xthree_types.hpp @@ -0,0 +1,72 @@ +#ifndef XTHREE_THREE_TYPES_HPP +#define XTHREE_THREE_TYPES_HPP + +#include "xthree.hpp" + +#include "xtensor/xarray.hpp" +#include "xtensor/xadapt.hpp" + +#include +#include +#include +#include +#include + +namespace xthree +{ + using vector2 = std::array; + using vector3 = std::array; + using vector4 = std::array; + + using matrix3 = std::array; + using matrix4 = std::array; + + using face3 = std::tuple; + using euler = std::tuple; + + using dict = std::map>; + using dictvec = std::map>>; + + template + struct webgldataunion: public xt::xarray + { + using base_type = xt::xarray; + + webgldataunion(): base_type(){}; + webgldataunion(base_type& b): base_type(b){}; + + template + webgldataunion(const xt::xexpression& b) : base_type(b){}; + template + webgldataunion(xt::xexpression&& b) : base_type(std::move(b)){}; + + std::string type2str() const + { + return "float32"; + } + }; + + template + inline void xwidgets_deserialize(webgldataunion& value, const xeus::xjson& j, const xeus::buffer_sequence& buffers) + { + std::size_t index = xw::buffer_index(j.template get()); + std::vector shape = j["shape"]; + const auto& buffer = buffers[index]; + value = xt::adapt(static_cast(buffer.data()), + buffer.size() / sizeof(D), xt::no_ownership(), + shape); + } + + template + inline void xwidgets_serialize(const webgldataunion& value, xeus::xjson& j, xeus::buffer_sequence& buffers) + { + j = { + {"shape", value.shape()}, + {"dtype", value.type2str()}, + {"buffer", xw::xbuffer_reference_prefix() + std::to_string(buffers.size())} + }; + buffers.emplace_back(value.data(), sizeof(D) * value.size()); + } +} + +#endif diff --git a/xthreejs/include/xthreejs/core/xbuffer_attribute.hpp b/xthreejs/include/xthreejs/core/xbuffer_attribute.hpp new file mode 100644 index 00000000..89d0b8df --- /dev/null +++ b/xthreejs/include/xthreejs/core/xbuffer_attribute.hpp @@ -0,0 +1,140 @@ +#ifndef XTHREE_BUFFER_ATTRIBUTE_HPP +#define XTHREE_BUFFER_ATTRIBUTE_HPP + +#include "xtl/xoptional.hpp" +#include "xwidgets/xeither.hpp" +#include "xwidgets/xwidget.hpp" + +#include "../base/xenums.hpp" +#include "../base/xthree_types.hpp" +#include "../base/xthree.hpp" +#include "../base/xrender.hpp" + +namespace xthree +{ + template + struct xbuffer_traits; + + // + // buffer_attribute declaration + // + + template + class xbuffer_attribute : public xthree_widget + { + public: + + using base_type = xthree_widget; + using derived_type = D; + + using value_type = typename xbuffer_traits::value_type; + + void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const; + void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&); + + XPROPERTY(webgldataunion, derived_type, array); + XPROPERTY(bool, derived_type, dynamic, false); + XPROPERTY(bool, derived_type, needsUpdate, false); + XPROPERTY(bool, derived_type, normalized, true); + XPROPERTY(int, derived_type, version, -1); + + const std::vector& buffer_paths() const; + + std::shared_ptr> pre = nullptr; + + protected: + + xbuffer_attribute(); + using base_type::base_type; + + private: + + void set_defaults(); + }; + + template + using buffer_attribute = xw::xmaterialize; + + template + using buffer_attribute_generator = xw::xgenerator; + + template + struct xbuffer_traits> + { + using value_type = T; + }; + + template + struct xbuffer_traits> + { + using value_type = T; + }; + + // + // buffer_attribute implementation + // + + template + inline const std::vector& xbuffer_attribute::buffer_paths() const + { + static const std::vector default_buffer_paths = { + { "array", "buffer" }, + }; + return default_buffer_paths; + } + + template + inline void xbuffer_attribute::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const + { + base_type::serialize_state(state, buffers); + + xw::set_patch_from_property(array, state, buffers); + xw::set_patch_from_property(dynamic, state, buffers); + xw::set_patch_from_property(needsUpdate, state, buffers); + xw::set_patch_from_property(normalized, state, buffers); + xw::set_patch_from_property(version, state, buffers); + } + + template + inline void xbuffer_attribute::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers) + { + base_type::apply_patch(patch, buffers); + + xw::set_property_from_patch(array, patch, buffers); + xw::set_property_from_patch(dynamic, patch, buffers); + xw::set_property_from_patch(needsUpdate, patch, buffers); + xw::set_property_from_patch(normalized, patch, buffers); + xw::set_property_from_patch(version, patch, buffers); + } + + template + inline xbuffer_attribute::xbuffer_attribute() + : base_type() + { + set_defaults(); + } + + template + inline void xbuffer_attribute::set_defaults() + { + this->_model_name() = "BufferAttributeModel"; + this->_view_name() = ""; + } +} + +/********************* + * precompiled types * + *********************/ + +#ifdef XTHREEJS_PRECOMPILED + #ifndef _WIN32 + extern template class xw::xmaterialize; + extern template xw::xmaterialize::xmaterialize(); + extern template class xw::xtransport>; + extern template class xw::xgenerator; + extern template xw::xgenerator::xgenerator(); + extern template class xw::xtransport>; + #endif +#endif + +#endif \ No newline at end of file diff --git a/xthreejs/include/xthreejs/core/xinstanced_buffer_attribute.hpp b/xthreejs/include/xthreejs/core/xinstanced_buffer_attribute.hpp new file mode 100644 index 00000000..e8bdacad --- /dev/null +++ b/xthreejs/include/xthreejs/core/xinstanced_buffer_attribute.hpp @@ -0,0 +1,112 @@ +#ifndef XTHREE_INSTANCED_BUFFER_ATTRIBUTE_HPP +#define XTHREE_INSTANCED_BUFFER_ATTRIBUTE_HPP + +#include "xtl/xoptional.hpp" +#include "xwidgets/xeither.hpp" +#include "xwidgets/xwidget.hpp" + +#include "../base/xenums.hpp" +#include "../base/xthree_types.hpp" +#include "xbuffer_attribute.hpp" +#include "../base/xrender.hpp" + +namespace xthree +{ + // + // instanced_buffer_attribute declaration + // + + template + class xinstanced_buffer_attribute : public xbuffer_attribute + { + public: + + using base_type = xbuffer_attribute; + using derived_type = D; + + void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const; + void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&); + + XPROPERTY(int, derived_type, meshPerAttribute, 1); + + std::shared_ptr> pre = nullptr; + + protected: + + xinstanced_buffer_attribute(); + using base_type::base_type; + + private: + + void set_defaults(); + }; + + template + using instanced_buffer_attribute = xw::xmaterialize; + + template + using instanced_buffer_attribute_generator = xw::xgenerator; + + template + struct xbuffer_traits> + { + using value_type = T; + }; + + template + struct xbuffer_traits> + { + using value_type = T; + }; + + // + // instanced_buffer_attribute implementation + // + + template + inline void xinstanced_buffer_attribute::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const + { + base_type::serialize_state(state, buffers); + + xw::set_patch_from_property(meshPerAttribute, state, buffers); + } + + template + inline void xinstanced_buffer_attribute::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers) + { + base_type::apply_patch(patch, buffers); + + xw::set_property_from_patch(meshPerAttribute, patch, buffers); + } + + template + inline xinstanced_buffer_attribute::xinstanced_buffer_attribute() + : base_type() + { + set_defaults(); + } + + template + inline void xinstanced_buffer_attribute::set_defaults() + { + this->_model_name() = "InstancedBufferAttributeModel"; + this->_view_name() = ""; + } +} + +/********************* + * precompiled types * + *********************/ + +#ifdef XTHREEJS_PRECOMPILED + #ifndef _WIN32 + extern template class xw::xmaterialize; + extern template xw::xmaterialize::xmaterialize(); + extern template class xw::xtransport>; + extern template class xw::xgenerator; + extern template xw::xgenerator::xgenerator(); + extern template class xw::xtransport>; + #endif +#endif + +#endif \ No newline at end of file diff --git a/xthreejs/include/xthreejs/core/xobject3d.hpp b/xthreejs/include/xthreejs/core/xobject3d.hpp new file mode 100644 index 00000000..5f622d85 --- /dev/null +++ b/xthreejs/include/xthreejs/core/xobject3d.hpp @@ -0,0 +1,106 @@ +#ifndef XTHREE_OBJECT3D_HPP +#define XTHREE_OBJECT3D_HPP + +#include "xtl/xoptional.hpp" +#include "xwidgets/xeither.hpp" +#include "xwidgets/xwidget.hpp" +#include "xwidgets/xtransport.hpp" + +#include "../base/xenums.hpp" +#include "../base/xthree_types.hpp" +#include "../base/xthree.hpp" + +#include "xobject3d_autogen.hpp" + + +namespace xthree +{ + // + // object3d declaration + // + + template + class xobject3d : public xobject3d_base + { + public: + using base_type = xobject3d_base; + using derived_type = D; + + template + void add(const xthree_widget& w); + + template + void add(xthree_widget&& w); + + protected: + + xobject3d(); + using base_type::base_type; + + private: + + void set_defaults(); + }; + + using object3d = xw::xmaterialize; + + using object3d_generator = xw::xgenerator; + + // + // object3d implementation + // + + template + inline xobject3d::xobject3d() + : base_type() + { + set_defaults(); + } + + template + inline void xobject3d::set_defaults() + { + this->_model_name() = "Object3DModel"; + this->_view_name() = ""; + } + + template + template + inline void xobject3d::add(const xthree_widget& w) + { + this->children().emplace_back(xw::make_id_holder(w.id())); + xeus::xjson state; + xeus::buffer_sequence buffers; + xw::set_patch_from_property(this->children, state, buffers); + this->send_patch(std::move(state), std::move(buffers)); + } + + template + template + inline void xobject3d::add(xthree_widget&& w) + { + this->children().emplace_back(xw::make_owning_holder(std::move(w))); + xeus::xjson state; + xeus::buffer_sequence buffers; + xw::set_patch_from_property(this->children, state, buffers); + this->send_patch(std::move(state), std::move(buffers)); + } + +} + +/********************* + * precompiled types * + *********************/ + +#ifdef XTHREEJS_PRECOMPILED + #ifndef _WIN32 + extern template class xw::xmaterialize; + extern template xw::xmaterialize::xmaterialize(); + extern template class xw::xtransport>; + extern template class xw::xgenerator; + extern template xw::xgenerator::xgenerator(); + extern template class xw::xtransport>; + #endif +#endif + +#endif \ No newline at end of file diff --git a/xthreejs/include/xthreejs/core/xrenderer.hpp b/xthreejs/include/xthreejs/core/xrenderer.hpp new file mode 100644 index 00000000..8011b46b --- /dev/null +++ b/xthreejs/include/xthreejs/core/xrenderer.hpp @@ -0,0 +1,117 @@ +#ifndef XTHREE_RENDERER_HPP +#define XTHREE_RENDERER_HPP + +#include "xtl/xoptional.hpp" +#include "xwidgets/xeither.hpp" +#include "xwidgets/xwidget.hpp" + +#include "../base/xenums.hpp" +#include "../base/xthree_types.hpp" +#include "../base/xthree.hpp" +#include "../base/xrender.hpp" +#include "../scenes/xscene_autogen.hpp" +#include "../cameras/xcamera_autogen.hpp" +#include "../controls/xcontrols_autogen.hpp" + +namespace xthree +{ + // + // renderer declaration + // + + template + class xrenderer : public xrender_widget + { + public: + + using base_type = xrender_widget; + using derived_type = D; + + void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const; + void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&); + + XPROPERTY(int, derived_type, _width, 200); + XPROPERTY(int, derived_type, _height, 200); + XPROPERTY(xw::xholder, derived_type, scene); + XPROPERTY(xw::xholder, derived_type, camera); + XPROPERTY(std::vector>, derived_type, controls); + //XPROPERTY(effect, derived_type, effect = Instance(Effect, allow_none=True).tag(sync=True, **widget_serialization) + XPROPERTY(xw::html_color, derived_type, background, "black"); + XPROPERTY(double, derived_type, background_opacity, 1.); + + protected: + + xrenderer(); + + private: + + void set_defaults(); + }; + + using renderer = xw::xmaterialize; + + using renderer_generator = xw::xgenerator; + + // + // renderer implementation + // + + template + inline void xrenderer::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers) + { + base_type::apply_patch(patch, buffers); + + xw::set_property_from_patch(_width, patch, buffers); + xw::set_property_from_patch(_height, patch, buffers); + xw::set_property_from_patch(scene, patch, buffers); + xw::set_property_from_patch(camera, patch, buffers); + xw::set_property_from_patch(controls, patch, buffers); + xw::set_property_from_patch(background, patch, buffers); + xw::set_property_from_patch(background_opacity, patch, buffers); + } + + template + inline void xrenderer::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const + { + base_type::serialize_state(state, buffers); + + xw::set_patch_from_property(_width, state, buffers); + xw::set_patch_from_property(_height, state, buffers); + xw::set_patch_from_property(scene, state, buffers); + xw::set_patch_from_property(camera, state, buffers); + xw::set_patch_from_property(controls, state, buffers); + xw::set_patch_from_property(background, state, buffers); + xw::set_patch_from_property(background_opacity, state, buffers); + } + + template + inline xrenderer::xrenderer() + : base_type() + { + set_defaults(); + } + + template + inline void xrenderer::set_defaults() + { + this->_model_name() = "RendererModel"; + this->_view_name() = "RendererView"; + } +} + +/********************* + * precompiled types * + *********************/ + +#ifdef XTHREEJS_PRECOMPILED + #ifndef _WIN32 + extern template class xw::xmaterialize; + extern template xw::xmaterialize::xmaterialize(); + extern template class xw::xtransport>; + extern template class xw::xgenerator; + extern template xw::xgenerator::xgenerator(); + extern template class xw::xtransport>; + #endif +#endif + +#endif \ No newline at end of file diff --git a/xthreejs/include/xthreejs/lights/xlight_shadow.hpp b/xthreejs/include/xthreejs/lights/xlight_shadow.hpp new file mode 100644 index 00000000..c4d788b2 --- /dev/null +++ b/xthreejs/include/xthreejs/lights/xlight_shadow.hpp @@ -0,0 +1,112 @@ +#ifndef XTHREE_LIGHT_SHADOW_HPP +#define XTHREE_LIGHT_SHADOW_HPP + +#include "xtl/xoptional.hpp" +#include "xwidgets/xeither.hpp" +#include "xwidgets/xwidget.hpp" + +#include "../base/xenums.hpp" +#include "../base/xthree_types.hpp" +#include "../base/xthree.hpp" +#include "../base/xrender.hpp" +#include "../core/xobject3d.hpp" + +namespace xthree +{ + // + // light_shadow declaration + // + + template + class xlight_shadow : public xthree_widget + { + public: + + using base_type = xthree_widget; + using derived_type = D; + + void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const; + void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&); + + XPROPERTY(xw::xholder, derived_type, camera, object3d()); + XPROPERTY(double, derived_type, bias, 0); + XPROPERTY(vector2, derived_type, mapSize, vector2({512,512})); + XPROPERTY(double, derived_type, radius, 1); + + + std::shared_ptr> pre = nullptr; + + protected: + + xlight_shadow(); + using base_type::base_type; + + private: + + void set_defaults(); + }; + + using light_shadow = xw::xmaterialize; + + using light_shadow_generator = xw::xgenerator; + + // + // light_shadow implementation + // + + + template + inline void xlight_shadow::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const + { + base_type::serialize_state(state, buffers); + + xw::set_patch_from_property(camera, state, buffers); + xw::set_patch_from_property(bias, state, buffers); + xw::set_patch_from_property(mapSize, state, buffers); + xw::set_patch_from_property(radius, state, buffers); + } + + template + inline void xlight_shadow::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers) + { + base_type::apply_patch(patch, buffers); + + xw::set_property_from_patch(camera, patch, buffers); + xw::set_property_from_patch(bias, patch, buffers); + xw::set_property_from_patch(mapSize, patch, buffers); + xw::set_property_from_patch(radius, patch, buffers); + } + + template + inline xlight_shadow::xlight_shadow() + : base_type() + { + set_defaults(); + } + + template + inline void xlight_shadow::set_defaults() + { + this->_model_name() = "LightShadowModel"; + this->_view_name() = ""; + } +} + +xeus::xjson mime_bundle_repr(xw::xmaterialize& widget); + +/********************* + * precompiled types * + *********************/ + +#ifdef XTHREEJS_PRECOMPILED + #ifndef _WIN32 + extern template class xw::xmaterialize; + extern template xw::xmaterialize::xmaterialize(); + extern template class xw::xtransport>; + extern template class xw::xgenerator; + extern template xw::xgenerator::xgenerator(); + extern template class xw::xtransport>; + #endif +#endif + +#endif \ No newline at end of file diff --git a/xthreejs/include/xthreejs/materials/xmaterial.hpp b/xthreejs/include/xthreejs/materials/xmaterial.hpp new file mode 100644 index 00000000..e46b2e1e --- /dev/null +++ b/xthreejs/include/xthreejs/materials/xmaterial.hpp @@ -0,0 +1,91 @@ +#ifndef XTHREE_MATERIAL_HPP +#define XTHREE_MATERIAL_HPP + +#include "xtl/xoptional.hpp" +#include "xwidgets/xeither.hpp" +#include "xwidgets/xwidget.hpp" +#include "xwidgets/xtransport.hpp" + +#include "../base/xenums.hpp" +#include "../base/xthree_types.hpp" +#include "../base/xthree.hpp" + +#include "xmaterial_autogen.hpp" + + +namespace xthree +{ + // + // material declaration + // + + template + class xmaterial : public xmaterial_base + { + public: + using base_type = xmaterial_base; + using derived_type = D; + + void update(); + + protected: + + xmaterial(); + using base_type::base_type; + + private: + + void set_defaults(); + }; + + using material = xw::xmaterialize; + + using material_generator = xw::xgenerator; + + // + // material implementation + // + + template + inline xmaterial::xmaterial() + : base_type() + { + set_defaults(); + } + + template + inline void xmaterial::set_defaults() + { + this->_model_name() = "MaterialModel"; + this->_view_name() = ""; + } + + template + inline void xmaterial::update() + { + xeus::xjson content; + xeus::buffer_sequence buffers; + content["type"] = "needsUpdate"; + this->send(std::move(content), std::move(buffers)); + } + +} + +xeus::xjson mime_bundle_repr(xthree::material& widget); + +/********************* + * precompiled types * + *********************/ + +#ifdef XTHREEJS_PRECOMPILED + #ifndef _WIN32 + extern template class xw::xmaterialize; + extern template xw::xmaterialize::xmaterialize(); + extern template class xw::xtransport>; + extern template class xw::xgenerator; + extern template xw::xgenerator::xgenerator(); + extern template class xw::xtransport>; + #endif +#endif + +#endif \ No newline at end of file diff --git a/xthreejs/include/xthreejs/math/xplane.hpp b/xthreejs/include/xthreejs/math/xplane.hpp new file mode 100644 index 00000000..92647768 --- /dev/null +++ b/xthreejs/include/xthreejs/math/xplane.hpp @@ -0,0 +1,99 @@ +#ifndef XTHREE_PLANE_HPP +#define XTHREE_PLANE_HPP + +#include "xtl/xoptional.hpp" +#include "xwidgets/xeither.hpp" +#include "xwidgets/xwidget.hpp" + +#include "../base/xenums.hpp" +#include "../base/xthree_types.hpp" +#include "../base/xthree.hpp" + +namespace xthree +{ + // + // plane declaration + // + + template + class xplane : public xthree_widget + { + public: + + using base_type = xthree_widget; + using derived_type = D; + + void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const; + void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&); + + XPROPERTY(vector3, derived_type, normal, vector3({0,0,0})); + XPROPERTY(double, derived_type, constant, 0); + + protected: + + xplane(); + using base_type::base_type; + + private: + + void set_defaults(); + }; + + using plane = xw::xmaterialize; + + using plane_generator = xw::xgenerator; + + // + // plane implementation + // + + + template + inline void xplane::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const + { + base_type::serialize_state(state, buffers); + + xw::set_patch_from_property(normal, state, buffers); + xw::set_patch_from_property(constant, state, buffers); + } + + template + inline void xplane::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers) + { + base_type::apply_patch(patch, buffers); + + xw::set_property_from_patch(normal, patch, buffers); + xw::set_property_from_patch(constant, patch, buffers); + } + + template + inline xplane::xplane() + : base_type() + { + set_defaults(); + } + + template + inline void xplane::set_defaults() + { + this->_model_name() = "PlaneModel"; + this->_view_name() = ""; + } +} + +/********************* + * precompiled types * + *********************/ + +#ifdef XTHREEJS_PRECOMPILED + #ifndef _WIN32 + extern template class xw::xmaterialize; + extern template xw::xmaterialize::xmaterialize(); + extern template class xw::xtransport>; + extern template class xw::xgenerator; + extern template xw::xgenerator::xgenerator(); + extern template class xw::xtransport>; + #endif +#endif + +#endif \ No newline at end of file diff --git a/xthreejs/include/xthreejs/renderers/shaders/xuniform_lib.hpp b/xthreejs/include/xthreejs/renderers/shaders/xuniform_lib.hpp new file mode 100644 index 00000000..616799fa --- /dev/null +++ b/xthreejs/include/xthreejs/renderers/shaders/xuniform_lib.hpp @@ -0,0 +1,255 @@ +#ifndef XTHREE_UNIFORMLIB_HPP +#define XTHREE_UNIFORMLIB_HPP + +#include + +namespace xthree +{ + static auto xuniform_lib = R"( +{ + "common": { + "diffuse": { + "value": 15658734 + }, + "opacity": { + "value": 1 + }, + "map": { + "value": null + }, + "uvTransform": { + "value": { + "elements": [ + 1, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 1 + ] + } + }, + "alphaMap": { + "value": null + } + }, + "specularmap": { + "specularMap": { + "value": null + } + }, + "envmap": { + "envMap": { + "value": null + }, + "flipEnvMap": { + "value": -1 + }, + "reflectivity": { + "value": 1 + }, + "refractionRatio": { + "value": 0.98 + } + }, + "aomap": { + "aoMap": { + "value": null + }, + "aoMapIntensity": { + "value": 1 + } + }, + "lightmap": { + "lightMap": { + "value": null + }, + "lightMapIntensity": { + "value": 1 + } + }, + "emissivemap": { + "emissiveMap": { + "value": null + } + }, + "bumpmap": { + "bumpMap": { + "value": null + }, + "bumpScale": { + "value": 1 + } + }, + "normalmap": { + "normalMap": { + "value": null + }, + "normalScale": { + "value": { + "x": 1, + "y": 1 + } + } + }, + "displacementmap": { + "displacementMap": { + "value": null + }, + "displacementScale": { + "value": 1 + }, + "displacementBias": { + "value": 0 + } + }, + "roughnessmap": { + "roughnessMap": { + "value": null + } + }, + "metalnessmap": { + "metalnessMap": { + "value": null + } + }, + "gradientmap": { + "gradientMap": { + "value": null + } + }, + "fog": { + "fogDensity": { + "value": 0.00025 + }, + "fogNear": { + "value": 1 + }, + "fogFar": { + "value": 2000 + }, + "fogColor": { + "value": 16777215 + } + }, + "lights": { + "ambientLightColor": { + "value": [] + }, + "directionalLights": { + "value": [], + "properties": { + "direction": {}, + "color": {}, + "shadow": {}, + "shadowBias": {}, + "shadowRadius": {}, + "shadowMapSize": {} + } + }, + "directionalShadowMap": { + "value": [] + }, + "directionalShadowMatrix": { + "value": [] + }, + "spotLights": { + "value": [], + "properties": { + "color": {}, + "position": {}, + "direction": {}, + "distance": {}, + "coneCos": {}, + "penumbraCos": {}, + "decay": {}, + "shadow": {}, + "shadowBias": {}, + "shadowRadius": {}, + "shadowMapSize": {} + } + }, + "spotShadowMap": { + "value": [] + }, + "spotShadowMatrix": { + "value": [] + }, + "pointLights": { + "value": [], + "properties": { + "color": {}, + "position": {}, + "decay": {}, + "distance": {}, + "shadow": {}, + "shadowBias": {}, + "shadowRadius": {}, + "shadowMapSize": {}, + "shadowCameraNear": {}, + "shadowCameraFar": {} + } + }, + "pointShadowMap": { + "value": [] + }, + "pointShadowMatrix": { + "value": [] + }, + "hemisphereLights": { + "value": [], + "properties": { + "direction": {}, + "skyColor": {}, + "groundColor": {} + } + }, + "rectAreaLights": { + "value": [], + "properties": { + "color": {}, + "position": {}, + "width": {}, + "height": {} + } + } + }, + "points": { + "diffuse": { + "value": 15658734 + }, + "opacity": { + "value": 1 + }, + "size": { + "value": 1 + }, + "scale": { + "value": 1 + }, + "map": { + "value": null + }, + "uvTransform": { + "value": { + "elements": [ + 1, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 1 + ] + } + } + } +} + )"_json; +} +#endif \ No newline at end of file diff --git a/xthreejs/include/xthreejs/renderers/webgl/xwebgl_shadow_map.hpp b/xthreejs/include/xthreejs/renderers/webgl/xwebgl_shadow_map.hpp new file mode 100644 index 00000000..04393096 --- /dev/null +++ b/xthreejs/include/xthreejs/renderers/webgl/xwebgl_shadow_map.hpp @@ -0,0 +1,103 @@ +#ifndef XTHREE_WEBGL_SHADOW_MAP_HPP +#define XTHREE_WEBGL_SHADOW_MAP_HPP + +#include "xtl/xoptional.hpp" +#include "xwidgets/xeither.hpp" +#include "xwidgets/xwidget.hpp" + +#include "../../base/xenums.hpp" +#include "../../base/xthree_types.hpp" +#include "../../base/xthree.hpp" + +namespace xthree +{ + // + // webgl_shadow_map declaration + // + + template + class xwebgl_shadow_map : public xthree_widget + { + public: + + using base_type = xthree_widget; + using derived_type = D; + + void serialize_state(xeus::xjson&, xeus::buffer_sequence&) const; + void apply_patch(const xeus::xjson&, const xeus::buffer_sequence&); + + XPROPERTY(bool, derived_type, enabled, false); + XPROPERTY(std::string, derived_type, type, "PCFShadowMap", xenums::ShadowTypes); + XPROPERTY(bool, derived_type, renderReverseSided, false); + XPROPERTY(bool, derived_type, renderSingleSided, true); + + protected: + + xwebgl_shadow_map(); + using base_type::base_type; + + private: + + void set_defaults(); + }; + + using webgl_shadow_map = xw::xmaterialize; + + using webgl_shadow_map_generator = xw::xgenerator; + + // + // webgl_shadow_map implementation + // + + + template + inline void xwebgl_shadow_map::serialize_state(xeus::xjson& state, xeus::buffer_sequence& buffers) const + { + base_type::serialize_state(state, buffers); + + xw::set_patch_from_property(enabled, state, buffers); + xw::set_patch_from_property(type, state, buffers); + xw::set_patch_from_property(renderReverseSided, state, buffers); + xw::set_patch_from_property(renderSingleSided, state, buffers); + } + + template + inline void xwebgl_shadow_map::apply_patch(const xeus::xjson& patch, const xeus::buffer_sequence& buffers) + { + base_type::apply_patch(patch, buffers); + + xw::set_property_from_patch(enabled, patch, buffers); + xw::set_property_from_patch(type, patch, buffers); + xw::set_property_from_patch(renderReverseSided, patch, buffers); + xw::set_property_from_patch(renderSingleSided, patch, buffers); + } + + template + inline xwebgl_shadow_map::xwebgl_shadow_map() + : base_type() + { + set_defaults(); + } + + template + inline void xwebgl_shadow_map::set_defaults() + { + this->_model_name() = "WebGLShadowMapModel"; + this->_view_name() = ""; + } +} + +/********************* + * precompiled types * + *********************/ + +//#ifndef _WIN32 +// extern template class xw::xmaterialize; +// extern template xw::xmaterialize::xmaterialize(); +// extern template class xw::xtransport>; +// extern template class xw::xgenerator; +// extern template xw::xgenerator::xgenerator(); +// extern template class xw::xtransport>; +//#endif + +#endif \ No newline at end of file diff --git a/xthreejs/include/xthreejs/renderers/xwebgl_renderer.hpp b/xthreejs/include/xthreejs/renderers/xwebgl_renderer.hpp new file mode 100644 index 00000000..8139b2e9 --- /dev/null +++ b/xthreejs/include/xthreejs/renderers/xwebgl_renderer.hpp @@ -0,0 +1,103 @@ +#ifndef XTHREE_WEBGL_RENDERER_HPP +#define XTHREE_WEBGL_RENDERER_HPP + +#include "xtl/xoptional.hpp" +#include "xwidgets/xeither.hpp" +#include "xwidgets/xwidget.hpp" + +#include "../base/xenums.hpp" +#include "../base/xthree_types.hpp" +#include "../base/xrender.hpp" +#include "../scenes/xscene_autogen.hpp" +#include "../cameras/xcamera_autogen.hpp" +#include "../cameras/xperspective_camera_autogen.hpp" + +namespace xthree +{ + // + // xwebgl_renderer declaration + // + template + class xwebgl_renderer : public xrender_widget + { + public: + + using base_type = xrender_widget; + using derived_type = D; + + void render(scene& s, perspective_camera& c); + + void freeze(); + protected: + + xwebgl_renderer(); + using base_type::base_type; + + private: + + void set_defaults(); + }; + + using webgl_renderer = xw::xmaterialize; + using webgl_renderer_generator = xw::xgenerator; + + // + // xwebgl_renderer implementation + // + + template + inline xwebgl_renderer::xwebgl_renderer() + : base_type() + { + set_defaults(); + } + + template + inline void xwebgl_renderer::set_defaults() + { + this->_model_name() = "WebGLRendererModel"; + this->_view_name() = "WebGLRendererView"; + } + + template + inline void xwebgl_renderer::render(scene& s, perspective_camera& c) + { + xeus::xjson content; + xeus::buffer_sequence buffers; + content["type"] = "render"; + + xeus::xjson scene_content; + xw::to_json(scene_content, s); + content["scene"] = scene_content; + xeus::xjson camera_content; + xw::to_json(camera_content, c); + content["camera"] = camera_content; + this->send(std::move(content), std::move(buffers)); + } + + template + inline void xwebgl_renderer::freeze() + { + xeus::xjson content; + xeus::buffer_sequence buffers; + content["type"] = "freeze"; + this->send(std::move(content), std::move(buffers)); + } +} + +/********************* + * precompiled types * + *********************/ + +#ifdef XTHREEJS_PRECOMPILED + #ifndef _WIN32 + extern template class xw::xmaterialize; + extern template xw::xmaterialize::xmaterialize(); + extern template class xw::xtransport>; + extern template class xw::xgenerator; + extern template xw::xgenerator::xgenerator(); + extern template class xw::xtransport>; + #endif +#endif + +#endif \ No newline at end of file diff --git a/xthreejs/include/xthreejs/xthreejs_config.hpp.in b/xthreejs/include/xthreejs/xthreejs_config.hpp.in new file mode 100644 index 00000000..bc1e5962 --- /dev/null +++ b/xthreejs/include/xthreejs/xthreejs_config.hpp.in @@ -0,0 +1,44 @@ +#ifndef XTHREEJS_CONFIG_HPP +#define XTHREEJS_CONFIG_HPP + +#ifdef _WIN32 + #ifdef XTHREEJS_EXPORTS + #define XTHREEJS_API __declspec(dllexport) + #else + #define XTHREEJS_API __declspec(dllimport) + #endif +#else + #define XTHREEJS_API +#endif + +// Project version +#define XTHREEJS_VERSION_MAJOR 0 +#define XTHREEJS_VERSION_MINOR 0 +#define XTHREEJS_VERSION_PATCH 1 + +// Binary version +#define XTHREEJS_BINARY_CURRENT 1 +#define XTHREEJS_BINARY_REVISION 0 +#define XTHREEJS_BINARY_AGE 1 + +// Semver requirement for threejs +#define XTHREEJS_PROTOCOL_VERSION_MAJOR 1 +#define XTHREEJS_PROTOCOL_VERSION_MINOR 1 +#define XTHREEJS_PROTOCOL_VERSION_PATCH 0 + +// Composing the protocol version string from major, minor and patch +#define XTHREEJS_CONCATENATE(A, B) XTHREEJS_CONCATENATE_IMPL(A, B) +#define XTHREEJS_CONCATENATE_IMPL(A, B) A##B +#define XTHREEJS_STRINGIFY(a) XTHREEJS_STRINGIFY_IMPL(a) +#define XTHREEJS_STRINGIFY_IMPL(a) #a + +#define XTHREEJS_PROTOCOL_VERSION XTHREEJS_STRINGIFY(XTHREEJS_CONCATENATE(XTHREEJS_PROTOCOL_VERSION_MAJOR, \ + XTHREEJS_CONCATENATE(.,XTHREEJS_CONCATENATE(XTHREEJS_PROTOCOL_VERSION_MINOR, \ + XTHREEJS_CONCATENATE(.,XTHREEJS_PROTOCOL_VERSION_PATCH))))) + +#ifdef __CLING__ +#pragma cling add_library_path(@XTHREEJS_INSTALL_LIBRARY_DIR@) +#pragma cling load("libxthreejs") +#endif + +#endif diff --git a/xthreejs/src/animation/xanimation_action.cpp b/xthreejs/src/animation/xanimation_action.cpp new file mode 100644 index 00000000..39442248 --- /dev/null +++ b/xthreejs/src/animation/xanimation_action.cpp @@ -0,0 +1,10 @@ +#include "xthreejs/animation/xanimation_action.hpp" + +#ifdef XTHREEJS_PRECOMPILED + template class xw::xmaterialize; + template xw::xmaterialize::xmaterialize(); + template class xw::xtransport>; + template class xw::xgenerator; + template xw::xgenerator::xgenerator(); + template class xw::xtransport>; +#endif \ No newline at end of file diff --git a/xthreejs/src/base/xrender.cpp b/xthreejs/src/base/xrender.cpp new file mode 100644 index 00000000..582a7cbc --- /dev/null +++ b/xthreejs/src/base/xrender.cpp @@ -0,0 +1,8 @@ +#include "xthreejs/base/xrender.hpp" + +#ifdef XTHREEJS_PRECOMPILED + template class xw::xmaterialize; + template class xw::xtransport>; + template class xw::xgenerator; + template class xw::xtransport>; +#endif \ No newline at end of file diff --git a/xthreejs/src/base/xthree_types.cpp b/xthreejs/src/base/xthree_types.cpp new file mode 100644 index 00000000..d15b3ebd --- /dev/null +++ b/xthreejs/src/base/xthree_types.cpp @@ -0,0 +1,37 @@ +#include "xthreejs/base/xthree_types.hpp" + +template<> +std::string xthree::webgldataunion::type2str() const +{ + return "float32"; +} + +template<> +std::string xthree::webgldataunion::type2str() const +{ + return "int32"; +} + +template<> +std::string xthree::webgldataunion::type2str() const +{ + return "uint32"; +} + +template<> +std::string xthree::webgldataunion::type2str() const +{ + return "int16"; +} + +template<> +std::string xthree::webgldataunion::type2str() const +{ + return "uint16"; +} + +template<> +std::string xthree::webgldataunion::type2str() const +{ + return "uint8"; +} diff --git a/xthreejs/src/core/xbuffer_attribute.cpp b/xthreejs/src/core/xbuffer_attribute.cpp new file mode 100644 index 00000000..3fe32cfb --- /dev/null +++ b/xthreejs/src/core/xbuffer_attribute.cpp @@ -0,0 +1,10 @@ +//#include "xthreejs/core/xbuffer_attribute.hpp" + +// #ifdef XTHREEJS_PRECOMPILED +// template class xw::xmaterialize; +// template xw::xmaterialize::xmaterialize(); +// template class xw::xtransport>; +// template class xw::xgenerator; +// template xw::xgenerator::xgenerator(); +// template class xw::xtransport>; +// #endif \ No newline at end of file diff --git a/xthreejs/src/core/xinstanced_buffer_attribute.cpp b/xthreejs/src/core/xinstanced_buffer_attribute.cpp new file mode 100644 index 00000000..d8192749 --- /dev/null +++ b/xthreejs/src/core/xinstanced_buffer_attribute.cpp @@ -0,0 +1,10 @@ +//#include "xthreejs/core/xinstanced_buffer_attribute.hpp" + +// #ifdef XTHREEJS_PRECOMPILED +// template class xw::xmaterialize; +// template xw::xmaterialize::xmaterialize(); +// template class xw::xtransport>; +// template class xw::xgenerator; +// template xw::xgenerator::xgenerator(); +// template class xw::xtransport>; +// #endif \ No newline at end of file diff --git a/xthreejs/src/core/xobject3d.cpp b/xthreejs/src/core/xobject3d.cpp new file mode 100644 index 00000000..73eea4fc --- /dev/null +++ b/xthreejs/src/core/xobject3d.cpp @@ -0,0 +1,10 @@ +#include "xthreejs/core/xobject3d.hpp" + +#ifdef XTHREEJS_PRECOMPILED + template class xw::xmaterialize; + template xw::xmaterialize::xmaterialize(); + template class xw::xtransport>; + template class xw::xgenerator; + template xw::xgenerator::xgenerator(); + template class xw::xtransport>; +#endif \ No newline at end of file diff --git a/xthreejs/src/core/xrenderer.cpp b/xthreejs/src/core/xrenderer.cpp new file mode 100644 index 00000000..feeebd38 --- /dev/null +++ b/xthreejs/src/core/xrenderer.cpp @@ -0,0 +1,10 @@ +#include "xthreejs/core/xrenderer.hpp" + +#ifdef XTHREEJS_PRECOMPILED + template class xw::xmaterialize; + template xw::xmaterialize::xmaterialize(); + template class xw::xtransport>; + template class xw::xgenerator; + template xw::xgenerator::xgenerator(); + template class xw::xtransport>; +#endif \ No newline at end of file diff --git a/xthreejs/src/lights/xlight_shadow.cpp b/xthreejs/src/lights/xlight_shadow.cpp new file mode 100644 index 00000000..abed8d29 --- /dev/null +++ b/xthreejs/src/lights/xlight_shadow.cpp @@ -0,0 +1,17 @@ +#include "xthreejs/lights/xlight_shadow.hpp" + +xeus::xjson mime_bundle_repr(xw::xmaterialize& widget) +{ + if (not widget.pre) + widget.pre = std::make_shared(xthree::preview(widget)); + return mime_bundle_repr(*widget.pre); +} + +#ifdef XTHREEJS_PRECOMPILED + template class xw::xmaterialize; + template xw::xmaterialize::xmaterialize(); + template class xw::xtransport>; + template class xw::xgenerator; + template xw::xgenerator::xgenerator(); + template class xw::xtransport>; +#endif \ No newline at end of file diff --git a/xthreejs/src/math/xplane.cpp b/xthreejs/src/math/xplane.cpp new file mode 100644 index 00000000..d86c4528 --- /dev/null +++ b/xthreejs/src/math/xplane.cpp @@ -0,0 +1,10 @@ +#include "xthreejs/math/xplane.hpp" + +#ifdef XTHREEJS_PRECOMPILED + template class xw::xmaterialize; + template xw::xmaterialize::xmaterialize(); + template class xw::xtransport>; + template class xw::xgenerator; + template xw::xgenerator::xgenerator(); + template class xw::xtransport>; +#endif \ No newline at end of file diff --git a/xthreejs/xthreejs/base/xenums.hpp b/xthreejs/xthreejs/base/xenums.hpp new file mode 100644 index 00000000..e42d4d7c --- /dev/null +++ b/xthreejs/xthreejs/base/xenums.hpp @@ -0,0 +1,210 @@ +#pragma once + +// +// This file auto-generated with generate-enums.js +// Date: Thu Jan 25 2018 04:46:33 GMT+0100 (CET) +// + +#include "xwidgets/xeither.hpp" + +namespace xthree{ + namespace xenums{ + + auto Equations = XEITHER( + "AddEquation", + "SubtractEquation", + "ReverseSubtractEquation", + "MinEquation", + "MaxEquation", + ); + + auto BlendFactors = XEITHER( + "ZeroFactor", + "OneFactor", + "SrcColorFactor", + "OneMinusSrcColorFactor", + "SrcAlphaFactor", + "OneMinusSrcAlphaFactor", + "DstAlphaFactor", + "OneMinusDstAlphaFactor", + "DstColorFactor", + "OneMinusDstColorFactor", + "SrcAlphaSaturateFactor", + ); + + auto Side = XEITHER( + "FrontSide", + "BackSide", + "DoubleSide", + ); + + auto Shading = XEITHER( + "FlatShading", + "SmoothShading", + ); + + auto Colors = XEITHER( + "NoColors", + "FaceColors", + "VertexColors", + ); + + auto BlendingMode = XEITHER( + "NoBlending", + "NormalBlending", + "AdditiveBlending", + "SubtractiveBlending", + "MultiplyBlending", + "CustomBlending", + ); + + auto DepthMode = XEITHER( + "NeverDepth", + "AlwaysDepth", + "LessDepth", + "LessEqualDepth", + "EqualDepth", + "GreaterEqualDepth", + "GreaterDepth", + "NotEqualDepth", + ); + + auto Operations = XEITHER( + "MultiplyOperation", + "MixOperation", + "AddOperation", + ); + + auto MappingModes = XEITHER( + "UVMapping", + "CubeReflectionMapping", + "CubeRefractionMapping", + "EquirectangularReflectionMapping", + "EquirectangularRefractionMapping", + "SphericalReflectionMapping", + "CubeUVReflectionMapping", + "CubeUVRefractionMapping", + ); + + auto WrappingModes = XEITHER( + "RepeatWrapping", + "ClampToEdgeWrapping", + "MirroredRepeatWrapping", + ); + + auto Filters = XEITHER( + "NearestFilter", + "NearestMipMapNearestFilter", + "NearestMipMapLinearFilter", + "LinearFilter", + "LinearMipMapNearestFilter", + "LinearMipMapLinearFilter", + ); + + auto DataTypes = XEITHER( + "UnsignedByteType", + "ByteType", + "ShortType", + "UnsignedShortType", + "IntType", + "UnsignedIntType", + "FloatType", + "HalfFloatType", + ); + + auto PixelTypes = XEITHER( + "UnsignedShort4444Type", + "UnsignedShort5551Type", + "UnsignedShort565Type", + "UnsignedInt248Type", + ); + + auto PixelFormats = XEITHER( + "AlphaFormat", + "RGBFormat", + "RGBAFormat", + "LuminanceFormat", + "LuminanceAlphaFormat", + "DepthFormat", + "DepthStencilFormat", + ); + + auto DepthFormats = XEITHER( + "DepthFormat", + "DepthStencilFormat", + ); + + auto CompressedTextureFormats = XEITHER( + "RGB_S3TC_DXT1_Format", + "RGBA_S3TC_DXT1_Format", + "RGBA_S3TC_DXT3_Format", + "RGBA_S3TC_DXT5_Format", + "RGB_PVRTC_4BPPV1_Format", + "RGB_PVRTC_2BPPV1_Format", + "RGBA_PVRTC_4BPPV1_Format", + "RGBA_PVRTC_2BPPV1_Format", + "RGB_ETC1_Format", + ); + + auto TextureEncodings = XEITHER( + "LinearEncoding", + "sRGBEncoding", + "RGBEEncoding", + "LogLuvEncoding", + "RGBM7Encoding", + "RGBM16Encoding", + "RGBDEncoding", + "GammaEncoding", + ); + + auto CullFaceModes = XEITHER( + "CullFaceNone", + "CullFaceBack", + "CullFaceFront", + "CullFaceFrontBack", + ); + + auto FrontFaceDirection = XEITHER( + "FrontFaceDirectionCW", + "FrontFaceDirectionCCW", + ); + + auto ShadowTypes = XEITHER( + "BasicShadowMap", + "PCFShadowMap", + "PCFSoftShadowMap", + ); + + auto ToneMappings = XEITHER( + "NoToneMapping", + "LinearToneMapping", + "ReinhardToneMapping", + "Uncharted2ToneMapping", + "CineonToneMapping", + ); + + auto LoopModes = XEITHER( + "LoopOnce", + "LoopRepeat", + "LoopPingPong", + ); + + auto InterpolationModes = XEITHER( + "InterpolateDiscrete", + "InterpolateLinear", + "InterpolateSmooth", + ); + + auto EndingModes = XEITHER( + "ZeroCurvatureEnding", + "ZeroSlopeEnding", + "WrapAroundEnding", + ); + + auto DrawModes = XEITHER( + "TrianglesDrawMode", + "TriangleStripDrawMode", + "TriangleFanDrawMode", + ); + } +} \ No newline at end of file diff --git a/xthreejs/xthreejs/base/xrender.hpp b/xthreejs/xthreejs/base/xrender.hpp new file mode 100644 index 00000000..c0a29839 --- /dev/null +++ b/xthreejs/xthreejs/base/xrender.hpp @@ -0,0 +1,219 @@ +#ifndef XTHREE_RENDER_HPP +#define XTHREE_RENDER_HPP + +#include + +#include "xwidgets/xmaterialize.hpp" +#include "xwidgets/xobject.hpp" +#include "xwidgets/xcolor.hpp" +#include "xwidgets/xholder.hpp" + +#include "xenums.hpp" +#include "../math/xplane_autogen.hpp" +#include "../renderers/webgl/xwebgl_shadow_map_autogen.hpp" + +namespace xthree +{ + + // + // xRenderWidget declaration + // + + template + class xRenderWidget : public xw::xwidget + { + public: + + using base_type = xw::xwidget; + using derived_type = D; + + xeus::xjson get_state() const; + void apply_patch(const xeus::xjson& patch); + + XPROPERTY(int, derived_type, _width, 200); + XPROPERTY(int, derived_type, _height, 200); + XPROPERTY(bool, derived_type, _antialias, false); + + XPROPERTY(bool, derived_type, autoClear, true); + XPROPERTY(bool, derived_type, autoClearColor, true); + XPROPERTY(bool, derived_type, autoClearDepth, true); + XPROPERTY(bool, derived_type, autoClearStencil, true); + XPROPERTY(std::vector, derived_type, clippingPlanes); + XPROPERTY(double, derived_type, gammaFactor, 2.0); + XPROPERTY(bool, derived_type, gammaInput, false); + XPROPERTY(bool, derived_type, gammaOutput, false); + XPROPERTY(bool, derived_type, localClippingEnabled, false); + XPROPERTY(int, derived_type, maxMorphTargets, 8); + XPROPERTY(int, derived_type, maxMorphNormals, 4); + XPROPERTY(bool, derived_type, physicallyCorrectLights, false); + XPROPERTY(webgl_shadow_map, derived_type, shadowMap, webgl_shadow_map()); + XPROPERTY(bool, derived_type, sortObject, true); + XPROPERTY(std::string, derived_type, toneMapping, "LinearToneMapping", xenums::ToneMappings); + XPROPERTY(double, derived_type, toneMappingExposure, 1.0); + XPROPERTY(double, derived_type, toneMappingWhitePoint, 1.0); + + XPROPERTY(xw::html_color, derived_type, clearColor, "#000000"); + XPROPERTY(double, derived_type, clearOpacity, 1.0); + + protected: + + xRenderWidget(); + + using base_type::base_type; + + private: + + void set_defaults(); + }; + + // + // xRenderWidget implementation + // + + template + inline void xRenderWidget::apply_patch(const xeus::xjson& patch) + { + base_type::apply_patch(patch); + + XOBJECT_SET_PROPERTY_FROM_PATCH(_width, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(_height, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(_antialias, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(autoClear, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(autoClearColor, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(autoClearDepth, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(autoClearStencil, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(clippingPlanes, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(gammaFactor, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(gammaInput, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(gammaOutput, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(localClippingEnabled, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(maxMorphTargets, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(maxMorphNormals, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(physicallyCorrectLights, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(shadowMap, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(sortObject, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(toneMapping, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(toneMappingExposure, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(toneMappingWhitePoint, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(clearColor, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(clearOpacity, patch); + } + + template + inline xeus::xjson xRenderWidget::get_state() const + { + xeus::xjson state = base_type::get_state(); + + XOBJECT_SET_PATCH_FROM_PROPERTY(_width, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(_height, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(_antialias, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(autoClear, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(autoClearColor, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(autoClearDepth, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(autoClearStencil, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(clippingPlanes, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(gammaFactor, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(gammaInput, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(gammaOutput, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(localClippingEnabled, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(maxMorphTargets, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(maxMorphNormals, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(physicallyCorrectLights, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(shadowMap, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(sortObject, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(toneMapping, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(toneMappingExposure, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(toneMappingWhitePoint, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(clearColor, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(clearOpacity, state); + return state; + } + + template + inline xRenderWidget::xRenderWidget() + : base_type() + { + set_defaults(); + } + + template + inline void xRenderWidget::set_defaults() + { + this->_model_module() = "jupyter-threejs"; + this->_model_module_version() = "1.0.0-beta.3"; + this->_view_module() = "jupyter-threejs"; + this->_view_module_version() = "1.0.0-beta.3"; + + } + + // + // xPreview declaration + // + + template + class xPreview : public xRenderWidget + { + public: + + using base_type = xRenderWidget; + using derived_type = D; + + using child_type = xw::xholder; + + xeus::xjson get_state() const; + void apply_patch(const xeus::xjson& patch); + + XPROPERTY(bool, derived_type, _flat, false); + XPROPERTY(bool, derived_type, _wire, false); + XPROPERTY(child_type, derived_type, child); + + xPreview(const child_type&); + + private: + + void set_defaults(); + }; + + using preview = xw::xmaterialize; + using preview_generator = xw::xgenerator; + + // + // xPreview implementation + // + + template + inline void xPreview::apply_patch(const xeus::xjson& patch) + { + base_type::apply_patch(patch); + + XOBJECT_SET_PROPERTY_FROM_PATCH(_flat, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(_wire, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(child, patch); + } + + template + inline xeus::xjson xPreview::get_state() const + { + xeus::xjson state = base_type::get_state(); + XOBJECT_SET_PATCH_FROM_PROPERTY(_flat, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(_wire, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(child, state); + return state; + } + + template + inline xPreview::xPreview(const child_type& child_) + : base_type() + { + this->child() = child_; + set_defaults(); + } + + template + inline void xPreview::set_defaults() + { + this->_model_name() = "PreviewModel"; + this->_view_name() = "PreviewView"; + } +} +#endif \ No newline at end of file diff --git a/xthreejs/xthreejs/base/xthree.hpp b/xthreejs/xthreejs/base/xthree.hpp new file mode 100644 index 00000000..344db329 --- /dev/null +++ b/xthreejs/xthreejs/base/xthree.hpp @@ -0,0 +1,74 @@ +#ifndef XTHREE_THREE_HPP +#define XTHREE_THREE_HPP + +#include + +#include "xwidgets/xmaterialize.hpp" +#include "xwidgets/xobject.hpp" + +namespace xthree +{ + + // + // xthree_widget declaration + // + + template + class xthree_widget : public xw::xobject + { + public: + + using base_type = xw::xobject; + using derived_type = D; + + xeus::xjson get_state() const; + void apply_patch(const xeus::xjson& patch); + + protected: + + xthree_widget(); + + using base_type::base_type; + + private: + + bool _previewable = true; + void set_defaults(); + }; + + using three_widget = xw::xmaterialize; + using three_widget_generator = xw::xgenerator; + + // + // xthree_widget implementation + // + + template + inline void xthree_widget::apply_patch(const xeus::xjson& patch) + { + base_type::apply_patch(patch); + } + + template + inline xeus::xjson xthree_widget::get_state() const + { + return base_type::get_state(); + } + + template + inline xthree_widget::xthree_widget() + : base_type() + { + set_defaults(); + } + + template + inline void xthree_widget::set_defaults() + { + this->_model_module() = "jupyter-threejs"; + this->_model_module_version() = "1.0.0-beta.3"; + this->_view_module() = ""; + this->_view_module_version() = ""; + } +} +#endif \ No newline at end of file diff --git a/xthreejs/xthreejs/base/xthree_types.hpp b/xthreejs/xthreejs/base/xthree_types.hpp new file mode 100644 index 00000000..fac29776 --- /dev/null +++ b/xthreejs/xthreejs/base/xthree_types.hpp @@ -0,0 +1,15 @@ +#ifndef XTHREE_THREE_TYPES_HPP +#define XTHREE_THREE_TYPES_HPP + +#include + +namespace xthree{ + using vector2 = std::array; + using vector3 = std::array; + using vector4 = std::array; + + using matrix3 = std::array; + using matrix4 = std::array; +} + +#endif diff --git a/xthreejs/xthreejs/core/xrenderer.hpp b/xthreejs/xthreejs/core/xrenderer.hpp new file mode 100644 index 00000000..d8497c48 --- /dev/null +++ b/xthreejs/xthreejs/core/xrenderer.hpp @@ -0,0 +1,102 @@ +#ifndef XTHREE_RENDERER_HPP +#define XTHREE_RENDERER_HPP + +#include "xtl/xoptional.hpp" +#include "xwidgets/xeither.hpp" +#include "xwidgets/xwidget.hpp" + +#include "../base/xenums.hpp" +#include "../base/xthree_types.hpp" +#include "../base/xthree.hpp" +#include "../base/xrender.hpp" +#include "../scenes/xscene_autogen.hpp" +#include "../cameras/xcamera_autogen.hpp" +#include "../controls/xcontrols_autogen.hpp" + +namespace xthree +{ + // + // renderer declaration + // + + template + class xrenderer : public xRenderWidget + { + public: + + using base_type = xRenderWidget; + using derived_type = D; + + xeus::xjson get_state() const; + void apply_patch(const xeus::xjson& patch); + + XPROPERTY(int, derived_type, width, 200); + XPROPERTY(int, derived_type, height, 200); + XPROPERTY(xw::xholder, derived_type, scene); + XPROPERTY(xw::xholder, derived_type, camera); + XPROPERTY(std::vector>, derived_type, controls); + //XPROPERTY(effect, derived_type, effect = Instance(Effect, allow_none=True).tag(sync=True, **widget_serialization) + XPROPERTY(xw::html_color, derived_type, background, "black"); + XPROPERTY(double, derived_type, background_opacity, 1.); + + protected: + + xrenderer(); + + private: + + void set_defaults(); + }; + + using renderer = xw::xmaterialize; + + using renderer_generator = xw::xgenerator; + + // + // renderer implementation + // + + template + inline void xrenderer::apply_patch(const xeus::xjson& patch) + { + base_type::apply_patch(patch); + + XOBJECT_SET_PROPERTY_FROM_PATCH(width, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(height, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(scene, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(camera, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(controls, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(background, patch); + XOBJECT_SET_PROPERTY_FROM_PATCH(background_opacity, patch); + } + + template + inline xeus::xjson xrenderer::get_state() const + { + xeus::xjson state = base_type::get_state(); + + XOBJECT_SET_PATCH_FROM_PROPERTY(width, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(height, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(scene, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(camera, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(controls, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(background, state); + XOBJECT_SET_PATCH_FROM_PROPERTY(background_opacity, state); + return state; + } + + template + inline xrenderer::xrenderer() + : base_type() + { + set_defaults(); + } + + template + inline void xrenderer::set_defaults() + { + this->_model_name() = "RendererModel"; + this->_view_name() = "RendererView"; + } +} +#endif \ No newline at end of file From 27b7eacb1dca7418a88a1e74fa4b3318d77ab44f Mon Sep 17 00:00:00 2001 From: gouarin Date: Sat, 16 Jun 2018 08:15:45 +0200 Subject: [PATCH 5/5] delete files --- xthreejs/xthreejs/base/xenums.hpp | 210 ----------------------- xthreejs/xthreejs/base/xrender.hpp | 219 ------------------------ xthreejs/xthreejs/base/xthree.hpp | 74 -------- xthreejs/xthreejs/base/xthree_types.hpp | 15 -- xthreejs/xthreejs/core/xrenderer.hpp | 102 ----------- 5 files changed, 620 deletions(-) delete mode 100644 xthreejs/xthreejs/base/xenums.hpp delete mode 100644 xthreejs/xthreejs/base/xrender.hpp delete mode 100644 xthreejs/xthreejs/base/xthree.hpp delete mode 100644 xthreejs/xthreejs/base/xthree_types.hpp delete mode 100644 xthreejs/xthreejs/core/xrenderer.hpp diff --git a/xthreejs/xthreejs/base/xenums.hpp b/xthreejs/xthreejs/base/xenums.hpp deleted file mode 100644 index e42d4d7c..00000000 --- a/xthreejs/xthreejs/base/xenums.hpp +++ /dev/null @@ -1,210 +0,0 @@ -#pragma once - -// -// This file auto-generated with generate-enums.js -// Date: Thu Jan 25 2018 04:46:33 GMT+0100 (CET) -// - -#include "xwidgets/xeither.hpp" - -namespace xthree{ - namespace xenums{ - - auto Equations = XEITHER( - "AddEquation", - "SubtractEquation", - "ReverseSubtractEquation", - "MinEquation", - "MaxEquation", - ); - - auto BlendFactors = XEITHER( - "ZeroFactor", - "OneFactor", - "SrcColorFactor", - "OneMinusSrcColorFactor", - "SrcAlphaFactor", - "OneMinusSrcAlphaFactor", - "DstAlphaFactor", - "OneMinusDstAlphaFactor", - "DstColorFactor", - "OneMinusDstColorFactor", - "SrcAlphaSaturateFactor", - ); - - auto Side = XEITHER( - "FrontSide", - "BackSide", - "DoubleSide", - ); - - auto Shading = XEITHER( - "FlatShading", - "SmoothShading", - ); - - auto Colors = XEITHER( - "NoColors", - "FaceColors", - "VertexColors", - ); - - auto BlendingMode = XEITHER( - "NoBlending", - "NormalBlending", - "AdditiveBlending", - "SubtractiveBlending", - "MultiplyBlending", - "CustomBlending", - ); - - auto DepthMode = XEITHER( - "NeverDepth", - "AlwaysDepth", - "LessDepth", - "LessEqualDepth", - "EqualDepth", - "GreaterEqualDepth", - "GreaterDepth", - "NotEqualDepth", - ); - - auto Operations = XEITHER( - "MultiplyOperation", - "MixOperation", - "AddOperation", - ); - - auto MappingModes = XEITHER( - "UVMapping", - "CubeReflectionMapping", - "CubeRefractionMapping", - "EquirectangularReflectionMapping", - "EquirectangularRefractionMapping", - "SphericalReflectionMapping", - "CubeUVReflectionMapping", - "CubeUVRefractionMapping", - ); - - auto WrappingModes = XEITHER( - "RepeatWrapping", - "ClampToEdgeWrapping", - "MirroredRepeatWrapping", - ); - - auto Filters = XEITHER( - "NearestFilter", - "NearestMipMapNearestFilter", - "NearestMipMapLinearFilter", - "LinearFilter", - "LinearMipMapNearestFilter", - "LinearMipMapLinearFilter", - ); - - auto DataTypes = XEITHER( - "UnsignedByteType", - "ByteType", - "ShortType", - "UnsignedShortType", - "IntType", - "UnsignedIntType", - "FloatType", - "HalfFloatType", - ); - - auto PixelTypes = XEITHER( - "UnsignedShort4444Type", - "UnsignedShort5551Type", - "UnsignedShort565Type", - "UnsignedInt248Type", - ); - - auto PixelFormats = XEITHER( - "AlphaFormat", - "RGBFormat", - "RGBAFormat", - "LuminanceFormat", - "LuminanceAlphaFormat", - "DepthFormat", - "DepthStencilFormat", - ); - - auto DepthFormats = XEITHER( - "DepthFormat", - "DepthStencilFormat", - ); - - auto CompressedTextureFormats = XEITHER( - "RGB_S3TC_DXT1_Format", - "RGBA_S3TC_DXT1_Format", - "RGBA_S3TC_DXT3_Format", - "RGBA_S3TC_DXT5_Format", - "RGB_PVRTC_4BPPV1_Format", - "RGB_PVRTC_2BPPV1_Format", - "RGBA_PVRTC_4BPPV1_Format", - "RGBA_PVRTC_2BPPV1_Format", - "RGB_ETC1_Format", - ); - - auto TextureEncodings = XEITHER( - "LinearEncoding", - "sRGBEncoding", - "RGBEEncoding", - "LogLuvEncoding", - "RGBM7Encoding", - "RGBM16Encoding", - "RGBDEncoding", - "GammaEncoding", - ); - - auto CullFaceModes = XEITHER( - "CullFaceNone", - "CullFaceBack", - "CullFaceFront", - "CullFaceFrontBack", - ); - - auto FrontFaceDirection = XEITHER( - "FrontFaceDirectionCW", - "FrontFaceDirectionCCW", - ); - - auto ShadowTypes = XEITHER( - "BasicShadowMap", - "PCFShadowMap", - "PCFSoftShadowMap", - ); - - auto ToneMappings = XEITHER( - "NoToneMapping", - "LinearToneMapping", - "ReinhardToneMapping", - "Uncharted2ToneMapping", - "CineonToneMapping", - ); - - auto LoopModes = XEITHER( - "LoopOnce", - "LoopRepeat", - "LoopPingPong", - ); - - auto InterpolationModes = XEITHER( - "InterpolateDiscrete", - "InterpolateLinear", - "InterpolateSmooth", - ); - - auto EndingModes = XEITHER( - "ZeroCurvatureEnding", - "ZeroSlopeEnding", - "WrapAroundEnding", - ); - - auto DrawModes = XEITHER( - "TrianglesDrawMode", - "TriangleStripDrawMode", - "TriangleFanDrawMode", - ); - } -} \ No newline at end of file diff --git a/xthreejs/xthreejs/base/xrender.hpp b/xthreejs/xthreejs/base/xrender.hpp deleted file mode 100644 index c0a29839..00000000 --- a/xthreejs/xthreejs/base/xrender.hpp +++ /dev/null @@ -1,219 +0,0 @@ -#ifndef XTHREE_RENDER_HPP -#define XTHREE_RENDER_HPP - -#include - -#include "xwidgets/xmaterialize.hpp" -#include "xwidgets/xobject.hpp" -#include "xwidgets/xcolor.hpp" -#include "xwidgets/xholder.hpp" - -#include "xenums.hpp" -#include "../math/xplane_autogen.hpp" -#include "../renderers/webgl/xwebgl_shadow_map_autogen.hpp" - -namespace xthree -{ - - // - // xRenderWidget declaration - // - - template - class xRenderWidget : public xw::xwidget - { - public: - - using base_type = xw::xwidget; - using derived_type = D; - - xeus::xjson get_state() const; - void apply_patch(const xeus::xjson& patch); - - XPROPERTY(int, derived_type, _width, 200); - XPROPERTY(int, derived_type, _height, 200); - XPROPERTY(bool, derived_type, _antialias, false); - - XPROPERTY(bool, derived_type, autoClear, true); - XPROPERTY(bool, derived_type, autoClearColor, true); - XPROPERTY(bool, derived_type, autoClearDepth, true); - XPROPERTY(bool, derived_type, autoClearStencil, true); - XPROPERTY(std::vector, derived_type, clippingPlanes); - XPROPERTY(double, derived_type, gammaFactor, 2.0); - XPROPERTY(bool, derived_type, gammaInput, false); - XPROPERTY(bool, derived_type, gammaOutput, false); - XPROPERTY(bool, derived_type, localClippingEnabled, false); - XPROPERTY(int, derived_type, maxMorphTargets, 8); - XPROPERTY(int, derived_type, maxMorphNormals, 4); - XPROPERTY(bool, derived_type, physicallyCorrectLights, false); - XPROPERTY(webgl_shadow_map, derived_type, shadowMap, webgl_shadow_map()); - XPROPERTY(bool, derived_type, sortObject, true); - XPROPERTY(std::string, derived_type, toneMapping, "LinearToneMapping", xenums::ToneMappings); - XPROPERTY(double, derived_type, toneMappingExposure, 1.0); - XPROPERTY(double, derived_type, toneMappingWhitePoint, 1.0); - - XPROPERTY(xw::html_color, derived_type, clearColor, "#000000"); - XPROPERTY(double, derived_type, clearOpacity, 1.0); - - protected: - - xRenderWidget(); - - using base_type::base_type; - - private: - - void set_defaults(); - }; - - // - // xRenderWidget implementation - // - - template - inline void xRenderWidget::apply_patch(const xeus::xjson& patch) - { - base_type::apply_patch(patch); - - XOBJECT_SET_PROPERTY_FROM_PATCH(_width, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(_height, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(_antialias, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(autoClear, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(autoClearColor, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(autoClearDepth, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(autoClearStencil, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(clippingPlanes, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(gammaFactor, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(gammaInput, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(gammaOutput, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(localClippingEnabled, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(maxMorphTargets, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(maxMorphNormals, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(physicallyCorrectLights, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(shadowMap, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(sortObject, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(toneMapping, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(toneMappingExposure, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(toneMappingWhitePoint, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(clearColor, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(clearOpacity, patch); - } - - template - inline xeus::xjson xRenderWidget::get_state() const - { - xeus::xjson state = base_type::get_state(); - - XOBJECT_SET_PATCH_FROM_PROPERTY(_width, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(_height, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(_antialias, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(autoClear, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(autoClearColor, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(autoClearDepth, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(autoClearStencil, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(clippingPlanes, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(gammaFactor, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(gammaInput, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(gammaOutput, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(localClippingEnabled, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(maxMorphTargets, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(maxMorphNormals, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(physicallyCorrectLights, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(shadowMap, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(sortObject, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(toneMapping, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(toneMappingExposure, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(toneMappingWhitePoint, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(clearColor, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(clearOpacity, state); - return state; - } - - template - inline xRenderWidget::xRenderWidget() - : base_type() - { - set_defaults(); - } - - template - inline void xRenderWidget::set_defaults() - { - this->_model_module() = "jupyter-threejs"; - this->_model_module_version() = "1.0.0-beta.3"; - this->_view_module() = "jupyter-threejs"; - this->_view_module_version() = "1.0.0-beta.3"; - - } - - // - // xPreview declaration - // - - template - class xPreview : public xRenderWidget - { - public: - - using base_type = xRenderWidget; - using derived_type = D; - - using child_type = xw::xholder; - - xeus::xjson get_state() const; - void apply_patch(const xeus::xjson& patch); - - XPROPERTY(bool, derived_type, _flat, false); - XPROPERTY(bool, derived_type, _wire, false); - XPROPERTY(child_type, derived_type, child); - - xPreview(const child_type&); - - private: - - void set_defaults(); - }; - - using preview = xw::xmaterialize; - using preview_generator = xw::xgenerator; - - // - // xPreview implementation - // - - template - inline void xPreview::apply_patch(const xeus::xjson& patch) - { - base_type::apply_patch(patch); - - XOBJECT_SET_PROPERTY_FROM_PATCH(_flat, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(_wire, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(child, patch); - } - - template - inline xeus::xjson xPreview::get_state() const - { - xeus::xjson state = base_type::get_state(); - XOBJECT_SET_PATCH_FROM_PROPERTY(_flat, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(_wire, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(child, state); - return state; - } - - template - inline xPreview::xPreview(const child_type& child_) - : base_type() - { - this->child() = child_; - set_defaults(); - } - - template - inline void xPreview::set_defaults() - { - this->_model_name() = "PreviewModel"; - this->_view_name() = "PreviewView"; - } -} -#endif \ No newline at end of file diff --git a/xthreejs/xthreejs/base/xthree.hpp b/xthreejs/xthreejs/base/xthree.hpp deleted file mode 100644 index 344db329..00000000 --- a/xthreejs/xthreejs/base/xthree.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef XTHREE_THREE_HPP -#define XTHREE_THREE_HPP - -#include - -#include "xwidgets/xmaterialize.hpp" -#include "xwidgets/xobject.hpp" - -namespace xthree -{ - - // - // xthree_widget declaration - // - - template - class xthree_widget : public xw::xobject - { - public: - - using base_type = xw::xobject; - using derived_type = D; - - xeus::xjson get_state() const; - void apply_patch(const xeus::xjson& patch); - - protected: - - xthree_widget(); - - using base_type::base_type; - - private: - - bool _previewable = true; - void set_defaults(); - }; - - using three_widget = xw::xmaterialize; - using three_widget_generator = xw::xgenerator; - - // - // xthree_widget implementation - // - - template - inline void xthree_widget::apply_patch(const xeus::xjson& patch) - { - base_type::apply_patch(patch); - } - - template - inline xeus::xjson xthree_widget::get_state() const - { - return base_type::get_state(); - } - - template - inline xthree_widget::xthree_widget() - : base_type() - { - set_defaults(); - } - - template - inline void xthree_widget::set_defaults() - { - this->_model_module() = "jupyter-threejs"; - this->_model_module_version() = "1.0.0-beta.3"; - this->_view_module() = ""; - this->_view_module_version() = ""; - } -} -#endif \ No newline at end of file diff --git a/xthreejs/xthreejs/base/xthree_types.hpp b/xthreejs/xthreejs/base/xthree_types.hpp deleted file mode 100644 index fac29776..00000000 --- a/xthreejs/xthreejs/base/xthree_types.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef XTHREE_THREE_TYPES_HPP -#define XTHREE_THREE_TYPES_HPP - -#include - -namespace xthree{ - using vector2 = std::array; - using vector3 = std::array; - using vector4 = std::array; - - using matrix3 = std::array; - using matrix4 = std::array; -} - -#endif diff --git a/xthreejs/xthreejs/core/xrenderer.hpp b/xthreejs/xthreejs/core/xrenderer.hpp deleted file mode 100644 index d8497c48..00000000 --- a/xthreejs/xthreejs/core/xrenderer.hpp +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef XTHREE_RENDERER_HPP -#define XTHREE_RENDERER_HPP - -#include "xtl/xoptional.hpp" -#include "xwidgets/xeither.hpp" -#include "xwidgets/xwidget.hpp" - -#include "../base/xenums.hpp" -#include "../base/xthree_types.hpp" -#include "../base/xthree.hpp" -#include "../base/xrender.hpp" -#include "../scenes/xscene_autogen.hpp" -#include "../cameras/xcamera_autogen.hpp" -#include "../controls/xcontrols_autogen.hpp" - -namespace xthree -{ - // - // renderer declaration - // - - template - class xrenderer : public xRenderWidget - { - public: - - using base_type = xRenderWidget; - using derived_type = D; - - xeus::xjson get_state() const; - void apply_patch(const xeus::xjson& patch); - - XPROPERTY(int, derived_type, width, 200); - XPROPERTY(int, derived_type, height, 200); - XPROPERTY(xw::xholder, derived_type, scene); - XPROPERTY(xw::xholder, derived_type, camera); - XPROPERTY(std::vector>, derived_type, controls); - //XPROPERTY(effect, derived_type, effect = Instance(Effect, allow_none=True).tag(sync=True, **widget_serialization) - XPROPERTY(xw::html_color, derived_type, background, "black"); - XPROPERTY(double, derived_type, background_opacity, 1.); - - protected: - - xrenderer(); - - private: - - void set_defaults(); - }; - - using renderer = xw::xmaterialize; - - using renderer_generator = xw::xgenerator; - - // - // renderer implementation - // - - template - inline void xrenderer::apply_patch(const xeus::xjson& patch) - { - base_type::apply_patch(patch); - - XOBJECT_SET_PROPERTY_FROM_PATCH(width, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(height, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(scene, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(camera, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(controls, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(background, patch); - XOBJECT_SET_PROPERTY_FROM_PATCH(background_opacity, patch); - } - - template - inline xeus::xjson xrenderer::get_state() const - { - xeus::xjson state = base_type::get_state(); - - XOBJECT_SET_PATCH_FROM_PROPERTY(width, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(height, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(scene, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(camera, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(controls, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(background, state); - XOBJECT_SET_PATCH_FROM_PROPERTY(background_opacity, state); - return state; - } - - template - inline xrenderer::xrenderer() - : base_type() - { - set_defaults(); - } - - template - inline void xrenderer::set_defaults() - { - this->_model_name() = "RendererModel"; - this->_view_name() = "RendererView"; - } -} -#endif \ No newline at end of file