问题
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
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.
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)
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.
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.
- is there a better way to do this?
回答1:
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.
The process is the same as adding something like jQuery, or any other javascript library.
- Drop the
three.js
file inapp/assets/javascripts/three.js
- Add
#= require three
to yourapplication.js.coffee
- Ensure that
javascript_include_tag('application')
is part of your application layout template
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.
回答2:
You can also use the following gem threejs-rails that I created for my rails app today. It works right out of the box if you're on rails 4+. Fork and submit a PR if you need further support on it!
Most efficient would obviously be via CDN, I plan to add that support soon.
来源:https://stackoverflow.com/questions/23479057/most-efficient-way-to-get-a-three-js-project-to-work-in-a-ruby-on-rails-app