Skip to content

Commit

Permalink
Added texture function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfredo Di Napoli authored and Alfredo Di Napoli committed Apr 27, 2011
1 parent 073c623 commit 0a33800
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,4 +4,5 @@ lib
classes
*idea
models
textures
extra/fenvs.py
Binary file modified imgs/leonard.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions project.clj
@@ -1,4 +1,4 @@
(defproject clj3D "0.0.3"
(defproject clj3D "0.0.4"
:description "The first Clojure 3D Library"

:dependencies [[org.clojure/clojure "1.2.0"]
Expand All @@ -15,8 +15,7 @@
[org.clojars.charles-stain/xmlpull-xpp3 "1.1.4c"]
[incanter/incanter-core "1.2.3"]
[incanter/incanter-charts "1.2.3"]
[matchure "0.10.1"]
[potemkin "0.1.0"]]
[matchure "0.10.1"]]

:dev-dependencies [[swank-clojure "1.2.0-SNAPSHOT"]]
:source-path "src"
Expand Down
31 changes: 27 additions & 4 deletions src/clj3D/fenvs.clj
Expand Up @@ -32,6 +32,7 @@
[com.jme3.asset AssetManager]
[com.jme3.system JmeSystem]
[com.jme3.material Material RenderState$FaceCullMode]
[com.jme3.texture Texture]
[com.jme3.scene.shape Box Line Sphere Cylinder Torus Quad Dome]
[com.jme3.scene Node Geometry Spatial Mesh Mesh$Mode VertexBuffer VertexBuffer$Type]
[jme3tools.optimize GeometryBatchFactory]
Expand Down Expand Up @@ -86,6 +87,11 @@
(.setColor "Color" default-color)))


(defn- textured-material [texture]
(doto (Material. asset-manager "Common/MatDefs/Misc/Unshaded.j3md")
(.setTexture "ColorMap" texture)))


(defn- colored-material
[color-keyword]
(doto (Material. asset-manager "Common/MatDefs/Light/Lighting.j3md")
Expand All @@ -103,11 +109,18 @@
object)


;;For custom Obj files
(.registerLocator ^AssetManager asset-manager
(str (. System getProperty "user.dir") "/models")
"com.jme3.asset.plugins.FileLocator")


;;For user textures
(.registerLocator ^AssetManager asset-manager
(str (. System getProperty "user.dir") "/textures")
"com.jme3.asset.plugins.FileLocator")


(defn- optimize
"Optimize a Spatial. Internal use."
[spatial]
Expand Down Expand Up @@ -443,10 +456,20 @@
example, in Maya, before exporting a model Combine the
meshes into a single one and triangulate the resulting object."
[filename]
(let [imported-model ^Geometry (.loadModel asset-manager filename)]
(mknode ^Geometry
(doto ^Spatial imported-model
(.setMaterial (default-material))))))
(let [imported-model ^Geometry (.loadModel ^AssetManager asset-manager filename)]
(mknode ^Node
(doto ^Geometry imported-model
(.setMaterial (default-material))))))


(defhigh texture
"Apply a texture to a given spatial."
[filename spatial]
(let [tex ^Texture (.loadTexture ^AssetManager asset-manager filename)
material ^Material (textured-material tex)]
(doto ^Node spatial
(.setMaterial material))))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down

0 comments on commit 0a33800

Please sign in to comment.