Giter Site home page Giter Site logo

jerryi / mathematica-threejs-graphics-engine Goto Github PK

View Code? Open in Web Editor NEW
27.0 5.0 2.0 12.89 MB

A parser for Wolfram Mathematica's Graphics3D functions (written in JS)

JavaScript 80.58% Mathematica 2.66% HTML 11.76% SCSS 3.10% CSS 1.91%
3d 3d-graphics javascript mathematica threejs wolfram-language

mathematica-threejs-graphics-engine's Introduction

Graphics3D engine based on THREE.js

written with love in Javascript

Graphics3D[{
    {Emissive[Red], Sphere[{0,0,2}]}, 
    {White, Sphere[]}
}, Lighting->None, RTX->True]

See disscussion at mathematica.stackexchange.

This is a core component of Wolfram JS Frontend project

Examples

Most Mathematica's functions for 3D plotting expands into a bunch of Graphics3D primitives

ContourPlot3D[x^3 + y^2 - z^2 == 0, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]

However, styling and labeling is not implemented

VectorPlot3D[{x, y, z}, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, VectorColorFunction -> Function[{x, y, z, vx, vy, vz, n}, ColorData["ThermometerColors"][x]]][[1]];
%/. {RGBColor[r_,g_,b_] :> Sequence[RGBColor[r/50,g/50,b/50], Emissive[RGBColor[r,g,b], 5]],};

Graphics3D[{%, Roughness[0], Sphere[{0,0,0}, 0.9]}, Lighting->None, RTX->True]

Custom lighting, mesh materials, shadows propeties are provided

Docs?

See HERE

Contributing

Please feel encouraged to contribute and expand features.

License

Project is released under the GNU General Public License (GPL).

mathematica-threejs-graphics-engine's People

Contributors

asukaminato0721 avatar jerryi avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

mathematica-threejs-graphics-engine's Issues

Live examples of output

How about adding an examples directory and letting GitHub render them to jerryl.github.io? That last step is a single change in your repository settings.

Use Three.js OrbitControls for navigation

Instead of maintaining your own navigation code, why not use the existing OrbitControls or one of the others? The Detector.js file you are currently using is a Three.js component, now named WebGL.js in the examples directory. It would not be difficult to use the existing controls as well and save yourself some effort in the future.

add test / examples

currently, this project is missing the test.

there may be 2 ways to test:

  1. test the single function.
  2. test generates pictures as a whole, I guess one way is to take a screenshot and compare the result vs the expected.

Because copying and pasting the JSON and seeing the rendered result is such a pain. :(

this is a discussion, not an issue :)

this parser is much like https://sourceacademy.org/sicpjs/4.1.1 .

(I am a fan of this topic (functional programming), by the way. I have completed the sicp-py, cs61a)

For clarity, evaluate has been implemented as a case analysis using conditional expressions. The disadvantage of this is that our function handles only a few distinguishable types of statements and expressions, and no new ones can be defined without editing the declaration of evaluate. In most interpreter implementations, dispatching on the type of a component is done in a data-directed style. This allows a user to add new types of components that evaluate can distinguish, without modifying the declaration of evaluate itself.

core[this.name](args, env)

so it's needless to write a huge switch case, and core.NewMethod just works.

sicp is one of my favourite book :)

remove THREE.Geometry

as the title said, Geometry is removed from three.js, so it's better to remove it here.

But since they are different, so remove it is harder than I think. : (

this is a task list for test examples on manual

Graphics3D[{Blue, Cylinder[], Red, Sphere[{0, 0, 2}], Black, Thick, 
  Dashed, Line[{{-2, 0, 2}, {2, 0, 2}, {0, 0, 4}, {-2, 0, 2}}], 
  Yellow, Polygon[{{-3, -3, -2}, {-3, 3, -2}, {3, 
     3, -2}, {3, -3, -2}}], Green, Opacity[.3], 
  Cuboid[{-2, -2, -2}, {2, 2, -1}]}]

image

Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> "Rainbow", 
 Mesh -> None]

works

ParametricPlot3D[{(3 + Cos[v]) Cos[u], (3 + Cos[v]) Sin[u], 
  Sin[v]}, {u, 0, 2 Pi}, {v, 0, 2 Pi}, Mesh -> None]

works

Table[Graphics3D[{Yellow, Opacity[.8], 
   PolyhedronData[p, "GraphicsComplex"]}], {p, {"Dodecahedron", 
   "Icosahedron", "TruncatedIcosahedron"}}]

table doesn't support :)

  • problem
Graphics3D[Polygon[{{0, 0, 0}, {1, 1, 1}, {0, 1, 1}, {1, 0, 0}}]]

image

image


Graphics3D[GraphicsComplex[v,
   Polygon[{{4, 5, 6}, {4, 6, 2}, {4, 2, 1}, {4, 1, 5}, {5, 1, 
     3}, {5, 3, 6}, 
       {3, 1, 2}, {6, 3, 2}}]]]

works


Graphics3D[{Yellow, Sphere[], {Blue, Sphere[{1, 0, 0}]}, 
  Sphere[{2, 0, 0}]}]

works


ContourPlot3D[ 
 Cos[x] Sin[y] + Cos[y] Sin[z] + Cos[z] Sin[x] == 0, {x, -2 \[Pi], 
  2 \[Pi]}, {y, -2 \[Pi], 2 \[Pi]}, {z, -2 \[Pi], 2 \[Pi]}, 
 ContourStyle -> 
  Directive[FaceForm[Orange, Red], Specularity[White, 30]], 
 Mesh -> None]
  • website crashed (maybe adding an option to upload txt file is a better idea.

PlotPoints -> 3

image


SphericalPlot3D[
 1 + Sin[5 \[Phi]]/5, {\[Theta], 0, Pi}, {\[Phi], 0, 2 Pi}, 
 PlotStyle -> Directive[Yellow, Opacity[0.7], Specularity[White, 20]],
  Mesh -> None, PlotPoints -> 30]

works


ChemicalData["Caffeine", "MoleculePlot"] // Export["~/tmp.txt", #//N, "ExpressionJSON"]&
  • not work.

add out box

I am testing plot3d.

image

but the AspectRatio is strange.

image

but I think it's acceptable. :). Since the graph is correct.

but missing the box outside makes it hard to "feel the space".

Then I found this may help. https://threejs.org/docs/#api/en/helpers/BoxHelper

But where to add it is a problem, since there may have many objects in a scene.

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.