Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/strands/strands_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,73 @@
}
}
}
//////////////////////////////////////////////
// Global p5 properties
//////////////////////////////////////////////
const globalProperties = [
{ name: 'width', type: DataType.float1 },
{ name: 'height', type: DataType.float1 },
{ name: 'mouseX', type: DataType.float1 },
{ name: 'mouseY', type: DataType.float1 },
{ name: 'pmouseX', type: DataType.float1 },
{ name: 'pmouseY', type: DataType.float1 },
{ name: 'winMouseX', type: DataType.float1 },
{ name: 'winMouseY', type: DataType.float1 },
{ name: 'frameCount', type: DataType.int1 },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is an integer value, it's fairly unintuitive for users of strands for it to actually be a glsl int instead of a float, since in JS all numbers are floats, and you'd expect frameCount / 2 to have decimals sometimes. So maybe let's turn all the ints into floats here?

{ name: 'focused', type: DataType.bool1 },
{ name: 'displayWidth', type: DataType.float1 },
{ name: 'displayHeight', type: DataType.float1 },
{ name: 'windowWidth', type: DataType.float1 },
{ name: 'windowHeight', type: DataType.float1 },
{ name: 'mouseButton', type: DataType.int1 },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In p5 2.x this isn't an int, it's an object: https://beta.p5js.org/reference/p5/mousebutton/ We might need to special case this one by either making each property a uniform, or by just omitting it for now.

{ name: 'mouseIsPressed', type: DataType.bool1 }
];

const originalDescriptors = {};
for (const { name } of globalProperties) {
originalDescriptors[name] = Object.getOwnPropertyDescriptor(fn, name) || {
get: function() { return p5.prototype[name]; },
configurable: true
};
}

for (const { name, type } of globalProperties) {
strandsContext.fnOverrides[name] = originalDescriptors[name];

(function(propName, propType, origDescriptor) {
Object.defineProperty(fn, propName, {
get: function() {
if (strandsContext.active) {
const uniformName = `_p5_${propName}`;
const existingUniform = strandsContext.uniforms.find(u => u.name === uniformName);

if (!existingUniform) {
const { id, dimension } = build.variableNode(strandsContext, propType, uniformName);
strandsContext.uniforms.push({
name: uniformName,
typeInfo: propType,
defaultValue: origDescriptor.get ?
() => origDescriptor.get.call(fn) :
() => origDescriptor.value
});
return createStrandsNode(id, dimension, strandsContext);
} else {
const { id, dimension } = build.variableNode(strandsContext, propType, uniformName);
return createStrandsNode(id, dimension, strandsContext);
}
} else {
if (origDescriptor.get) {
return origDescriptor.get.call(this);
} else {
return origDescriptor.value;
}
}
},
configurable: true,
enumerable: true
});
})(name, type, originalDescriptors[name]);
}
}
//////////////////////////////////////////////
// Per-Hook functions
Expand All @@ -183,7 +250,7 @@
for (let i = 0; i < structTypeInfo.properties.length; i++) {
const propertyType = structTypeInfo.properties[i];
Object.defineProperty(structNode, propertyType.name, {
get() {

Check failure on line 253 in src/strands/strands_api.js

View workflow job for this annotation

GitHub Actions / test

test/unit/core/vertex.js

TypeError: Cannot redefine property: width ❯ src/strands/strands_api.js:253:14 ❯ initGlobalStrandsAPI src/strands/strands_api.js:284:7 ❯ strands src/strands/p5.strands.js:59:3 ❯ default src/webgl/index.js:36:3 ❯ src/app.js:51:1

Check failure on line 253 in src/strands/strands_api.js

View workflow job for this annotation

GitHub Actions / test

test/unit/core/version.js

TypeError: Cannot redefine property: width ❯ src/strands/strands_api.js:253:14 ❯ initGlobalStrandsAPI src/strands/strands_api.js:284:7 ❯ strands src/strands/p5.strands.js:59:3 ❯ default src/webgl/index.js:36:3 ❯ src/app.js:51:1

Check failure on line 253 in src/strands/strands_api.js

View workflow job for this annotation

GitHub Actions / test

test/unit/core/structure.js

TypeError: Cannot redefine property: width ❯ src/strands/strands_api.js:253:14 ❯ initGlobalStrandsAPI src/strands/strands_api.js:284:7 ❯ strands src/strands/p5.strands.js:59:3 ❯ default src/webgl/index.js:36:3 ❯ src/app.js:51:1

Check failure on line 253 in src/strands/strands_api.js

View workflow job for this annotation

GitHub Actions / test

test/unit/core/rendering.js

TypeError: Cannot redefine property: width ❯ src/strands/strands_api.js:253:14 ❯ initGlobalStrandsAPI src/strands/strands_api.js:284:7 ❯ strands src/strands/p5.strands.js:59:3 ❯ default src/webgl/index.js:36:3 ❯ src/app.js:51:1

Check failure on line 253 in src/strands/strands_api.js

View workflow job for this annotation

GitHub Actions / test

test/unit/core/p5.Graphics.js

TypeError: Cannot redefine property: width ❯ src/strands/strands_api.js:253:14 ❯ initGlobalStrandsAPI src/strands/strands_api.js:284:7 ❯ strands src/strands/p5.strands.js:59:3 ❯ default src/webgl/index.js:36:3 ❯ src/app.js:51:1

Check failure on line 253 in src/strands/strands_api.js

View workflow job for this annotation

GitHub Actions / test

test/unit/core/main.js

TypeError: Cannot redefine property: width ❯ src/strands/strands_api.js:253:14 ❯ initGlobalStrandsAPI src/strands/strands_api.js:284:7 ❯ strands src/strands/p5.strands.js:59:3 ❯ default src/webgl/index.js:36:3 ❯ src/app.js:51:1

Check failure on line 253 in src/strands/strands_api.js

View workflow job for this annotation

GitHub Actions / test

test/unit/core/environment.js

TypeError: Cannot redefine property: width ❯ src/strands/strands_api.js:253:14 ❯ initGlobalStrandsAPI src/strands/strands_api.js:284:7 ❯ strands src/strands/p5.strands.js:59:3 ❯ default src/webgl/index.js:36:3 ❯ src/app.js:51:1

Check failure on line 253 in src/strands/strands_api.js

View workflow job for this annotation

GitHub Actions / test

test/unit/color/setting.js

TypeError: Cannot redefine property: width ❯ src/strands/strands_api.js:253:14 ❯ initGlobalStrandsAPI src/strands/strands_api.js:284:7 ❯ strands src/strands/p5.strands.js:59:3 ❯ default src/webgl/index.js:36:3 ❯ src/app.js:51:1

Check failure on line 253 in src/strands/strands_api.js

View workflow job for this annotation

GitHub Actions / test

test/unit/color/color_conversion.js

TypeError: Cannot redefine property: width ❯ src/strands/strands_api.js:253:14 ❯ initGlobalStrandsAPI src/strands/strands_api.js:284:7 ❯ strands src/strands/p5.strands.js:59:3 ❯ default src/webgl/index.js:36:3 ❯ src/app.js:51:1

Check failure on line 253 in src/strands/strands_api.js

View workflow job for this annotation

GitHub Actions / test

test/unit/accessibility/outputs.js

TypeError: Cannot redefine property: width ❯ src/strands/strands_api.js:253:14 ❯ initGlobalStrandsAPI src/strands/strands_api.js:284:7 ❯ strands src/strands/p5.strands.js:59:3 ❯ default src/webgl/index.js:36:3 ❯ src/app.js:51:1
const propNode = getNodeDataFromID(dag, dag.dependsOn[structNode.id][i])
const onRebind = (newFieldID) => {
const oldDeps = dag.dependsOn[structNode.id];
Expand Down
Loading