简体   繁体   English

如何在Ruby中的Webgl中保存和发布JS代码结果

[英]how to save and post JS code result in Webgl within ruby on rails

Currently I have two input text area for users to write the Javascript and JS Library on the browser and run it with a run button. 目前,我有两个输入文本区域,供用户在浏览器中编写Javascript和JS库并使用运行按钮运行它。 Here is the view html: 这是html视图:

<textarea id="scriptJS" rows="20" style="width:100%;">
</textarea> 
<textarea id="libsJS" rows="20" style="width:100%;">
</textarea>

<button id="btn-run">Run</button>

<canvas id='your_canvas'></canvas> </br>

By clicking Run, the Canvas will render the image as the result of the code (Webgl). 通过单击“运行”,“画布”将根据代码(Webgl)渲染图像。 Below is the Javascript I have in order to make this possible: 下面是为了使之成为可能的Javascript:

$(window).load(function(){
  $("#btn-run").on('click', function(){
    scriptJS = $("#scriptJS").val();
    libsJS = $("#libsJS").val();
    eval(libsJS);
    eval(scriptJS);
    main();
  });
});

Now what I need to know in Ruby on Rails is how do I write this so that when the user click run, the result image in the Canvas (webgl) is saved and automatically rendered on the users profile. 现在,我需要在Ruby on Rails中知道的是如何编写该代码,以便在用户单击运行时将Canvas(webgl)中的结果图像保存并自动呈现在用户配置文件中。 I need the 3d webgl image result be saved and posted with the code so that you can still interact with the image in the canvas after it is saved and posted. 我需要将3d webgl图像结果保存并用代码发布,以便在保存并发布后仍可以与画布中的图像进行交互。 Any help would be great. 任何帮助都会很棒。

Cant see any ruby code there but i guess you want to transfer the rendered image to the server, doing so requires you to create the webgl context with 'preserveDrawingbuffer'. 不能在那里看到任何红宝石代码,但是我想您想将渲染的图像传输到服务器,这样做需要您使用'preserveDrawingbuffer'创建webgl上下文。 When enabled you can call toDataURL on the canvas element and get a jpg/png whatever base64 string you can send to your server using ajax. 启用后,您可以调用canvas元素上的toDataURL并获取jpg / png,无论您使用ajax可以将其发送到服务器的base64字符串是什么。

Oh and take some of this while you're at it: eval is evil 哦,趁着它取一些: 评估是邪恶的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM