static duk_ret_t AssetReferenceList_Set_uint_AssetReference(duk_context* ctx)
{
    AssetReferenceList* thisObj = GetThisValueObject<AssetReferenceList>(ctx, AssetReferenceList_ID);
    uint i = (uint)duk_require_number(ctx, 0);
    AssetReference& ref = *GetCheckedValueObject<AssetReference>(ctx, 1, AssetReference_ID);
    thisObj->Set(i, ref);
    return 0;
}
Пример #2
0
bool EC_Mesh::SetMaterial(uint index, const QString& material_name, AttributeChange::Type change)
{
    if (!entity_)
        return false;
    
    if (index >= entity_->getNumSubEntities())
    {
        LogError("EC_Mesh::SetMaterial: Could not set material " + material_name + ": illegal submesh index " + QString::number(index) + 
            ". Mesh \"" + meshRef.Get().ref + "\" has only " + QString::number(entity_->getNumSubEntities()) + " submeshes!");
        return false;
    }
    
    try
    {
        entity_->getSubEntity(index)->setMaterialName(AssetAPI::SanitateAssetRef(material_name.toStdString()));

        if (pendingFailedMaterials_.contains(index))
            pendingFailedMaterials_.removeAll(index);

        // Update the EC_Mesh material attribute list so that users can call EC_Mesh::SetMaterial as a replacement for setting
        // meshMaterial attribute. Only apply the change if the value really changed.
        AssetReferenceList materials = meshMaterial.Get();
        while(materials.Size() <= (int)index)
            materials.Append(AssetReference());
        if (material_name.compare(materials[index].ref, Qt::CaseSensitive) != 0)
        {
            materials.Set(index, AssetReference(material_name));
            meshMaterial.Set(materials, change); // Potentially signal the change of attribute, if requested so.
        }

        // To retain compatibility with old behavior, always fire the EC_Mesh -specific change signal independent of the value of 'change'.
        emit MaterialChanged(index, material_name);
    }
    catch(Ogre::Exception& e)
    {
        LogError("EC_Mesh::SetMaterial: Could not set material " + material_name + ": " + e.what());
        return false;
    }
    
    return true;
}