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 (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
96 96
97 bool defaultFallthrough;97 bool defaultFallthrough;
98 std::unordered_map<uint, bool> propertyFallthroughs; // not actually exposed to script98 std::unordered_map<uint, bool> propertyFallthroughs; // not actually exposed to script
99
100 graphics::MaterialKey key { 0 };
99 };101 };
100 102
101 /**jsdoc103 /**jsdoc
libraries/graphics-scripting/src/graphics-scripting/GraphicsScriptingInterface.cpp+75−14
@@ -364,20 +364,81 @@ namespace scriptable { · 363 unmodified lines
364 obj.setProperty("model", material.model);364 obj.setProperty("model", material.model);
365 365
366 const QScriptValue FALLTHROUGH("fallthrough");366 const QScriptValue FALLTHROUGH("fallthrough");
367 obj.setProperty("opacity", material.propertyFallthroughs.at(graphics::MaterialKey::OPACITY_VAL_BIT) ? FALLTHROUGH : material.opacity);367 if (material.propertyFallthroughs.at(graphics::MaterialKey::OPACITY_VAL_BIT)) {
368 obj.setProperty("roughness", material.propertyFallthroughs.at(graphics::MaterialKey::GLOSSY_VAL_BIT) ? FALLTHROUGH : material.roughness);368 obj.setProperty("opacity", FALLTHROUGH);
369 obj.setProperty("metallic", material.propertyFallthroughs.at(graphics::MaterialKey::METALLIC_VAL_BIT) ? FALLTHROUGH : material.metallic);369 } else if (material.key.isTranslucentFactor()) {
370 obj.setProperty("scattering", material.propertyFallthroughs.at(graphics::MaterialKey::SCATTERING_VAL_BIT) ? FALLTHROUGH : material.scattering);370 obj.setProperty("opacity", material.opacity);
371 obj.setProperty("unlit", material.propertyFallthroughs.at(graphics::MaterialKey::UNLIT_VAL_BIT) ? FALLTHROUGH : material.unlit);371 }
372 obj.setProperty("emissive", material.propertyFallthroughs.at(graphics::MaterialKey::EMISSIVE_VAL_BIT) ? FALLTHROUGH : vec3ColorToScriptValue(engine, material.emissive));372
373 obj.setProperty("albedo", material.propertyFallthroughs.at(graphics::MaterialKey::ALBEDO_VAL_BIT) ? FALLTHROUGH : vec3ColorToScriptValue(engine, material.albedo));373 if (material.propertyFallthroughs.at(graphics::MaterialKey::GLOSSY_VAL_BIT)) {
374 374 obj.setProperty("roughness", FALLTHROUGH);
375 obj.setProperty("emissiveMap", material.propertyFallthroughs.at(graphics::MaterialKey::EMISSIVE_MAP_BIT) ? FALLTHROUGH : material.emissiveMap);375 } else if (material.key.isGlossy()) {
376 obj.setProperty("albedoMap", material.propertyFallthroughs.at(graphics::MaterialKey::ALBEDO_MAP_BIT) ? FALLTHROUGH : material.albedoMap);376 obj.setProperty("roughness", material.roughness);
377 obj.setProperty("opacityMap", material.opacityMap);377 }
378 obj.setProperty("occlusionMap", material.propertyFallthroughs.at(graphics::MaterialKey::OCCLUSION_MAP_BIT) ? FALLTHROUGH : material.occlusionMap);378
379 obj.setProperty("lightmapMap", material.propertyFallthroughs.at(graphics::MaterialKey::LIGHTMAP_MAP_BIT) ? FALLTHROUGH : material.lightmapMap);379 if (material.propertyFallthroughs.at(graphics::MaterialKey::METALLIC_VAL_BIT)) {
380 obj.setProperty("scatteringMap", material.propertyFallthroughs.at(graphics::MaterialKey::SCATTERING_MAP_BIT) ? FALLTHROUGH : material.scatteringMap);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 }
381 442
382 // Only set one of each of these443 // Only set one of each of these
383 if (material.propertyFallthroughs.at(graphics::MaterialKey::METALLIC_MAP_BIT)) {444 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
45 defaultFallthrough = material.defaultFallthrough;45 defaultFallthrough = material.defaultFallthrough;
46 propertyFallthroughs = material.propertyFallthroughs;46 propertyFallthroughs = material.propertyFallthroughs;
47 47
48 key = material.key;
49
48 return *this;50 return *this;
49}51}
50 52
51scriptable::ScriptableMaterial::ScriptableMaterial(const graphics::MaterialPointer& material) :53scriptable::ScriptableMaterial::ScriptableMaterial(const graphics::MaterialPointer& material) {
52 name(material->getName().c_str()),54 if (material) {
53 model(material->getModel().c_str()),55 name = material->getName().c_str();
54 opacity(material->getOpacity()),56 model = material->getModel().c_str();
55 roughness(material->getRoughness()),57 opacity = material->getOpacity();
56 metallic(material->getMetallic()),58 roughness = material->getRoughness();
57 scattering(material->getScattering()),59 metallic = material->getMetallic();
58 unlit(material->isUnlit()),60 scattering = material->getScattering();
59 emissive(material->getEmissive()),61 unlit = material->isUnlit();
60 albedo(material->getAlbedo()),62 emissive = material->getEmissive();
61 defaultFallthrough(material->getDefaultFallthrough()),63 albedo = material->getAlbedo();
62 propertyFallthroughs(material->getPropertyFallthroughs())64 defaultFallthrough = material->getDefaultFallthrough();
63{65 propertyFallthroughs = material->getPropertyFallthroughs();
64 auto map = material->getTextureMap(graphics::Material::MapChannel::EMISSIVE_MAP);66 key = material->getKey();
65 if (map && map->getTextureSource()) {67
66 emissiveMap = map->getTextureSource()->getUrl().toString();68 auto map = material->getTextureMap(graphics::Material::MapChannel::EMISSIVE_MAP);
67 }69 if (map && map->getTextureSource()) {
70 emissiveMap = map->getTextureSource()->getUrl().toString();
71 }
68 72
69 map = material->getTextureMap(graphics::Material::MapChannel::ALBEDO_MAP);73 map = material->getTextureMap(graphics::Material::MapChannel::ALBEDO_MAP);
70 if (map && map->getTextureSource()) {74 if (map && map->getTextureSource()) {
71 albedoMap = map->getTextureSource()->getUrl().toString();75 albedoMap = map->getTextureSource()->getUrl().toString();
72 if (map->useAlphaChannel()) {76 if (map->useAlphaChannel()) {
73 opacityMap = albedoMap;77 opacityMap = albedoMap;
78 }
74 }79 }
75 }
76 80
77 map = material->getTextureMap(graphics::Material::MapChannel::METALLIC_MAP);81 map = material->getTextureMap(graphics::Material::MapChannel::METALLIC_MAP);
78 if (map && map->getTextureSource()) {82 if (map && map->getTextureSource()) {
79 if (map->getTextureSource()->getType() == image::TextureUsage::Type::METALLIC_TEXTURE) {83 if (map->getTextureSource()->getType() == image::TextureUsage::Type::METALLIC_TEXTURE) {
80 metallicMap = map->getTextureSource()->getUrl().toString();84 metallicMap = map->getTextureSource()->getUrl().toString();
81 } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::SPECULAR_TEXTURE) {85 } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::SPECULAR_TEXTURE) {
82 specularMap = map->getTextureSource()->getUrl().toString();86 specularMap = map->getTextureSource()->getUrl().toString();
87 }
83 }88 }
84 }
85 89
86 map = material->getTextureMap(graphics::Material::MapChannel::ROUGHNESS_MAP);90 map = material->getTextureMap(graphics::Material::MapChannel::ROUGHNESS_MAP);
87 if (map && map->getTextureSource()) {91 if (map && map->getTextureSource()) {
88 if (map->getTextureSource()->getType() == image::TextureUsage::Type::ROUGHNESS_TEXTURE) {92 if (map->getTextureSource()->getType() == image::TextureUsage::Type::ROUGHNESS_TEXTURE) {
89 roughnessMap = map->getTextureSource()->getUrl().toString();93 roughnessMap = map->getTextureSource()->getUrl().toString();
90 } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::GLOSS_TEXTURE) {94 } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::GLOSS_TEXTURE) {
91 glossMap = map->getTextureSource()->getUrl().toString();95 glossMap = map->getTextureSource()->getUrl().toString();
96 }
92 }97 }
93 }
94 98
95 map = material->getTextureMap(graphics::Material::MapChannel::NORMAL_MAP);99 map = material->getTextureMap(graphics::Material::MapChannel::NORMAL_MAP);
96 if (map && map->getTextureSource()) {100 if (map && map->getTextureSource()) {
97 if (map->getTextureSource()->getType() == image::TextureUsage::Type::NORMAL_TEXTURE) {101 if (map->getTextureSource()->getType() == image::TextureUsage::Type::NORMAL_TEXTURE) {
98 normalMap = map->getTextureSource()->getUrl().toString();102 normalMap = map->getTextureSource()->getUrl().toString();
99 } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::BUMP_TEXTURE) {103 } else if (map->getTextureSource()->getType() == image::TextureUsage::Type::BUMP_TEXTURE) {
100 bumpMap = map->getTextureSource()->getUrl().toString();104 bumpMap = map->getTextureSource()->getUrl().toString();
105 }
101 }106 }
102 }
103 107
104 map = material->getTextureMap(graphics::Material::MapChannel::OCCLUSION_MAP);108 map = material->getTextureMap(graphics::Material::MapChannel::OCCLUSION_MAP);
105 if (map && map->getTextureSource()) {109 if (map && map->getTextureSource()) {
106 occlusionMap = map->getTextureSource()->getUrl().toString();110 occlusionMap = map->getTextureSource()->getUrl().toString();
107 }111 }
108 112
109 map = material->getTextureMap(graphics::Material::MapChannel::LIGHTMAP_MAP);113 map = material->getTextureMap(graphics::Material::MapChannel::LIGHTMAP_MAP);
110 if (map && map->getTextureSource()) {114 if (map && map->getTextureSource()) {
111 lightmapMap = map->getTextureSource()->getUrl().toString();115 lightmapMap = map->getTextureSource()->getUrl().toString();
112 }116 }
113 117
114 map = material->getTextureMap(graphics::Material::MapChannel::SCATTERING_MAP);118 map = material->getTextureMap(graphics::Material::MapChannel::SCATTERING_MAP);
115 if (map && map->getTextureSource()) {119 if (map && map->getTextureSource()) {
116 scatteringMap = map->getTextureSource()->getUrl().toString();120 scatteringMap = map->getTextureSource()->getUrl().toString();
121 }
117 }122 }
118}123}
119 124