1 /* 2 * Copyright 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SURROUND_VIEW_SERVICE_IMPL_MTLREADER_H_ 18 #define SURROUND_VIEW_SERVICE_IMPL_MTLREADER_H_ 19 20 #include <map> 21 #include <string> 22 23 #include "core_lib.h" 24 25 namespace android { 26 namespace hardware { 27 namespace automotive { 28 namespace sv { 29 namespace V1_0 { 30 namespace implementation { 31 32 // Mtl defined params. 33 struct MtlConfigParams { 34 // Ns exponent 35 // Specifies the specular exponent for the current material. This defines 36 // the focus of the specular highlight. 37 // Ns values normally range from 0 to 1000. 38 float ns = -1; 39 40 // optical_density 41 // Specifies the optical density for the surface. This is also known as 42 // index of refraction. 43 // "optical_density" is the value for the optical density. The values can 44 // range from 0.001 to 10. A value of 1.0 means that light does not bend 45 // as it passes through an object. Increasing the optical_density 46 // increases the amount of bending. Glass has an index of refraction of 47 // about 1.5. Values of less than 1.0 produce bizarre results and are not 48 // recommended. 49 float ni = -1; 50 51 // d defines the non-transparency of the material to be alpha. 52 // The default is 1.0 (not transparent at all). 53 // The quantities d and Tr are the opposites of each other. 54 float d = -1; 55 56 // The Tr statement specifies the transparency of the material to be alpha. 57 // The default is 0.0 (not transparent at all). 58 // The quantities d and Tr are the opposites of each other, 59 float tr = -1; 60 61 // The Tf statement specifies the transmission filter using RGB values. 62 // "r g b" are the values for the red, green, and blue components of the 63 // atmosphere. The g and b arguments are optional. If only r is 64 // specified, then g, and b are assumed to be equal to r. The r g b values 65 // are normally in the range of 0.0 to 1.0. Values outside this range 66 // increase or decrease the relectivity accordingly. 67 float tf[3] = {-1, -1, -1}; 68 69 // illum_# 70 // The "illum" statement specifies the illumination model to use in the 71 // material. Illumination models are mathematical equations that represent 72 // various material lighting and shading effects. 73 // 74 // "illum_#"can be a number from 0 to 10. The illumination models are 75 // summarized below; 76 // 77 // Illumination Properties that are turned on in the 78 // model Property Editor 79 // 80 // 0 Color on and Ambient off 81 // 1 Color on and Ambient on 82 // 2 Highlight on 83 // 3 Reflection on and Ray trace on 84 // 4 Transparency: Glass on 85 // Reflection: Ray trace on 86 // 5 Reflection: Fresnel on and Ray trace on 87 // 6 Transparency: Refraction on 88 // Reflection: Fresnel off and Ray trace on 89 // 7 Transparency: Refraction on 90 // Reflection: Fresnel on and Ray trace on 91 // 8 Reflection on and Ray trace off 92 // 9 Transparency: Glass on 93 // Reflection: Ray trace off 94 // 10 Casts shadows onto invisible surfaces 95 int illum = -1; 96 97 // The Ka statement specifies the ambient reflectivity using RGB values. 98 // "r g b" are the values for the red, green, and blue components of the 99 // color. The g and b arguments are optional. If only r is specified, 100 // then g, and b are assumed to be equal to r. The r g b values are 101 // normally in the range of 0.0 to 1.0. Values outside this range increase 102 // or decrease the relectivity accordingly. 103 float ka[3] = {-1, -1, -1}; 104 105 // The Kd statement specifies the diffuse reflectivity using RGB values. 106 // "r g b" are the values for the red, green, and blue components of the 107 // atmosphere. The g and b arguments are optional. If only r is 108 // specified, then g, and b are assumed to be equal to r. The r g b values 109 // are normally in the range of 0.0 to 1.0. Values outside this range 110 // increase or decrease the relectivity accordingly. 111 float kd[3] = {-1, -1, -1}; 112 113 // The Ks statement specifies the specular reflectivity using RGB values. 114 // "r g b" are the values for the red, green, and blue components of the 115 // atmosphere. The g and b arguments are optional. If only r is 116 // specified, then g, and b are assumed to be equal to r. The r g b values 117 // are normally in the range of 0.0 to 1.0. Values outside this range 118 // increase or decrease the relectivity accordingly. 119 float ks[3] = {-1, -1, -1}; 120 121 // Emissive coeficient. It goes together with ambient, diffuse and specular 122 // and represents the amount of light emitted by the material. 123 float ke[3] = {-1, -1, -1}; 124 125 // Specifies that a color texture file or color procedural texture file is 126 // linked to the specular reflectivity of the material. During rendering, 127 // the map_Ks value is multiplied by the Ks value. 128 std::string mapKs; 129 130 // Specifies that a color texture file or a color procedural texture file 131 // is applied to the ambient reflectivity of the material. During 132 // rendering, the "map_Ka" value is multiplied by the "Ka" value. 133 std::string mapKa; 134 135 // Specifies that a color texture file or color procedural texture file is 136 // linked to the diffuse reflectivity of the material. During rendering, 137 // the map_Kd value is multiplied by the Kd value. 138 std::string mapKd; 139 140 // Same as bump 141 std::string mapBump; 142 143 // Specifies that a bump texture file or a bump procedural texture file is 144 // linked to the material. 145 std::string bump; 146 147 MtlConfigParams& operator=(const MtlConfigParams& rhs) { 148 ns = rhs.ns; 149 ni = rhs.ni; 150 d = rhs.d; 151 tr = rhs.tr; 152 std::memcpy(tf, rhs.tf, 3 * sizeof(float)); 153 illum = rhs.illum; 154 std::memcpy(ka, rhs.ka, 3 * sizeof(float)); 155 std::memcpy(kd, rhs.kd, 3 * sizeof(float)); 156 std::memcpy(ks, rhs.ks, 3 * sizeof(float)); 157 std::memcpy(ke, rhs.ke, 3 * sizeof(float)); 158 mapKs = rhs.mapKs; 159 mapKa = rhs.mapKa; 160 mapKd = rhs.mapKd; 161 mapBump = rhs.mapBump; 162 bump = rhs.bump; 163 164 return *this; 165 } 166 }; 167 168 // Reads mtl file associated with obj file. 169 // |filename| is the full path and name of the obj file. 170 bool ReadMtlFromFile(const std::string& mtlFilename, 171 std::map<std::string, MtlConfigParams>* params); 172 173 } // namespace implementation 174 } // namespace V1_0 175 } // namespace sv 176 } // namespace automotive 177 } // namespace hardware 178 } // namespace android 179 180 #endif // SURROUND_VIEW_SERVICE_IMPL_MTLREADER_H_ 181