Skip to content

Commit

Permalink
updated version and moved to separate repo
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkulaga committed Jun 6, 2015
0 parents commit 514de7e
Show file tree
Hide file tree
Showing 42 changed files with 5,949 additions and 0 deletions.
Empty file added .Rhistory
Empty file.
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*.class
*.log

# sbt specific
.cache/
.history/
.lib/
dist/*
target/
lib_managed/
src_managed/
project/boot/
project/plugins/project/

# Scala-IDE specific
.scala_dependencies
.worksheet

.idea
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: scala

jdk:
- oraclejdk8

scala:
- 2.11.6

sudo: false

cache:
directories:
- $HOME/.ivy2/cache
- $HOME/.sbt/boot/

script:
# Your normal script
- sbt -J-XX:ReservedCodeCacheSize=256M test

# Tricks to avoid unnecessary cache updates
- find $HOME/.sbt -name "*.lock" | xargs rm
- find $HOME/.ivy2 -name "ivydata-*.properties" | xargs rm
363 changes: 363 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
threejs facade
==============

This if a facade of threejs library. All the code is inside threejs subproject.

Usage
=====

In order to resolve a lib you should add a resolver::
```scala
resolvers += sbt.Resolver.bintrayRepo("denigma", "denigma-releases") //add resolver
libraryDependencies += "org.scalajs" %%% "threejs-facade" % "0.0.71-0.1.5" //add dependency
```

Gettings started
----------------

You can see an example in preview subproject.

To run preview:
```sbt
sbt //to opens sbt console
re-start //Use this command **instead of** run to run the app
Open localhost:5552 to see the result, it should reload whenever any sources are changed
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.denigma.threejs.extensions

import org.denigma.threejs.extensions.controls.{HoverControls, CameraControls}
import org.denigma.threejs.extras.HtmlRenderer
import org.denigma.threejs.{Scene, WebGLRendererParameters, WebGLRenderer}
import org.scalajs.dom.{MouseEvent, Event}


import scala.scalajs.js.{Array, Dynamic}


trait Container3D extends SceneContainer
{


container.style.width = width.toString
container.style.height = height.toString
container.style.position = "relative"

override type RendererType = WebGLRenderer


protected def initRenderer= {
val params = Dynamic.literal(
antialias = true,
alpha = true
//canvas = container
).asInstanceOf[ WebGLRendererParameters]
val vr = new WebGLRenderer(params)

vr.domElement.style.position = "absolute"
vr.domElement.style.top = "0"
vr.domElement.style.margin = "0"
vr.domElement.style.padding = "0"
vr.setSize(width,height)
vr
}
val cssScene = new Scene()

val cssRenderer:HtmlRenderer = this.initCSSRenderer


protected def initCSSRenderer = {
val rendererCSS = new HtmlRenderer()
rendererCSS.setSize(width,height)
rendererCSS.domElement.style.position = "absolute"
rendererCSS.domElement.style.top = "0"
rendererCSS.domElement.style.margin = "0"
rendererCSS.domElement.style.padding = "0"
rendererCSS
}


//val controls = new OrbitControls(camera,this.container)
val controls:CameraControls = new HoverControls(camera,this.container)


container.appendChild( renderer.domElement )
container.appendChild( cssRenderer.domElement )
//cssRenderer.domElement.appendChild( renderer.domElement )



override def onEnterFrame() = {
controls.update()
renderer.render( scene, camera )
cssRenderer.render( cssScene, camera )

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.denigma.threejs.extensions

import org.denigma.threejs.{Scene, PerspectiveCamera, Renderer}
import org.scalajs.dom
import org.scalajs.dom.raw.HTMLElement

trait SceneContainer{

val container: HTMLElement

def width:Double

def height:Double

type RendererType <:Renderer

val scene = new Scene()

def distance:Double = 2000

lazy val renderer: RendererType = this.initRenderer()


lazy val camera = initCamera()


def aspectRatio = width /height


protected def initRenderer():RendererType


protected def initCamera() =
{
val camera = new PerspectiveCamera(40, this.aspectRatio, 1, 1000000)
camera.position.z = distance
camera
}



protected def onEnterFrameFunction(double: Double): Unit = {
onEnterFrame()
render()
}

def onEnterFrame():Unit = {
renderer.render(scene, camera)
}



def render() = dom.requestAnimationFrame( onEnterFrameFunction _ )


}


Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package org.denigma.threejs.extensions.animations

import java.util.Date

import org.scalajs.dom
import Animation.{Started, AniState}
import scala.concurrent.duration.Duration
import scala.scalajs.js


class Scheduler
{
def current = js.Date.now

var animations = List.empty[Animation]

def add(ani:Animation) = {
this.animations = ani::animations
ani.state = Animation.Running(current)
}

def tick() =
{
val now = current
animations.foreach{ani=>
ani.state match {
case Animation.Running(start)=> ani(now)
case other =>
//dom.console.info(other.toString)
//do nothing
}
}
}

protected def onEnterFrameFunction(double: Double): Unit = {
this.tick()
start()
}



def start() = {
dom.requestAnimationFrame( onEnterFrameFunction _ )
this
}


}

object Easings {

val linear:Double=>Double = i=>i

}

/**
* contains states of animations and some other useful stuff
*/
object Animation{
trait AniState
trait Started extends AniState{
def start:Double

}
// trait Active extends Started{
// def position:Double
// }
case object Stopped extends AniState
case class Finished(start:Double) extends Started
case class Paused(start:Double) extends Started
case class Running(start:Double) extends Started
case class Backward(start:Double,finished:Double) extends Started

//def apply(length:Duration,easing:Double=>Double = i=>i)(fun:(Double=>Unit)):Animation= new Animation(length,easing)(fun)

}


class Animation(val length:Duration,easing:Double=>Double = Easings.linear)(fun:(Double=>Unit))
{

lazy val lengthMillis: Long = length.toMillis

var state:AniState = Animation.Stopped

def apply(current:Double) = state match {
case st:Started=>
val finish:Double = st.start +this.lengthMillis
easing( 1.0-(finish-current)/length.toMillis) match{
case p if p>=1.0=>
fun(1.0)
this.state = Animation.Finished(current)
case p if p < 0.0=>
dom.console.error(s"animation percent is $p that is below zero!\n " +
s"Current time is $current, start is ${st.start} and length is $lengthMillis")
this.state = Animation.Finished(current)

case p=>
fun(p)
//dom.console.info( s"Current time is $current, start is ${st.start} and length is $lengthMillis and percent is $p")

}

case _=> dom.console.error("trying to run an operation that has not started")
}


def go(implicit scheduler:Scheduler) = {
scheduler.add(this)
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.denigma.threejs.extensions.controls

import org.denigma.threejs.Vector3
import org.scalajs.dom.MouseEvent

trait CameraControls {

def onMouseDown( event:MouseEvent ):Unit
def onMouseMove( event:MouseEvent ):Unit
def onMouseUp( event:MouseEvent ):Unit
def onMouseWheel( event:MouseEvent ):Unit

def update():Unit

def enabled:Boolean

}

trait RotateControls extends CameraControls{
val center:Vector3
def rotateLeft( angle:Double ): Unit
def rotateRight( angle:Double ): Unit
def rotateUp( angle:Double ): Unit
def rotateDown( angle:Double ): Unit

def zoomIn(zScale:Double ): Unit
def zoomOut(zScale:Double): Unit

def pan(distance:Vector3): Vector3
}
Loading

0 comments on commit 514de7e

Please sign in to comment.