Testing out JmonkeyEngine to make a game in Scala with Akka Actors within a pure FP layer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB

4 years ago
4 years ago
4 years ago
  1. package com.jme3
  2. import com.jme3.scene.control.Control
  3. /**
  4. * Created by Brandon Barker on 6/19/17.
  5. */
  6. package object scene {
  7. object Geometry {
  8. /**
  9. * Create a geometry node with mesh data.
  10. * The material of the geometry is null, it cannot
  11. * be rendered until it is set.
  12. *
  13. * @param name The name of this geometry
  14. * @param mesh The mesh data for this geometry
  15. */
  16. def apply(name: String, mesh: Mesh): Geometry = new Geometry(name, mesh)
  17. }
  18. object Node {
  19. /**
  20. * Constructor instantiates a new <code>Node</code> with a default empty
  21. * list for containing children.
  22. *
  23. * @param name the name of the scene element. This is required for
  24. * identification and comparison purposes.
  25. */
  26. def apply(name: String): Node = new Node(name)
  27. }
  28. implicit final class NodeWrap(private val uval: Node) extends AnyVal {
  29. def getControlMaybe[T <: Control](controlType: Class[T]): Option[T] =
  30. Option(uval.getControl(controlType))
  31. }
  32. implicit final class SpatialWrap(private val uval: Spatial) extends AnyVal {
  33. def toNode: Either[ClassCastException, Node] =
  34. uval match {
  35. case ul: Node => Right(ul)
  36. case ul =>
  37. Left(
  38. new ClassCastException(s"Couldn't convert ${ul.getName} to Node")
  39. )
  40. }
  41. }
  42. }