Skip to content

WIP: add WebGL debugMode() #3103

Merged
kjhollen merged 13 commits intoprocessing:webgl-gsoc-2018from
AidanNelson:add-helpers
Aug 11, 2018
Merged

WIP: add WebGL debugMode() #3103
kjhollen merged 13 commits intoprocessing:webgl-gsoc-2018from
AidanNelson:add-helpers

Conversation

@AidanNelson
Copy link
Copy Markdown
Member

This PR adds a debugMode() function to the webGL mode. The function works to make visualizing 3D space somewhat easier by adding a grid 'ground' plane and an axes icon indicating the +X, +Y, and +Z directions. Also...

  • adds Interaction submodule to webGL YUI doc organization to contain debugMode and orbitControl
  • adds _grid() and _axes() private functions to be added to preregisteredMethods by debugMode().

If there is a cleaner way to overload this function, please let me know.

Copy link
Copy Markdown
Member

@kjhollen kjhollen left a comment

Choose a reason for hiding this comment

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

See API suggestion and validateParams discussion inline.

Comment thread src/webgl/interaction.js
* }
* }
* </code>
* </div>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

each one of these needs an alt text description.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

added!

Comment thread src/webgl/interaction.js
* @param {Number} [zOff]
*/

p5.prototype.debugMode = function() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I find myself wondering if this should be debug3dMode, but I think this ok to leave as-is

normalMaterial();
let cam = createCamera();
cam.move(0, -this.height / 4, 0);
debugMode();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

just want to say that being able to comment this in or out in setup is a nice touch, and to have the flexibility of toggling with keypress is also great.

Comment thread src/webgl/interaction.js Outdated
* box(15, 30);
* // Press the spacebar to turn debugMode off!
* if (keyIsDown(32)) {
* debugMode(OFF);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

in keeping with smooth/noSmooth — maybe debugMode / noDebugMode? then we can eliminate the OFF parameter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, that is much better!

Comment thread src/webgl/interaction.js
* icon will be sized according to the current canvas size. Note that because the
* grid runs parallel to the default camera view, it is often helpful to use
* debugMode along with orbitControl to allow full view of the grid.
* @method debugMode
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I had a look at the errors for the argument-less version. I think the issue is that _validateParameters doesn't expect the argument array to be null. I recall seeing a discussion about not generating an error when the user supplies an argument to an argumentless function, because the function will work and the error will confuse a new programmer (I think not generating one is the right call). but, this case is different because that's only one mode of operation. hmm. maybe there's a way to work around by supplying a default argument?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This seems to have been fixed by adding 'either' after the @param {Constant} mode tag, per @Spongman's suggestion below.

Comment thread src/webgl/interaction.js
* box(15, 30);
* }
* </code>
* </div>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

these all look great, but when I click on the canvas, everything disappears! any ideas? I don't see anything in the error log. I'm running with npm run grunt yui:dev

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yea, this is because #3063 broke orbitControl (which was still using the old camera paradigm) and I didn't realize until after it was merged 😳.

#3088 will fix orbitControl so that it works with p5.Camera object.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

woops, okay, it looks like I can't fully test this until we get 3088 in—I think it's ready to go, but just had one more quick question there. I'll take a closer look at this and the _orbit tests tomorrow morning!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@AidanNelson I just merged #3088, do you want to go ahead and merge this branch with webgl-gsoc-2018 and push again?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cool, confirming that this is resolved with a merge of the latest webgl-gsoc-2018 branch!

Comment thread src/webgl/interaction.js Outdated
// Lines along X axis
for (var q = 0; q <= numDivs; q++) {
this.strokeWeight(1);
this.stroke(0, 0, 0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm, it could be good to set this color... black is a very common background color for 3D work. or could it just use the stroke color set by the user?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point, that would be nice!

I've set it to use the last-set stroke color and stroke weight. This introduces an odd behavior when called without first setting a stroke, where it will use the stroke color last set by _axesIcon(), but I suspect this is fixed by #3076.

let cam = createCamera();
cam.move(0, -this.height / 4, 0);
debugMode();
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

but also: I can't run this because it generates an error with validateParams in my default build...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

there's a bug in the validateParameters handling that causes a crash when the description of a {Constant}-typed parameter does not match the required format.
the fix in this case is to add the 'either' keyword before the list of valid values for the parameter ("either GRID, AXES, or OFF").

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Spongman Yes, that seems to have fixed it! Is this bug documented anywhere? It would be helpful to have this somewhere in the developer docs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

indeed, going to add that now...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sorry, i should have done this a long time ago... #3122

Comment thread src/webgl/interaction.js Outdated

/**
* @method debugMode
* @param {Constant} mode GRID, AXES, or OFF
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this should be

 * @param {Constant} mode either GRID, AXES, or OFF

@AidanNelson
Copy link
Copy Markdown
Member Author

@kjhollen these most recent changes also simplify the argument-checking. Let me know if you prefer the previous version.

And sorry about the number of commits! Let me know if you'd like me to rebase them...

Comment thread src/webgl/interaction.js Outdated
};

/**
* DebugMode() helps visualize 3D space by adding a grid to indicate where the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use lowercase 'd' here, sorry I didn't catch this one before!

Comment thread src/webgl/interaction.js Outdated
* </code>
* </div>
* @alt
* a 3D box is centered on a grid in a 3D sketch. there is also an icon
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you summarize what the icon is concisely? three lines + color + direction?

@kjhollen kjhollen merged commit 893060d into processing:webgl-gsoc-2018 Aug 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants