Skip to content

Commit

Permalink
feat(get-module-data): adds getModuleData (#906)
Browse files Browse the repository at this point in the history
Allows renderers to store certain data outside of presets/Vuex for performance and bugfixes
  • Loading branch information
2xAA committed May 4, 2024
1 parent f39311d commit a093a39
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
13 changes: 10 additions & 3 deletions src/application/renderers/three.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ store.dispatch("outputs/addAuxillaryOutput", {

const renderer = new THREE.WebGLRenderer({
alpha: true,
antialias: true,
canvas: threeCanvas
antialias: false,
canvas: threeCanvas,
powerPreference: "high-performance",
premultipliedAlpha: false
});
renderer.setPixelRatio(1);

Expand Down Expand Up @@ -178,6 +180,10 @@ function resize({ width, height }) {
renderer.setSize(width, height, false);
}

function getModuleData(name) {
return threeModuleData[name];
}

export default {
render,
updateModule,
Expand All @@ -186,6 +192,7 @@ export default {
setupModule,
removeModule,
createPresetData,
loadPresetData
loadPresetData,
getModuleData
};
export { threeModuleData };
4 changes: 3 additions & 1 deletion src/application/worker/index.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ async function start() {
tick,
resize,
createPresetData,
loadPresetData
loadPresetData,
getModuleData
} = renderers(rendererName).default;

store.commit("renderers/ADD_RENDERER", {
Expand All @@ -142,6 +143,7 @@ async function start() {
resizeModule,
createPresetData,
loadPresetData,
getModuleData,
tick
});
}
Expand Down
42 changes: 21 additions & 21 deletions src/application/worker/store/modules/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ const actions = {
},

async updateProp(
{ state, commit },
{ moduleId, prop, data, group, path = "", groupName, writeToSwap }
{ state, commit, rootState },
{ moduleId, prop, data, path = "", writeToSwap }
) {
if (!state.active[moduleId]) {
console.error(`The module with the moduleId ${moduleId} doesn't exist.`);
Expand All @@ -480,10 +480,6 @@ const actions = {
);
const { type } = propData;

// if (group || groupName) {
// propData = state.active[name].props[groupName].props[prop];
// }

if (data === currentValue) {
return;
}
Expand Down Expand Up @@ -520,28 +516,32 @@ const actions = {
type: propData.type,
path
},
group,
groupName,

writeToSwap
});

if (group || groupName) {
if ("set" in state.registered[moduleName].props[groupName].props[prop]) {
state.registered[moduleName].props[groupName].props[prop].set.bind(
state.registered[moduleName]
)({
data: { ...state.active[moduleId].data },
props: state.active[moduleId].props
});
}
} else if ("set" in state.registered[moduleName].props[prop]) {
state.registered[moduleName].props[prop].set.bind(
state.registered[moduleName]
)({
const registeredModule = state.registered[moduleName];

if ("set" in registeredModule.props[prop]) {
const { renderers } = rootState;

const { getModuleData = () => ({}) } = renderers[
registeredModule.meta.type
];

const newData = registeredModule.props[prop].set.bind(registeredModule)({
...getModuleData(registeredModule.meta.name),
data: { ...state.active[moduleId].data },
props: state.active[moduleId].props
});

if (newData) {
commit("UPDATE_ACTIVE_MODULE", {
id: moduleId,
key: "data",
value: newData
});
}
}
},

Expand Down

0 comments on commit a093a39

Please sign in to comment.