让 Three.js 项目在 ruby​​ on rails 应用程序中工作的最有效方法? [英] Most efficient way to get a Three.js project to work in a ruby on rails app?

查看:22
本文介绍了让 Three.js 项目在 ruby​​ on rails 应用程序中工作的最有效方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试 - 未成功 - 让 Three.js 项目在 Ruby on Rails 框架内工作

I'm trying -unsuccessfully- to get a Three.js project to work within the Ruby on Rails framework

我一直在想,一定有比我目前的做法更简单的方法来做到这一点

I keep thinking that there must be an easier way to do this than the way I'm doing it at the moment

首先,我在 google 上搜索了有关如何将工作 Three.js 代码移植到 rails 的指南/教程,但在该主题上发现的很少.我认为这意味着:要么人们不经常这样做 - 要么 - 很明显,没有人愿意记录它.

First I googled for a guide/tutorial on how to port working Three.js code to rails and found very little on the subject. Which I figure means: either people don't do it very often -or- that it's so obvious that no one has bothered to document it.

下一步我在谷歌上搜索了一个 Three.js gem 并在这里找到了一个 - http://rubygems.org/gems/threejs-导轨(我放弃了尝试开始工作 - 在对清单文件进行了大量处理之后)

Next I googled for a three.js gem and found one here - http://rubygems.org/gems/threejs-rails (which I gave up trying to get to work - after much messing around with the manifest file)

下一步我将 Three.js 的源代码安装到了 vendor 文件夹中,并再次弄乱了清单文件.这次我取得了更大的成功 - 尽管 Three.js 中似乎存在 require_tree(和我自己)都没有注意到的依赖问题.

Next I installed the source of Three.js into the vendors folder and messed around with the manifest file again. This time I had more success - although there seems to be dependency issues within Three.js that require_tree (and myself) are oblivious to.

所以理论上,在弄清楚 Three.js 加载顺序几个小时后,我可能可以让它工作,但这感觉不对.

So theoretically, I could probably get it to work after a several hours of figuring out the Three.js loading sequence, but this doesn't feel right.

我觉得我在这里走上了一条死胡同,我错过了一些明显的东西.

I feel like I've gone down a blind alley here and I'm missing something obvious.

  • 有没有更好的方法来做到这一点?

推荐答案

Rails 主要是一个后端服务器端框架.Three.js 是一个用于在浏览器中渲染 WebGL 的前端库.他们彼此关系不大.我觉得你太努力了.

Rails is, primarily, a back end server side framework. Three.js is a front end library for rendering WebGL in a browser. They have little to do with each other. I think you're trying too hard.

该过程与添加诸如 jQuery 或任何其他 javascript 库之类的内容相同.

The process is the same as adding something like jQuery, or any other javascript library.

  1. three.js 文件拖放到 app/assets/javascripts/three.js
  2. #= require 三 添加到您的 application.js.coffee
  3. 确保 javascript_include_tag('application') 是您的应用程序布局模板的一部分
  1. Drop the three.js file in app/assets/javascripts/three.js
  2. Add #= require three to your application.js.coffee
  3. Ensure that javascript_include_tag('application') is part of your application layout template

现在启动服务器,加载一个页面,然后在 javascript 控制台中输入 THREE.如果你得到一个返回值,你就很好!现在编写一些自定义 javascript,将其保存在 app/assets/javascripts 中,并将其包含在您想要制作出色 3D 内容的页面上.

Now launch the server, load a page, and type THREE in the javascript console. If you get a return value, your good! Now write some custom javascript, save it in app/assets/javascripts and include it on the pages you want to do awesome 3D stuff.

这篇关于让 Three.js 项目在 ruby​​ on rails 应用程序中工作的最有效方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆