-
Notifications
You must be signed in to change notification settings - Fork 9
/
hello_material.clj
72 lines (60 loc) · 2.61 KB
/
hello_material.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
;; Please start your REPL with `+test` profile
(ns examples.beginner-tutorials.hello-material
"Clojure version of https://wiki.jmonkeyengine.org/docs/3.3/tutorials/beginner/hello_material.html"
(:require
[jme-clj.core :refer :all])
(:import
(com.jme3.material RenderState$BlendMode)
(com.jme3.math ColorRGBA)
(com.jme3.renderer.queue RenderQueue$Bucket)
(com.jme3.scene.shape Sphere$TextureMode)))
(defn init []
;;A simple textured cube -- in good MIP map quality.
(let [cube-1-mesh (box 1 1 1)
cube-1-geo (geo "My Textured Box" cube-1-mesh)
cube-1-mat (material "Common/MatDefs/Misc/Unshaded.j3md")
cube-1-tex (load-texture "Interface/Logo/Monkey.jpg")
;;A translucent/transparent texture, similar to a window frame.
cube-2-mesh (box 1 1 0.01)
cube-2-geo (geo "window frame" cube-2-mesh)
cube-2-mat (material "Common/MatDefs/Misc/Unshaded.j3md")
;;A bumpy rock with a shiny light effect.
sphere-mesh (sphere 32 32 2)
sphere-geo (geo "Shiny rock" sphere-mesh)
sphere-mesh (-> sphere-mesh
(set* :texture-mode Sphere$TextureMode/Projected)
generate)
sphere-mat (material "Common/MatDefs/Light/Lighting.j3md")]
(set* cube-1-mat :texture "ColorMap" cube-1-tex)
(set* cube-1-geo :material cube-1-mat)
(add-to-root cube-1-geo)
(set* cube-2-mat :texture "ColorMap" (load-texture "Textures/ColoredTex/Monkey.png"))
(-> cube-2-mat (get* :additional-render-state) (set* :blend-mode RenderState$BlendMode/Alpha))
(-> cube-2-geo
(set* :queue-bucket RenderQueue$Bucket/Transparent)
(set* :material cube-2-mat)
(add-to-root))
(-> sphere-mat
;; had to wrap with `float`, interop could not find the correct method
(set* :float "Shininess" (float 64.0))
(set* :texture "DiffuseMap" (load-texture "Textures/Terrain/Pond/Pond.jpg"))
(set* :texture "NormalMap" (load-texture "Textures/Terrain/Pond/Pond_normal.png"))
(set* :boolean "UseMaterialColors" true)
(set* :color "Diffuse" ColorRGBA/White))
(-> sphere-geo
(set* :material sphere-mat)
(set* :local-translation 0 2 -2)
(rotate 1.6 0 0)
(add-to-root))
(-> (light :directional)
(set* :direction (vec3 1 0 -2 :normalize))
(set* :color ColorRGBA/White)
(add-light-to-root))))
(defsimpleapp app :init init)
(comment
(start app)
;;after calling unbind-app, we need to re-define the app with defsimpleapp
(unbind-app #'app)
(run app
(re-init init))
)