History

working on material baker

SamGondelman committed 7 years ago

Commit 94de0c11 parent 4965adb13 files · +492 −79Browse files

Showing the changes to libraries/graphics-scripting/src/graphics-scripting (3 of 13 files). Show all

Unified · Split

3 files
  1. libraries/graphics-scripting/src/graphics-scripting/Forward.h +2 −0
  2. libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.cpp +75 −14
  3. libraries/graphics-scripting/src/graphics-scripting/ScriptableModel.cpp +60 −55
libraries/graphics-scripting/src/graphics-scripting/Forward.h+2−0
@@ -96,6 +96,8 @@ namespace scriptable { · 95 unmodified lines
9696
9797 bool defaultFallthrough;
9898 std::unordered_map<uint, bool> propertyFallthroughs; // not actually exposed to script
99+
100+ graphics::MaterialKey key { 0 };
99101 };
100102
101103 /**jsdoc
libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.cpp+75−14
@@ -364,20 +364,81 @@ namespace scriptable { · 363 unmodified lines
364364 obj.setProperty("model", material.model);
365365
366366 const QScriptValue FALLTHROUGH("fallthrough");
367− obj.setProperty("opacity", material.propertyFallthroughs.at(graphics::MaterialKey::OPACITY_VAL_BIT) ? FALLTHROUGH : material.opacity);
368− obj.setProperty("roughness", material.propertyFallthroughs.at(graphics::MaterialKey::GLOSSY_VAL_BIT) ? FALLTHROUGH : material.roughness);
369− obj.setProperty("metallic", material.propertyFallthroughs.at(graphics::MaterialKey::METALLIC_VAL_BIT) ? FALLTHROUGH : material.metallic);
370− obj.setProperty("scattering", material.propertyFallthroughs.at(graphics::MaterialKey::SCATTERING_VAL_BIT) ? FALLTHROUGH : material.scattering);
371− obj.setProperty("unlit", material.propertyFallthroughs.at(graphics::MaterialKey::UNLIT_VAL_BIT) ? FALLTHROUGH : material.unlit);
372− obj.setProperty("emissive", material.propertyFallthroughs.at(graphics::MaterialKey::EMISSIVE_VAL_BIT) ? FALLTHROUGH : vec3ColorToScriptValue(engine, material.emissive));
373− obj.setProperty("albedo", material.propertyFallthroughs.at(graphics::MaterialKey::ALBEDO_VAL_BIT) ? FALLTHROUGH : vec3ColorToScriptValue(engine, material.albedo));
374−
375− obj.setProperty("emissiveMap", material.propertyFallthroughs.at(graphics::MaterialKey::EMISSIVE_MAP_BIT) ? FALLTHROUGH : material.emissiveMap);
376− obj.setProperty("albedoMap", material.propertyFallthroughs.at(graphics::MaterialKey::ALBEDO_MAP_BIT) ? FALLTHROUGH : material.albedoMap);
377− obj.setProperty("opacityMap", material.opacityMap);
378− obj.setProperty("occlusionMap", material.propertyFallthroughs.at(graphics::MaterialKey::OCCLUSION_MAP_BIT) ? FALLTHROUGH : material.occlusionMap);
379− obj.setProperty("lightmapMap", material.propertyFallthroughs.at(graphics::MaterialKey::LIGHTMAP_MAP_BIT) ? FALLTHROUGH : material.lightmapMap);
380− obj.setProperty("scatteringMap", material.propertyFallthroughs.at(graphics::MaterialKey::SCATTERING_MAP_BIT) ? FALLTHROUGH : material.scatteringMap);
367+ if (material.propertyFallthroughs.at(graphics::MaterialKey::OPACITY_VAL_BIT)) {
368+ obj.setProperty("opacity", FALLTHROUGH);
369+ } else if (material.key.isTranslucentFactor()) {
370+ obj.setProperty("opacity", material.opacity);
371+ }
372+
373+ if (material.propertyFallthroughs.at(graphics::MaterialKey::GLOSSY_VAL_BIT)) {
374+ obj.setProperty("roughness", FALLTHROUGH);
375+ } else if (material.key.isGlossy()) {
376+ obj.setProperty("roughness", material.roughness);
377+ }
378+
379+ if (material.propertyFallthroughs.at(graphics::MaterialKey::METALLIC_VAL_BIT)) {
380+ obj.setProperty("metallic", FALLTHROUGH);
381+ } else if (material.key.isMetallic()) {
382+ obj.setProperty("metallic", material.metallic);
383+ }
384+
385+ if (material.propertyFallthroughs.at(graphics::MaterialKey::SCATTERING_VAL_BIT)) {
386+ obj.setProperty("scattering", FALLTHROUGH);
387+ } else if (material.key.isScattering()) {
388+ obj.setProperty("scattering", material.scattering);
389+ }
390+
391+ if (material.propertyFallthroughs.at(graphics::MaterialKey::UNLIT_VAL_BIT)) {
392+ obj.setProperty("unlit", FALLTHROUGH);
393+ } else if (material.key.isUnlit()) {
394+ obj.setProperty("unlit", material.unlit);
395+ }
396+
397+ if (material.propertyFallthroughs.at(graphics::MaterialKey::EMISSIVE_VAL_BIT)) {
398+ obj.setProperty("emissive", FALLTHROUGH);
399+ } else if (material.key.isEmissive()) {
400+ obj.setProperty("emissive", vec3ColorToScriptValue(engine, material.emissive));
401+ }
402+
403+ if (material.propertyFallthroughs.at(graphics::MaterialKey::ALBEDO_VAL_BIT)) {
404+ obj.setProperty("albedo", FALLTHROUGH);
405+ } else if (material.key.isAlbedo()) {
406+ obj.setProperty("albedo", vec3ColorToScriptValue(engine, material.albedo));
407+ }
408+
409+ if (material.propertyFallthroughs.at(graphics::MaterialKey::EMISSIVE_MAP_BIT)) {
410+ obj.setProperty("emissiveMap", FALLTHROUGH);
411+ } else if (!material.emissiveMap.isEmpty()) {
412+ obj.setProperty("emissiveMap", material.emissiveMap);
413+ }
414+
415+ if (material.propertyFallthroughs.at(graphics::MaterialKey::ALBEDO_MAP_BIT)) {
416+ obj.setProperty("albedoMap", FALLTHROUGH);
417+ } else if (!material.albedoMap.isEmpty()) {
418+ obj.setProperty("albedoMap", material.albedoMap);
419+ }
420+
421+ if (!material.opacityMap.isEmpty()) {
422+ obj.setProperty("opacityMap", material.opacityMap);
423+ }
424+
425+ if (material.propertyFallthroughs.at(graphics::MaterialKey::OCCLUSION_MAP_BIT)) {
426+ obj.setProperty("occlusionMap", FALLTHROUGH);
427+ } else if (!material.occlusionMap.isEmpty()) {
428+ obj.setProperty("occlusionMap", material.occlusionMap);
429+ }
430+
431+ if (material.propertyFallthroughs.at(graphics::MaterialKey::LIGHTMAP_MAP_BIT)) {
432+ obj.setProperty("lightmapMap", FALLTHROUGH);
433+ } else if (!material.lightmapMap.isEmpty()) {
434+ obj.setProperty("lightmapMap", material.lightmapMap);
435+ }
436+
437+ if (material.propertyFallthroughs.at(graphics::MaterialKey::SCATTERING_MAP_BIT)) {
438+ obj.setProperty("scatteringMap", FALLTHROUGH);
439+ } else if (!material.scatteringMap.isEmpty()) {
440+ obj.setProperty("scatteringMap", material.scatteringMap);
441+ }
381442
382443 // Only set one of each of these
383444 if (material.propertyFallthroughs.at(graphics::MaterialKey::METALLIC_MAP_BIT)) {
libraries/graphics-scripting/src/graphics-scripting/ScriptableModel.cpp+60−55
@@ -45,75 +45,80 @@ scriptable::ScriptableMaterial& scriptable::ScriptableMaterial::operator=(const · 44 unmodified lines
4545 defaultFallthrough = material.defaultFallthrough;
4646 propertyFallthroughs = material.propertyFallthroughs;
4747
48+ key = material.key;
49+
4850 return *this;
4951 }
5052
51−scriptable::ScriptableMaterial::ScriptableMaterial(const graphics::MaterialPointer& material) :
52− name(material->getName().c_str()),
53− model(material->getModel().c_str()),
54− opacity(material->getOpacity()),
55− roughness(material->getRoughness()),
56− metallic(material->getMetallic()),
57− scattering(material->getScattering()),
58− unlit(material->isUnlit()),
59− emissive(material->getEmissive()),
60− albedo(material->getAlbedo()),
61− defaultFallthrough(material->getDefaultFallthrough()),
62− propertyFallthroughs(material->getPropertyFallthroughs())
63−{
64− auto map = material->getTextureMap(graphics::Material::MapChannel::EMISSIVE_MAP);
65− if (map && map->getTextureSource()) {
66− emissiveMap = map->getTextureSource()->getUrl().toString();
67− }
53+scriptable::ScriptableMaterial::ScriptableMaterial(const graphics::MaterialPointer& material) {
54+ if (material) {
55+ name = material->getName().c_str();
56+ model = material->getModel().c_str();
57+ opacity = material->getOpacity();
58+ roughness = material->getRoughness();
59+ metallic = material->getMetallic();
60+ scattering = material->getScattering();
61+ unlit = material->isUnlit();
62+ emissive = material->getEmissive();
63+ albedo = material->getAlbedo();
64+ defaultFallthrough = material->getDefaultFallthrough();
65+ propertyFallthroughs = material->getPropertyFallthroughs();
66+ key = material->getKey();
67+
68+ auto map = material->getTextureMap(graphics::Material::MapChannel::EMISSIVE_MAP);
69+ if (map && map->getTextureSource()) {
70+ emissiveMap = map->getTextureSource()->getUrl().toString();
71+ }
6872
69− map = material->getTextureMap(graphics::Material::MapChannel::ALBEDO_MAP);
70− if (map && map->getTextureSource()) {
71− albedoMap = map->getTextureSource()->getUrl().toString();
72− if (map->useAlphaChannel()) {
73− opacityMap = albedoMap;
73+ map = material->getTextureMap(graphics::Material::MapChannel::ALBEDO_MAP);
74+ if (map && map->getTextureSource()) {
75+ albedoMap = map->getTextureSource()->getUrl().toString();
76+ if (map->useAlphaChannel()) {
77+ opacityMap = albedoMap;
78+ }
7479 }
75− }
7680
77− map = material->getTextureMap(graphics::Material::MapChannel::METALLIC_MAP);
78− if (map && map->getTextureSource()) {
79− if (map->getTextureSource()->getType() == image::TextureUsage::Type::METALLIC_TEXTURE) {
80− metallicMap = map->getTextureSource()->getUrl().toString();
81− } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::SPECULAR_TEXTURE) {
82− specularMap = map->getTextureSource()->getUrl().toString();
81+ map = material->getTextureMap(graphics::Material::MapChannel::METALLIC_MAP);
82+ if (map && map->getTextureSource()) {
83+ if (map->getTextureSource()->getType() == image::TextureUsage::Type::METALLIC_TEXTURE) {
84+ metallicMap = map->getTextureSource()->getUrl().toString();
85+ } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::SPECULAR_TEXTURE) {
86+ specularMap = map->getTextureSource()->getUrl().toString();
87+ }
8388 }
84− }
8589
86− map = material->getTextureMap(graphics::Material::MapChannel::ROUGHNESS_MAP);
87− if (map && map->getTextureSource()) {
88− if (map->getTextureSource()->getType() == image::TextureUsage::Type::ROUGHNESS_TEXTURE) {
89− roughnessMap = map->getTextureSource()->getUrl().toString();
90− } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::GLOSS_TEXTURE) {
91− glossMap = map->getTextureSource()->getUrl().toString();
90+ map = material->getTextureMap(graphics::Material::MapChannel::ROUGHNESS_MAP);
91+ if (map && map->getTextureSource()) {
92+ if (map->getTextureSource()->getType() == image::TextureUsage::Type::ROUGHNESS_TEXTURE) {
93+ roughnessMap = map->getTextureSource()->getUrl().toString();
94+ } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::GLOSS_TEXTURE) {
95+ glossMap = map->getTextureSource()->getUrl().toString();
96+ }
9297 }
93− }
9498
95− map = material->getTextureMap(graphics::Material::MapChannel::NORMAL_MAP);
96− if (map && map->getTextureSource()) {
97− if (map->getTextureSource()->getType() == image::TextureUsage::Type::NORMAL_TEXTURE) {
98− normalMap = map->getTextureSource()->getUrl().toString();
99− } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::BUMP_TEXTURE) {
100− bumpMap = map->getTextureSource()->getUrl().toString();
99+ map = material->getTextureMap(graphics::Material::MapChannel::NORMAL_MAP);
100+ if (map && map->getTextureSource()) {
101+ if (map->getTextureSource()->getType() == image::TextureUsage::Type::NORMAL_TEXTURE) {
102+ normalMap = map->getTextureSource()->getUrl().toString();
103+ } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::BUMP_TEXTURE) {
104+ bumpMap = map->getTextureSource()->getUrl().toString();
105+ }
101106 }
102− }
103107
104− map = material->getTextureMap(graphics::Material::MapChannel::OCCLUSION_MAP);
105− if (map && map->getTextureSource()) {
106− occlusionMap = map->getTextureSource()->getUrl().toString();
107− }
108+ map = material->getTextureMap(graphics::Material::MapChannel::OCCLUSION_MAP);
109+ if (map && map->getTextureSource()) {
110+ occlusionMap = map->getTextureSource()->getUrl().toString();
111+ }
108112
109− map = material->getTextureMap(graphics::Material::MapChannel::LIGHTMAP_MAP);
110− if (map && map->getTextureSource()) {
111− lightmapMap = map->getTextureSource()->getUrl().toString();
112− }
113+ map = material->getTextureMap(graphics::Material::MapChannel::LIGHTMAP_MAP);
114+ if (map && map->getTextureSource()) {
115+ lightmapMap = map->getTextureSource()->getUrl().toString();
116+ }
113117
114− map = material->getTextureMap(graphics::Material::MapChannel::SCATTERING_MAP);
115− if (map && map->getTextureSource()) {
116− scatteringMap = map->getTextureSource()->getUrl().toString();
118+ map = material->getTextureMap(graphics::Material::MapChannel::SCATTERING_MAP);
119+ if (map && map->getTextureSource()) {
120+ scatteringMap = map->getTextureSource()->getUrl().toString();
121+ }
117122 }
118123 }
119124