Giter VIP home page Giter VIP logo

chilipeppr / widget-3dviewer Goto Github PK

View Code? Open in Web Editor NEW
16.0 6.0 42.0 642 KB

The amazing 3D viewer that is the centerpiece of ChiliPeppr. It knows how to parse Gcode to show it as a 3D representation. Has a simulator built in for the tool path. Also has numerous pubsub signals defined to enable 3rd party tools to inject 3D objects into the viewer.

HTML 47.77% JavaScript 51.84% CSS 0.39%

widget-3dviewer's Introduction

com-chilipeppr-widget-3dviewer

Visualize your GCode in 3D by simulating your GCode run or seeing where your run is at in 3D while your CNC operation is in action.

alt text

ChiliPeppr Widget / 3D GCode Viewer

All ChiliPeppr widgets/elements are defined using cpdefine() which is a method that mimics require.js. Each defined object must have a unique ID so it does not conflict with other ChiliPeppr widgets.

Item Value
ID com-chilipeppr-widget-3dviewer
Name Widget / 3D GCode Viewer
Description Visualize your GCode in 3D by simulating your GCode run or seeing where your run is at in 3D while your CNC operation is in action.
chilipeppr.load() URL http://raw.githubusercontent.com/chilipeppr/widget-3dviewer/master/auto-generated-widget.html
Edit URL http://ide.c9.io/chilipeppr/widget-3dviewer
Github URL http://github.com/chilipeppr/widget-3dviewer
Test URL https://preview.c9users.io/chilipeppr/widget-3dviewer/widget.html

Example Code for chilipeppr.load() Statement

You can use the code below as a starting point for instantiating this widget inside a workspace or from another widget. The key is that you need to load your widget inlined into a div so the DOM can parse your HTML, CSS, and Javascript. Then you use cprequire() to find your widget's Javascript and get back the instance of it.

// Inject new div to contain widget or use an existing div with an ID
$("body").append('<' + 'div id="myDivWidget3dviewer"><' + '/div>');

chilipeppr.load(
  "#myDivWidget3dviewer",
  "http://raw.githubusercontent.com/chilipeppr/widget-3dviewer/master/auto-generated-widget.html",
  function() {
    // Callback after widget loaded into #myDivWidget3dviewer
    // Now use require.js to get reference to instantiated widget
    cprequire(
      ["inline:com-chilipeppr-widget-3dviewer"], // the id you gave your widget
      function(myObjWidget3dviewer) {
        // Callback that is passed reference to the newly loaded widget
        console.log("Widget / 3D GCode Viewer just got loaded.", myObjWidget3dviewer);
        myObjWidget3dviewer.init();
      }
    );
  }
);

Publish

This widget/element publishes the following signals. These signals are owned by this widget/element and are published to all objects inside the ChiliPeppr environment that listen to them via the chilipeppr.subscribe(signal, callback) method. To better understand how ChiliPeppr's subscribe() method works see amplify.js's documentation at http://amplifyjs.com/api/pubsub/

Signal Description
/com-chilipeppr-widget-3dviewer/recv3dObjectWhen you send a /request3dObject you will receive a signal back of /recv3dObject. This signal has a payload of the THREE.js user object being shown in the 3D viewer.
/com-chilipeppr-widget-3dviewer/recvUnitsWhen you send a /requestUnits you will receive back this signal with a payload of "mm" or "inch" as a string. Please also see /unitsChanged in case you want to know whenever units are changed from a file open event. You can request what units the Gcode are in from the 3D Viewer. Since the 3D Viewer parses Gcode, it can determine the units. The 3D Viewer is mostly unit agnostic, however to draw the toolhead, grid, and extents labels it does need to know the units to draw the decorations in a somewhat appropriate size.
/com-chilipeppr-widget-3dviewer/unitsChangedThis signal is published when the user loads a new file into the 3D viewer and the units change. If other widgets need to know what units are being used, you should subscribe to this signal to be notified on demand.
/com-chilipeppr-widget-3dviewer/sceneReloadedThis signal is sent when the scene has been (re)load because the user dragged / dropped. The payload indicates the global bounding box of the scene. This signal is similar to listening to /com-chilipeppr-elem-dragdrop/ondropped however, /sceneReloaded is guaranteed to fire every time the 3D viewer loads a new file into the viewer. Credit for this signal goes to Dat Chu who created it for his GrblLaser workspace.

Subscribe

This widget/element subscribes to the following signals. These signals are owned by this widget/element. Other objects inside the ChiliPeppr environment can publish to these signals via the chilipeppr.publish(signal, data) method. To better understand how ChiliPeppr's publish() method works see amplify.js's documentation at http://amplifyjs.com/api/pubsub/

Signal Description
/com-chilipeppr-widget-3dviewer/gotolineThis widget subscribes to this channel so other widgets can move the toolhead and highlight the Gcode line being worked on. This would mostly be when sending Gcode from a Gcode viewer/sender widget, that widget can have the 3D view follow along. Just the line number should be sent as the 3D viewer has it's own cache of the Gcode data loaded.
/com-chilipeppr-widget-3dviewer/resizeYou can ask this widget to resize itself. It will resize the rendering area to the region it is bound to (typically the window width/height).
/com-chilipeppr-widget-3dviewer/sceneaddYou can send Threejs objects to this widget and they will be added to the scene. You must send true THREE.Line() or other ThreeJS objects in that are added as scene.add() objects.
/com-chilipeppr-widget-3dviewer/sceneremoveYou can also remove objects from the 3D scene. This is the opposite of /sceneadd
/com-chilipeppr-widget-3dviewer/sceneclearThis resets the 3D viewer and clears the scene. It keeps the axes, toolhead, and grid. The user object and extents is removed.
/com-chilipeppr-widget-3dviewer/drawextentsThis asks the 3D viewer to draw the extents of what it is showing.
/com-chilipeppr-widget-3dviewer/viewextentsThis asks the 3D viewer to place the entire 3D object set in the view window from a front facing position. It is the equivalent of the button with the "eye" icon in the toolbar.
/com-chilipeppr-widget-3dviewer/setunitsPass in a string of "mm" or "inch" to set the units for the 3D Viewer.
/com-chilipeppr-widget-3dviewer/wakeanimateThe 3d viewer sleeps the rendering after 5 seconds. So if you are going to do any updates to the 3D scene you should wake the animation before your update. It will timeout on its own so you don't have to worry about it. /sceneadd and /sceneremove do their own waking so you don't need to ask for it on those.
/com-chilipeppr-widget-3dviewer/request3dObjectYou can request the parent-most object that is showing in the 3D viewer. This is a THREE.js object that is generated by the 3D viewer. It contains all user elements shown in the scene. It does not contain the XYZ axis, toolhead, or other system elements. When you send this signal you will receive a publish back on /recv3dObject
/com-chilipeppr-widget-3dviewer/requestUnitsSend in this signal and you will be sent back a /recvUnits with a payload of "mm" or "inch" as a string. Please also see /unitsChanged in case you want to know whenever units are changed from a file open event. You can request what units the Gcode are in from the 3D Viewer. Since the 3D Viewer parses Gcode, it can determine the units. The 3D Viewer is mostly unit agnostic, however to draw the toolhead, grid, and extents labels it does need to know the units to draw the decorations in a somewhat appropriate size.

Foreign Publish

This widget/element publishes to the following signals that are owned by other objects. To better understand how ChiliPeppr's subscribe() method works see amplify.js's documentation at http://amplifyjs.com/api/pubsub/

Signal Description
(No signals defined in this widget/element)

Foreign Subscribe

This widget/element publishes to the following signals that are owned by other objects. To better understand how ChiliPeppr's publish() method works see amplify.js's documentation at http://amplifyjs.com/api/pubsub/

Signal Description
/com-chilipeppr-widget-3dviewer/com-chilipeppr-interface-cnccontroller/axesIf we see this signal come in, we move the toolhead to the xyz position in the payload of the signal.
/com-chilipeppr-widget-3dviewer/com-chilipeppr-elem-dragdrop/ondroppedWhen a user drags and drops a file to the main window, we want to get notified so we can load it into the 3D viewer. During development mode in JSFiddle, this widget loads it's own com-chilipeppr-elem-dragdrop so you can test development, but when this widget is loaded in a full ChiliPeppr app it uses the global com-chilipeppr-elem-dragdrop.

Methods / Properties

The table below shows, in order, the methods and properties inside the widget/element.

Method / Property Type Description
idstring"com-chilipeppr-widget-3dviewer"
namestring"Widget / 3D GCode Viewer"
descstring"Visualize your GCode in 3D by simulating your GCode run or seeing where your run is at in 3D while your CNC operation is in action."
urlstring"http://raw.githubusercontent.com/chilipeppr/widget-3dviewer/master/auto-generated-widget.html"
fiddleurlstring"http://ide.c9.io/chilipeppr/widget-3dviewer"
githuburlstring"http://github.com/chilipeppr/widget-3dviewer"
testurlstring"http://widget-3dviewer-chilipeppr.c9users.io/widget.html"
publishobjectPlease see docs above.
subscribeobjectPlease see docs above.
foreignSubscribeobjectPlease see docs above.
foreignPublishobjectPlease see docs above.
sceneobject
objectobject
cameraobject
controlsobject
toolheadobject
tweenobject
tweenHighlightobject
tweenIndexobject
tweenSpeednumber
tweenPausedboolean
tweenIsPlayingboolean
wantAnimateboolean
initOptionsobject
initfunctionfunction (initOptions)
setupScenePubSubfunctionfunction ()
onSignalSceneReloadedFailAttemptsnumber
onSignalSceneReloadedfunctionfunction ()
isInspectSelectboolean
initInspectfunctionfunction ()
setupInspectfunctionfunction (evt)
unsetupInspectfunctionfunction ()
toggleInspectfunctionfunction (evt)
inspectKeyDownfunctionfunction (evt)
inspectKeyUpfunctionfunction (evt)
inspectMouseClickfunctionfunction (evt)
onInspectGotofunctionfunction (evt)
inspectArrowGrpobject
createInspectArrowfunctionfunction ()
inspectCurPosobject
inspectLastObjobject
inspectLastDecorateGroupobject
inspectDlgElobject
inspectMouseMovefunctionfunction (evt)
createGlowfunctionfunction (threeObj)
createGlowCubeCapsfunctionfunction (threeObj)
isJogBtnAttachedboolean
isJogSelectboolean
initJogfunctionfunction ()
setupJogfunctionfunction (evt)
unsetupJogfunctionfunction ()
toggleJogfunctionfunction (evt)
jogKeyDownfunctionfunction (evt)
jogKeyUpfunctionfunction (evt)
arrowHelperobject
jogPlaneobject
isJogRaycasterboolean
jogArrowobject
jogArrowCylobject
jogArrowLineobject
jogArrowShadowobject
unsetupJogRaycasterfunctionfunction ()
setupJogRaycasterfunctionfunction ()
jogMouseClickfunctionfunction (evt)
jogCurPosobject
jogMouseMovefunctionfunction (evt)
showShadowboolean
setupCogMenufunctionfunction ()
onToggleShadowClickfunctionfunction (evt, param)
setupFpsMenufunctionfunction ()
onFpsClickfunctionfunction (evt, param)
gridSizenumber
setupGridSizeMenufunctionfunction ()
onGridSizeClickfunctionfunction (evt, param)
setUnitsfunctionfunction (units)
requestUnitsfunctionfunction ()
onUnitsChangedfunctionfunction ()
request3dObjectfunctionfunction ()
sceneAddfunctionfunction (obj)
sceneRemovefunctionfunction (obj)
sceneClearfunctionfunction ()
btnSetupfunctionfunction ()
forkSetupfunctionfunction ()
onPubSubFileLoadedfunctionfunction (txt)
errorfunctionfunction (msg)
loadFilefunctionfunction (path, callback /* function(contents) */ )
setDetailsfunctionfunction (txt)
speedUpfunctionfunction ()
openGCodeFromPathfunctionfunction (path)
openGCodeFromTextfunctionfunction (gcode)
lookAtCenterfunctionfunction ()
isLookAtToolHeadModeboolean
lookAtToolHeadfunctionfunction ()
toCameraCoordsfunctionfunction (position)
scaleInViewfunctionfunction ()
viewExtentsfunctionfunction ()
stopSampleRunfunctionfunction (evt)
pauseSampleRunfunctionfunction ()
gotoXyzfunctionfunction (data)
gotoLinefunctionfunction (data)
playNextTweenfunctionfunction (isGotoLine)
zheighttestnumber
playSampleRunfunctionfunction (evt)
makeTextfunctionfunction (vals)
decorateobject
decorateExtentsfunctionfunction ()
convertMinsToPrettyDurationfunctionfunction (mins)
makeSpritefunctionfunction (scene, rendererType, vals)
elementobject
getInchesFromMmfunctionfunction (mm)
getUnitValfunctionfunction (val)
drawAxesToolAndExtentsfunctionfunction ()
shadowplaneobject
drawToolheadfunctionfunction ()
gridobject
gridTurnOfffunctionfunction ()
gridTurnOnfunctionfunction ()
drawGridfunctionfunction ()
drawExtentsLabelsfunctionfunction ()
axesobject
drawAxesfunctionfunction ()
colorBackgroundnumber
createScenefunctionfunction (element)
resizefunctionfunction ()
mytimeoutobject
renderFrameCtrnumber
fpsCounterIntervalobject
fpsElobject
fpsCounterStartfunctionfunction ()
fpsCounterOnIntervalfunctionfunction ()
fpsCounterEndfunctionfunction ()
setFrameRatefunctionfunction (rate)
animEnableboolean
animateDisabledfunctionfunction ()
animateEnabledfunctionfunction ()
frameRateDelayMsnumber
animatefunctionfunction ()
wakeAnimatefunctionfunction (evt)
sleepAnimatefunctionfunction ()
cancelSleepfunctionfunction ()
isNoSleepModeboolean
animNoSleepfunctionfunction ()
animAllowSleepfunctionfunction ()
GCodeParserfunctionfunction (handlers, modecmdhandlers)

Parses a string of gcode instructions, and invokes handlers for each type of command.

Special handler: 'default': Called if no other handler matches.
colorG0number
colorG1number
colorG2number
createObjectFromGCodefunctionfunction (gcode, indxMax)
convertLineGeometryToBufferGeometryfunctionfunction (lineGeometry, color)

About ChiliPeppr

ChiliPeppr is a hardware fiddle, meaning it is a website that lets you easily create a workspace to fiddle with your hardware from software. ChiliPeppr provides a Serial Port JSON Server that you run locally on your computer, or remotely on another computer, to connect to the serial port of your hardware like an Arduino or other microcontroller.

You then create a workspace at ChiliPeppr.com that connects to your hardware by starting from scratch or forking somebody else's workspace that is close to what you are after. Then you write widgets in Javascript that interact with your hardware by forking the base template widget or forking another widget that is similar to what you are trying to build.

ChiliPeppr is massively capable such that the workspaces for TinyG and Grbl CNC controllers have become full-fledged CNC machine management software used by tens of thousands.

ChiliPeppr has inspired many people in the hardware/software world to use the browser and Javascript as the foundation for interacting with hardware. The Arduino team in Italy caught wind of ChiliPeppr and now ChiliPeppr's Serial Port JSON Server is the basis for the Arduino's new web IDE. If the Arduino team is excited about building on top of ChiliPeppr, what will you build on top of it?

widget-3dviewer's People

Contributors

chilipeppr avatar mitchbradley avatar raykholo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

widget-3dviewer's Issues

[Bug] Ctrl-click to jog doesn't seem to work (Mac)

Chrome 51.0.2704.84 on Mac OS X 10.11.3.

Have to look more into repro steps more when I'm at the machine again, but I noticed that the jog tool was not working consistently. It didn't work on several tries, and randomly seemed to work maybe once. I think it may be registering control-clicks as right-clicks (as is the case on Macs), so it'd be great if we could also accept Cmd-clicks for Mac users.

Development thread: S parameter as variable opacity

screenshot from 2016-02-13 13-56-48

Hi John

I hope you wouldn't mind me opening a thread, but just easier to keep it going here where I can easily reference code lines, upload etc than the G+ community

So, from our discussion yesterday (#1)

I went ahead and added the subscribe

https://github.com/openhardwarecoza/widget-3dviewer/blob/master/widget.js#L138
and
https://github.com/openhardwarecoza/widget-3dviewer/blob/master/widget.js#L189

and hopefully data published should trigger the function https://github.com/openhardwarecoza/widget-3dviewer/blob/master/widget.js#L3014

However, I don't see the function fire off (i.e. not logging to console) when I connect and disconnect to the TinyG

(As you can tell I am totally noob with the subscribe/publish, so going by example code from other widgets here)

Clear 3D viewer without changing view angle

Is it possible to ask 3D viewer to clear the scene without changing the view angle? I want send this command from Eagle BRD Widget to redraw the board but I want to keep the view angle intact.

Misinterpreted G2/G3 direction for arcs in ZX plane

Arcs from .gcode seem to render with wrong clockwise direction for arcs ZX plane. Preview shows lots of weird circles instead of neat arcs, while tool tracking from G2 board (DUE) goes correctly. If G2 and G3 are swapped for ZX plane (by tweaks in tinyg.cps post) - the preview shows correct picture, BUT the weird circles appear in tool tracking.
In other words: G2/G3 interpretation of 3dviewer (GCodeParser object?) is different from tinyg for arcs in ZX plane.

Fix deprecation notices

Rather than branch/revert/patch/pull request... ill just submit a ticket.

THREE.LinePieces has been deprecated.

var line = new THREE.Line(lineGeo, material, THREE.LinePieces);

becomes

var line = new THREE.LineSegments(lineGeo, material);

You can cherry pick from this commit: dchote/widget-3dviewer-rpi@18e6b4f

Question about Toolhead and info text

Is it possible for a widget to tell 3dviewer widget to hide/show Toolhead and info text?

I tried changing the visible property of some item from this.obj3d.parent.children with no success. Where this.obj3d.parent is the scene object.

simple 2d gcode visualize

hi , sorry to open ticket for my question , actually I made my low weight web interface on ESP8266 which is use the JavaScript readerFile to load the gcode file on client side , I use the GRBL as cnc interpreter and connected to my ESP and its work well, however I intend to add visualize tab page so I could show gcode tool path but I couldn't find single file JS code (no Jquery) , I really appreciated if I have any hint on how to use essential this repo code for simple 2d visualize purpose
favicxzccon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.