njpipeorgan / wolfram-language-notebook

Notebook support for Wolfram Language in VS Code
Apache License 2.0
159 stars 11 forks source link

Add dynamic plot3d #40

Closed asukaminato0721 closed 1 year ago

asukaminato0721 commented 1 year ago

Is your feature request related to a problem? A clear and concise description of what the problem is.

Now 3d plot is static. Make them interactive.

Describe the solution you'd like A clear and concise description of what you want to happen.

https://github.com/wuyudi/Mathematica-ThreeJS-graphics-engine/tree/enable-plot3d

Plot3D[Sin[x^2+y^2], {x,0,4},{y,0,4}] 
%//ExportString[#//N, "ExpressionJSON"]& // Export["~/test.txt", #]&

now it works well

image

Additional context Add any other context or screenshots about the feature request here.

Some pitfalls:

Because that repo is legacy, three js's version is old, hard to add new functions.

For example:

https://stackoverflow.com/a/51591365

https://discourse.threejs.org/t/three-geometry-will-be-removed-from-core-with-r125/22401

asukaminato0721 commented 1 year ago

Update:

  1. The author keeps developing it, it's quite ok now.
  2. directly use wolfram player with this code snippet.
BeginPackage["CommandLineUtilities`Display`"];
Begin["`Private`"];
$TemporaryOutput = FileNameJoin@{$TemporaryDirectory, "WolframKernelOutput"};
If[!DirectoryQ@#, CreateDirectory@#] &@$TemporaryOutput;
WolframPlayer[expr_, box_] := StartProcess[{
            "wolframplayer",
            Export[
                FileNameJoin@{$TemporaryOutput, CreateUUID["CDFOutput-"]<>".cdf"}, 
                Notebook[{Cell@BoxData@box}, WindowSize -> All],
                "CDF"
            ]
}]
End[];
EndPackage[];
(*$DisplayFunction = WolframPlayer[#, ToBoxes@#]&;*)
$Post = With[{box = ToBoxes@#},
    If[FreeQ[DynamicBox|DynamicModuleBox|GraphicsBox|Graphics3DBox]@box,
            #,
            WolframPlayer[#, box]
    ]
]&;

image