// MIT License // Copyright (c) 2012 DK22Pac // Copyright (c) 2017 FYP // Permission is…
- User
// MIT License
// Copyright (c) 2012 DK22Pac // Copyright (c) 2017 FYP
// Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE.
#include "pch.h" #include "vehicle_renderer.h" #include "lua_texture.h"
auto& VehicleRenderer::getVehicleData(CVehicle* veh) { if (!_vehicleData) _vehicleData = std::make_unique<VehicleDataExtended>(); return _vehicleData->get(veh); }
auto& VehicleRenderer::getVehicleMaterialProperties(CVehicle* veh) { return getVehicleData(veh)._materialProperties; }
void VehicleRenderer::setMaterialColor(CVehicle* veh, RpMaterial* material, RpGeometry* geometry, RwRGBA color) { auto& matProps = getVehicleMaterialProperties(veh)[material]; matProps._recolor = true; matProps._color = color; matProps._geometry = geometry; }
void VehicleRenderer::setMaterialTexture(CVehicle* veh, RpMaterial* material, std::shared_ptr<lua_texture::Texture> texture) { auto& matProps = getVehicleMaterialProperties(veh)[material]; matProps._retexture = true; matProps._texture = texture; }
void VehicleRenderer::resetMaterialColor(CVehicle* veh, RpMaterial* material) { if (isInitialized() && _vehicleData->exists(veh)) { auto& matProps = getVehicleMaterialProperties(veh)[material]; matProps._recolor = false; matProps._color = {0, 0, 0, 0}; } }
void VehicleRenderer::resetMaterialTexture(CVehicle* veh, RpMaterial* material) { if (isInitialized() && _vehicleData->exists(veh)) { auto& matProps = getVehicleMaterialProperties(veh)[material]; matProps._retexture = false; matProps._texture.reset(); } }
void VehicleRenderer::processRender(CVehicle* veh) { if (isInitialized() && _vehicleData->exists(veh)) { for (auto& it : _vehicleData->get(veh)._materialProperties) { if (it.second._recolor) { it.second._originalColor = it.first->color; it.first->color = it.second._color; it.second._originalGeometryFlags = it.second._geometry->flags; it.second._geometry->flags |= rpGEOMETRYMODULATEMATERIALCOLOR; } if (it.second._retexture) { auto tex = it.second._texture.lock(); if (tex) { it.second._originalTexture = it.first->texture; it.first->texture = tex->getRwTexture(); } else { it.second._retexture = false; } } } } }
void VehicleRenderer::postRender(CVehicle* veh) { if (isInitialized() && _vehicleData->exists(veh)) { for (auto& it : _vehicleData->get(veh)._materialProperties) { if (it.second._recolor) { it.first->color = it.second._originalColor; it.second._geometry->flags = it.second._originalGeometryFlags; } if (it.second._retexture) { it.first->texture = it.second._originalTexture; } } } }
дай вывод из этого кода что за структура RpMaterial и как в нее относится surface properties
- Assistant
На основании данного кода можно сделать предположения о структуре
RpMaterialи как она связана с surface properties.RpMaterial
RpMaterial- это структура, представляющая материал в системе рендеринга. Она, по крайней мере, включает следующие члены, судя по коду:RwRGBA color: Цвет материала.RwTexture* texture: Текстура, связанная с материалом.
Surface Properties
Информация о surface properties непосредственно в данной части кода не упоминается, но можно сделать предположение, что surface properties материала могут быть частью
RpMaterialили могут быть связаны сRpMaterialчерез другие объекты. Обычно, surface properties (свойства поверхности) включают такие характеристики, как жесткость, отражательность, трение и т.д.Вот пример возможного определения структуры
RpMaterial, основанного на предоставленном коде:struct RpMaterial { RwRGBA color; // Цвет материала RwTexture* texture; // Указатель на текстуру материала // Допустим, что surface properties могут быть здесь // SurfaceProperties surfaceProps; // Пример: свойства поверхности };Как связано с кодом
В коде
VehicleRendererнесколько функций манипулируют материалами:-
setMaterialColor- Устанавливает цвет материала и отмечает его для перекраски:void VehicleRenderer::setMaterialColor(CVehicle* veh, RpMaterial* material, RpGeometry* geometry, RwRGBA color) { auto& matProps = getVehicleMaterialProperties(veh)[material]; matProps._recolor = true; matProps._color = color; matProps._geometry = geometry; } -
setMaterialTexture- Устанавливает текстуру материала:void VehicleRenderer::setMaterialTexture(CVehicle* veh, RpMaterial* material, std::shared_ptr<lua_texture::Texture> texture) { auto& matProps = getVehicleMaterialProperties(veh)[material]; matProps._retexture = true; matProps._texture = texture; } -
resetMaterialColor- Сбрасывает цвет материала к его оригинальному состоянию:void VehicleRenderer::resetMaterialColor(CVehicle* veh, RpMaterial* material) { if (isInitialized() && _vehicleData->exists(veh)) { auto& matProps = getVehicleMaterialProperties(veh)[material]; matProps._recolor = false; matProps._color = {0, 0, 0, 0}; } } -
resetMaterialTexture- Сбрасывает текстуру материала к его оригинальному состоянию:void VehicleRenderer::resetMaterialTexture(CVehicle* veh, RpMaterial* material) { if (isInitialized() && _vehicleData->exists(veh)) { auto& matProps = getVehicleMaterialProperties(veh)[material]; matProps._retexture = false; matProps._texture.reset(); } } -
processRenderиpostRender- Эти функции управляют состоянием материалов до и после рендеринга:void VehicleRenderer::processRender(CVehicle* veh) { if (isInitialized() && _vehicleData->exists(veh)) { for (auto& it : _vehicleData->get(veh)._materialProperties) { if (it.second._recolor) { it.second._originalColor = it.first->color; it.first->color = it.second._color; it.second._originalGeometryFlags = it.second._geometry->flags; it.second._geometry->flags |= rpGEOMETRYMODULATEMATERIALCOLOR; } if (it.second._retexture) { auto tex = it.second._texture.lock(); if (tex) { it.second._originalTexture = it.first->texture; it.first->texture = tex->getRwTexture(); } else { it.second._retexture = false; } } } } } void VehicleRenderer::postRender(CVehicle* veh) { if (isInitialized() && _vehicleData->exists(veh)) { for (auto& it : _vehicleData->get(veh)._materialProperties) { if (it.second._recolor) { it.first->color = it.second._originalColor; it.second._geometry->flags = it.second._originalGeometryFlags; } if (it.second._retexture) { it.first->texture = it.second._originalTexture; } } } }
Поведение этих функций даёт понять, что структура
RpMaterialдолжна управлять параметрами окраски и текстуры, а также, возможно, другими свойствами поверхности, если они описаны в другом месте кода.