forked from Mirrors/openclonk
GetMeshMaterial called from definition context now returns default mesh materials.
parent
2c7d9c0549
commit
e704cd2ecb
|
@ -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>() == "Clonk_Body")
|
||||
|
@ -28,8 +28,14 @@ else
|
|||
<funclink>SetMeshMaterial</funclink>("Clonk_Body");</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>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue