joostn / OpenJsCad

3D solid CAD using only Javascript
315 stars 128 forks source link

Added path related helper functions. #17

Closed tonious closed 11 years ago

tonious commented 11 years ago

This patch adds two path related helper function.

OpenJsCad.Processor.setOpenJsCadPath( path );

This function allows the user to set a path to the OpenJsCad folder.

OpenJsCad.Processor.addLibrary( library );

This function allows users to import additional javascript files. Objects within those files can then be referenced within the OpenJsCad web worker context.

In both cases, paths can be relative or absolute.

The use case of both functions is to be able to add OpenJsCad as a git submodule, and allow use of OpenJsCad without necessarily forking OpenJsCad.

Both functions rely on the addition of an options hash to OpenJsCad.Processor. This hash is then passed through OpenJsCad.parseJsCadScriptASync. This involved changing the call parameters to add said hash.

This patch was inspired by iamwillhelms pull request1 but varies in syntax somewhat to better represent the actual goal of each function.

tonious commented 11 years ago

Example usage:

function onload()
{
  gProcessor = new OpenJsCad.Processor(document.getElementById("viewer"));
  gProcessor.setOpenJsCadPath( "OpenJsCad/" );
  gProcessor.addLibrary( "utils.js" );

  updateSolid();
}
joostn commented 11 years ago

Thanks!