GetMeshMaterial called from definition context now returns default mesh materials.

heavy-resources
Sven Eberhardt 2014-04-18 14:09:49 +02:00
parent 2c7d9c0549
commit e704cd2ecb
3 changed files with 29 additions and 7 deletions

View File

@ -19,7 +19,7 @@
</param>
</params>
</syntax>
<desc>Returns the material currently set for the calling object.</desc>
<desc>Returns the material currently set for the calling object. May also be called from definition context to return the default material of the graphics of this definition.</desc>
<examples>
<example>
<code><funclink>if</funclink>(<funclink>GetMeshMaterial</funclink>() == &quot;Clonk_Body&quot;)
@ -28,8 +28,14 @@ else
<funclink>SetMeshMaterial</funclink>(&quot;Clonk_Body&quot;);</code>
<text>If a clonk has its eyes open then this script makes it close them, otherwise they are opened.</text>
</example>
<example>
<code><funclink>for</funclink> (var i=0,mat; mat=<funclink>GetID</funclink>()->GetMeshMaterial(i); ++i)
<funclink>SetMeshMaterial</funclink>(mat, i);</code>
<text>Resets the mesh material of all submeshes of this object to their respective defaults.</text>
</example>
</examples>
<related><funclink>SetMeshMaterial</funclink></related>
</func>
<author>Clonk-Karl</author><date>2010-04</date>
<author>Sven2</author><date>2014-04</date>
</funcs>

View File

@ -69,6 +69,7 @@ public:
bool Load(C4Group &hGroup, bool fColorByOwner); // load graphics from group
C4DefGraphics *Get(const char *szGrpName); // get graphics by name
void Clear(); // clear fields; delete additional graphics
bool IsMesh() const { return Type == TYPE_Mesh; }
bool IsColorByOwner() // returns whether ColorByOwner-surfaces have been created
{ return Type == TYPE_Mesh || !!Bmp.BitmapClr; } // Mesh can always apply PlayerColor (if used in its material)
bool CopyGraphicsFrom(C4DefGraphics &rSource); // copy bitmaps from source graphics

View File

@ -2150,13 +2150,28 @@ static bool FnSetAttachTransform(C4Object *Obj, long iAttachNumber, C4ValueArray
return true;
}
static Nillable<C4String*> FnGetMeshMaterial(C4Object *Obj, int iSubMesh)
static Nillable<C4String*> FnGetMeshMaterial(C4PropList * _this, int iSubMesh)
{
if (!Obj || !Obj->pMeshInstance) return C4Void();
if (iSubMesh < 0 || (unsigned int)iSubMesh >= Obj->pMeshInstance->GetNumSubMeshes()) return C4Void();
StdSubMeshInstance& submesh = Obj->pMeshInstance->GetSubMesh(iSubMesh);
return String(submesh.GetMaterial().Name.getData());
// Called in object or definition context?
C4Object *Obj = Object(_this);
if (!Obj)
{
if (!_this || !_this->GetDef()) throw new NeedNonGlobalContext("GetMeshMaterial");
// Called in definition context: Get definition default mesh material
C4Def *def = _this->GetDef();
if (!def->Graphics.IsMesh()) return C4Void();
if (iSubMesh < 0 || (unsigned int)iSubMesh >= def->Graphics.Mesh->GetNumSubMeshes()) return C4Void();
const StdSubMesh &submesh = def->Graphics.Mesh->GetSubMesh(iSubMesh);
return String(submesh.GetMaterial().Name.getData());
}
else
{
// Called in object context: Get material of mesh instance
if (!Obj->pMeshInstance) return C4Void();
if (iSubMesh < 0 || (unsigned int)iSubMesh >= Obj->pMeshInstance->GetNumSubMeshes()) return C4Void();
StdSubMeshInstance& submesh = Obj->pMeshInstance->GetSubMesh(iSubMesh);
return String(submesh.GetMaterial().Name.getData());
}
}
static bool FnSetMeshMaterial(C4Object *Obj, C4String* Material, int iSubMesh)