/*! NIFLIB_HIDDEN function. For internal use only. */ internal MaterialWrapper(NiMaterialProperty mat, NiTexturingProperty texing, NiTextureProperty tex, NiMultiTextureProperty multi, NiSpecularProperty spec, NiAlphaProperty alpha, NiStencilProperty stencil, MatTexCollection creator) { mat_prop = mat; texing_prop = texing; tex_prop = tex; multi_prop = multi; spec_prop = spec; alpha_prop = alpha; stencil_prop = stencil; _creator = creator; }
/* * Creates a new material and adds it to the end of the array of materials * contained in this collection. The type of material data that will * appear in the new material must be specified, and a version number can be * used to determine how the data will be stored in the eventual NIF file. * Note that the multi_tex option is only a suggestion, as later NIF versions * combine the texture and multi-texture data into one NIF object. * \param[in] color Whether or not to include color data in the new * material. * \param[in] texture Whether or not to include base texture data in the * new material. * \param[in] multi_tex Whether or not to include multi-texture data in the * new material. * \param[in] multi_tex Whether or not to include multi-texture data in the * new material. This is only a suggestion as some NIF versions cannot * separate this from base texture information. * \param[in] specular Whether or not to include specular lighting data in * the new material. * \param[in] translucenty Whether or not to include alpha translucenty * data in the new material. * \param[in] version The NIF version to target when creating the underlying NIF * objects that store the requested types of data. * \return The index of the newly created material. */ public uint CreateMaterial(bool color, bool texture, bool multi_tex, bool specular, bool translucency, uint version) { //Make sure at least one option is set to true if (!color && !texture && !multi_tex && !specular && !translucency) { throw new Exception("At least one of the types of texture/material info needs to be stored in a new material. All the argumetns to MatTexCollection::CreateMaterial cannot be false."); } NiMaterialProperty mat = null; NiTexturingProperty texing = null; NiTextureProperty tex = null; NiMultiTextureProperty multi = null; NiSpecularProperty spec = null; NiAlphaProperty alpha = null; NiStencilProperty stencil = null; if (color) { mat = new NiMaterialProperty(); } if (specular) { spec = new NiSpecularProperty(); } if (translucency) { alpha = new NiAlphaProperty(); } if (version < Nif.VER_3_3_0_13) { //Old texturing property style if (texture) { tex = new NiTextureProperty(); } if (multi_tex) { multi = new NiMultiTextureProperty(); } } //New texturing property style else if (texture) { texing = new NiTexturingProperty(); } //Create Material and add it to the array materials.Add(new MaterialWrapper(mat, texing, tex, multi, spec, alpha, stencil, this)); //Return the index of the newly created material return(materials.Length - 1); }
/* * Retrieves the material index of the material that matches the given list * of properties, if any. * \param[in] properties An unsorted list of properties that is thought to contain some related to materials. * \return The index of the material that matches the given properties, * or NO_MATERIAL if no match is found. */ public uint GetMaterialIndex(NiProperty[] properties) { //Get Material and Texturing properties, if any NiMaterialProperty mat = null; NiTexturingProperty texing = null; NiTextureProperty tex = null; NiMultiTextureProperty multi = null; NiSpecularProperty spec = null; NiAlphaProperty alpha = null; NiStencilProperty stencil = null; for (var i = 0; i < properties.Length; ++i) { if (properties[i] == null) { continue; } if (properties[i].IsDerivedType(NiMaterialProperty.TYPE)) { mat = (NiMaterialProperty)properties[i]; } else if (properties[i].IsDerivedType(NiTexturingProperty.TYPE)) { texing = (NiTexturingProperty)properties[i]; } else if (properties[i].IsDerivedType(NiTextureProperty.TYPE)) { tex = (NiTextureProperty)properties[i]; } else if (properties[i].IsDerivedType(NiMultiTextureProperty.TYPE)) { multi = (NiMultiTextureProperty)properties[i]; } else if (properties[i].IsDerivedType(NiSpecularProperty.TYPE)) { spec = (NiSpecularProperty)properties[i]; } else if (properties[i].IsDerivedType(NiAlphaProperty.TYPE)) { alpha = (NiAlphaProperty)properties[i]; } else if (properties[i].IsDerivedType(NiStencilProperty.TYPE)) { stencil = (NiStencilProperty)properties[i]; } } //Do the search return(GetMaterialIndex(mat, texing, tex, multi, spec, alpha, stencil)); }
/* * Retrieves the material index of the material that matches the given list * of properties, if any. * \param[in] mat The NiMaterialProperty to match. * \param[in] texing The NiTexturingProperty to match. * \param[in] tex The NiTextureProperty to match. * \param[in] multi The NiMultiTextureProperty to match. * \return The index of the material that matches the specified properties, * or NO_MATERIAL if no match is found. */ public uint GetMaterialIndex(NiMaterialProperty mat, NiTexturingProperty texing, NiTextureProperty tex, NiMultiTextureProperty multi, NiSpecularProperty spec, NiAlphaProperty alpha, NiStencilProperty stencil) { for (var i = 0; i < materials.Length; ++i) { if (materials[i].mat_prop == mat && materials[i].texing_prop == texing && materials[i].tex_prop == tex && materials[i].multi_prop == multi && materials[i].spec_prop == spec && materials[i].alpha_prop == alpha && materials[i].stencil_prop == stencil) { //Match found, return its index return(i); } } //No match was found, return NO_MATERIAL return(NO_MATERIAL); }