Allow multiple materials in one geometry

This commit is contained in:
Jeremy Penner 2013-11-22 23:15:27 -05:00
parent 7940bb61d5
commit 8c52f9f627

View file

@ -93,16 +93,14 @@
(let [idMat (id-from-mat mat) (let [idMat (id-from-mat mat)
idFx (str idMat "_fx")] idFx (str idMat "_fx")]
{:materials {:materials
[[:material {:id idMat :name idFx} [[:material {:id idMat }
[:instance_effect {:url (str "#" idFx)}]]] [:instance_effect {:url (str "#" idFx)}]]]
:effects :effects
[[:effect {:id idFx :name idFx} [[:effect {:id idFx}
[:profile_COMMON {} [:profile_COMMON {}
[:technique {:sid "common"} [:technique {:sid "common"}
[:phong {} [:phong {}
[:diffuse {} (dae-colour-from-mat mat)] [:diffuse {} (dae-colour-from-mat mat)]]]]]]})))
[:ambient {} (dae-colour-from-mat mat)]
[:specular {} (dae-colour-from-mat mat)]]]]]]})))
(defn rgmat-from-rgpoly [rgpoly] (defn rgmat-from-rgpoly [rgpoly]
(set (for [{mat :mat} rgpoly :when (not (nil? mat))] mat))) (set (for [{mat :mat} rgpoly :when (not (nil? mat))] mat)))
@ -115,18 +113,21 @@
(defn dae-geom-from-rgpoly [rgpoly id name] (defn dae-geom-from-rgpoly [rgpoly id name]
(let [rgtri (apply concat (map :rgvec3 rgpoly)) (let [rgtri (apply concat (map :rgvec3 rgpoly))
[mpvec3_i rgvec3] (dedup rgtri) [mpvec3_i rgvec3] (dedup rgtri)
mpmat_rgtri (reduce (fn [mp poly] (merge-with concat mp {(:mat poly) (:rgvec3 poly)})) {} rgpoly)
points_id (str id "_points") points_id (str id "_points")
vertices_id (str id "_vertices")] vertices_id (str id "_vertices")]
{:geometries {:geometries
[[:geometry {:id id :name name} [[:geometry {:id id :name name}
(into [] (concat
[:mesh {} [:mesh {}
(dae-vec3-array rgvec3 points_id "X" "Y" "Z") (dae-vec3-array rgvec3 points_id "X" "Y" "Z")
;todo: normals, textures ;todo: textures
[:vertices {:id vertices_id} [:vertices {:id vertices_id}
[:input {:semantic "POSITION" :source (str "#" points_id)}]] [:input {:semantic "POSITION" :source (str "#" points_id)}]]]
[:triangles {:count (count rgpoly) :material (id-from-mat (:mat (first rgpoly)))} (for [[mat rgtri] mpmat_rgtri]
[:triangles {:count (/ (count rgtri) 3) :material (id-from-mat mat)}
[:input {:semantic "VERTEX" :source (str "#" vertices_id) :offset 0}] [:input {:semantic "VERTEX" :source (str "#" vertices_id) :offset 0}]
[:p {} (clojure.string/join " " (map #(get mpvec3_i %) rgtri))]]]]]})) [:p {} (clojure.string/join " " (map #(get mpvec3_i %) rgtri))]])))]]}))
(defn now (defn now
"Returns current ISO 8601 compliant date." "Returns current ISO 8601 compliant date."
@ -157,7 +158,7 @@
[:bind_material {} [:bind_material {}
[:technique_common {} [:technique_common {}
(for [mat (rgmat-from-rgpoly rgpoly)] (for [mat (rgmat-from-rgpoly rgpoly)]
[:instance_material {:material (id-from-mat mat) [:instance_material {:symbol (id-from-mat mat)
:target (str "#" (id-from-mat mat))}])]]]]]]}) :target (str "#" (id-from-mat mat))}])]]]]]]})
[:instance_visual_scene {:url (str "#id_" name "_scene")}])) [:instance_visual_scene {:url (str "#id_" name "_scene")}]))
@ -206,10 +207,7 @@
(write-dae (rgpoly-cube (->vec3 0 0 0) nil) "cube" "C:/dev/unity/cube.dae")) (write-dae (rgpoly-cube (->vec3 0 0 0) nil) "cube" "C:/dev/unity/cube.dae"))
(defn -main (defn -main
"I don't do a whole lot ... yet." "Takes all the CKO files on the command line and converts them to DAEs."
[& args] [& args]
(doseq [filename args] (doseq [filename args]
(convert-cko-to-dae filename))) (convert-cko-to-dae filename)))
(convert-cko-to-dae "C:/dev/unity/8.cko")
;(write-test-cube)