solaris-js
Version:
A reusable component for interactive visualization of the Solar System
57 lines (41 loc) • 2.31 kB
text/coffeescript
import publicize from './helpers/publicizer'
# Based on RadialRingGeometry.js by Sander Blue:
# https://github.com/sanderblue/solar-system-threejs/blob/gh-pages/src/app/Extensions/RadialRingGeometry.js
import {
Vector3, Vector2, Face3, Sphere, Geometry
MeshLambertMaterial, TextureLoader, Mesh, DoubleSide
} from 'three'
{cos, sin, PI} = Math
PlanetaryRingGeometry = (iRadius = 0, oRadius = 50, thetaSegments = 8) ->
Geometry.call(this)
for i in [0...thetaSegments] # One "rectangle" (trapezoid) per ring segment
circle = PI * 2 # Complete revolution in radians
ccwEdge = circle * (i / thetaSegments) # Counter-clockwise border angle
cwEdge = circle * ((i + 1) / thetaSegments) # Clockwise border angle
# "top left"
# "top right"
# "bottom left"
# "bottom right"
# The two triangular faces that make up the "rectangle"
# Map triangle corners to (rectangular) texture corners
# tl, tr, bl
# bl, tr, br
return
PlanetaryRingGeometry.prototype = Object.create(Geometry.prototype)
class $Ring
constructor: (model, key, root, @scale) ->
innerRadius = @scale.convert(model.innerRadius)
outerRadius = @scale.convert(model.outerRadius)
geometry = new PlanetaryRingGeometry innerRadius, outerRadius, 64, 64
material = new MeshLambertMaterial
side: DoubleSide
transparent: yes
map: new TextureLoader().load("#{root}/img/#{key}-rings.png")
export default class Ring extends publicize $Ring,
properties: ['mesh']