mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-04-01 12:06:43 +00:00
Handle material properties in trishapeToGeometry
This commit is contained in:
parent
6c63bab8e4
commit
74dfb23e7b
1 changed files with 12 additions and 7 deletions
|
@ -113,12 +113,11 @@ namespace
|
||||||
collectMaterialProperties(nifNode->parent, out);
|
collectMaterialProperties(nifNode->parent, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateMaterialProperties(osg::StateSet* stateset, const std::vector<const Nif::Property*>& properties)
|
void updateMaterialProperties(osg::StateSet* stateset, const std::vector<const Nif::Property*>& properties, bool hasVertexColors)
|
||||||
{
|
{
|
||||||
int specFlags = 0; // Specular is disabled by default, even if there's a specular color in the NiMaterialProperty
|
int specFlags = 0; // Specular is disabled by default, even if there's a specular color in the NiMaterialProperty
|
||||||
osg::Material* mat = new osg::Material;
|
osg::Material* mat = new osg::Material;
|
||||||
// FIXME: color mode should be disabled if the TriShape has no vertex colors
|
mat->setColorMode(hasVertexColors ? osg::Material::AMBIENT_AND_DIFFUSE : osg::Material::OFF);
|
||||||
mat->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
|
|
||||||
for (std::vector<const Nif::Property*>::const_reverse_iterator it = properties.rbegin(); it != properties.rend(); ++it)
|
for (std::vector<const Nif::Property*>::const_reverse_iterator it = properties.rbegin(); it != properties.rend(); ++it)
|
||||||
{
|
{
|
||||||
const Nif::Property* property = *it;
|
const Nif::Property* property = *it;
|
||||||
|
@ -145,6 +144,8 @@ namespace
|
||||||
case Nif::RC_NiVertexColorProperty:
|
case Nif::RC_NiVertexColorProperty:
|
||||||
{
|
{
|
||||||
const Nif::NiVertexColorProperty* vertprop = static_cast<const Nif::NiVertexColorProperty*>(property);
|
const Nif::NiVertexColorProperty* vertprop = static_cast<const Nif::NiVertexColorProperty*>(property);
|
||||||
|
if (!hasVertexColors)
|
||||||
|
break;
|
||||||
switch (vertprop->flags)
|
switch (vertprop->flags)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -504,13 +505,20 @@ namespace NifOsg
|
||||||
geometry->setTexCoordArray(textureStage, new osg::Vec2Array(data->uvlist[uvSet].size(), &data->uvlist[uvSet][0]), osg::Array::BIND_PER_VERTEX);
|
geometry->setTexCoordArray(textureStage, new osg::Vec2Array(data->uvlist[uvSet].size(), &data->uvlist[uvSet][0]), osg::Array::BIND_PER_VERTEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: material ColorMode should be disabled if the TriShape has no vertex colors
|
|
||||||
if (!data->colors.empty())
|
if (!data->colors.empty())
|
||||||
geometry->setColorArray(new osg::Vec4Array(data->colors.size(), &data->colors[0]), osg::Array::BIND_PER_VERTEX);
|
geometry->setColorArray(new osg::Vec4Array(data->colors.size(), &data->colors[0]), osg::Array::BIND_PER_VERTEX);
|
||||||
|
|
||||||
geometry->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES,
|
geometry->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES,
|
||||||
data->triangles.size(),
|
data->triangles.size(),
|
||||||
(unsigned short*)&data->triangles[0]));
|
(unsigned short*)&data->triangles[0]));
|
||||||
|
|
||||||
|
// osg::Material properties are handled here for two reasons:
|
||||||
|
// - if there are no vertex colors, we need to disable colorMode.
|
||||||
|
// - there are 3 "overlapping" nif properties that all affect the osg::Material, handling them
|
||||||
|
// above the actual renderable would be tedious.
|
||||||
|
std::vector<const Nif::Property*> materialProps;
|
||||||
|
collectMaterialProperties(triShape, materialProps);
|
||||||
|
updateMaterialProperties(geometry->getOrCreateStateSet(), materialProps, !data->colors.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Loader::handleTriShape(const Nif::NiTriShape* triShape, osg::Group* parentNode, const std::map<int, int>& boundTextures)
|
void Loader::handleTriShape(const Nif::NiTriShape* triShape, osg::Group* parentNode, const std::map<int, int>& boundTextures)
|
||||||
|
@ -653,9 +661,6 @@ namespace NifOsg
|
||||||
case Nif::RC_NiSpecularProperty:
|
case Nif::RC_NiSpecularProperty:
|
||||||
{
|
{
|
||||||
// TODO: handle these in handleTriShape so we know whether vertex colors are available
|
// TODO: handle these in handleTriShape so we know whether vertex colors are available
|
||||||
std::vector<const Nif::Property*> materialProps;
|
|
||||||
collectMaterialProperties(nifNode, materialProps);
|
|
||||||
updateMaterialProperties(stateset, materialProps);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Nif::RC_NiAlphaProperty:
|
case Nif::RC_NiAlphaProperty:
|
||||||
|
|
Loading…
Reference in a new issue