Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/celengine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ set(CELENGINE_SOURCES
meshmanager.h
modelgeometry.cpp
modelgeometry.h
multitexture.cpp
multitexture.h
name.cpp
name.h
nebula.cpp
Expand Down
6 changes: 3 additions & 3 deletions src/celengine/atmosphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <Eigen/Core>

#include <celutil/color.h>
#include <celengine/multitexture.h>
#include <celutil/texhandle.h>

struct Atmosphere
{
Expand All @@ -31,8 +31,8 @@ struct Atmosphere

float cloudHeight{ 0.0f };
float cloudSpeed{ 0.0f };
MultiResTexture cloudTexture;
MultiResTexture cloudNormalMap;
celestia::util::TextureHandle cloudTexture{ celestia::util::TextureHandle::Invalid };
celestia::util::TextureHandle cloudNormalMap{ celestia::util::TextureHandle::Invalid };

float mieCoeff{ 0.0f };
float mieScaleHeight{ 0.0f };
Expand Down
21 changes: 8 additions & 13 deletions src/celengine/body.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include <celutil/color.h>
#include <celutil/flag.h>
#include <celutil/ranges.h>
#include <celutil/texhandle.h>
#include <celutil/utf8.h>
#include "meshmanager.h"
#include "multitexture.h"
#include "surface.h"

struct Atmosphere;
Expand Down Expand Up @@ -94,20 +94,15 @@ class PlanetarySystem //NOSONAR

struct RingSystem
{
RingSystem(float inner, float outer) :
innerRadius(inner), outerRadius(outer)
{
}

float innerRadius;
float outerRadius;
Color color;
MultiResTexture texture;

RingSystem(float inner, float outer) :
innerRadius(inner), outerRadius(outer),
color(1.0f, 1.0f, 1.0f),
texture()
{ };

RingSystem(float inner, float outer, Color _color, const MultiResTexture& _texture) :
innerRadius(inner), outerRadius(outer), color(_color), texture(_texture)
{ };
Color color{ 1.0f, 1.0f, 1.0f };
celestia::util::TextureHandle texture{ celestia::util::TextureHandle::Invalid };
};

// Object class enumeration:
Expand Down
60 changes: 41 additions & 19 deletions src/celengine/meshmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <celutil/tokenizer.h>
#include "modelgeometry.h"
#include "spheremesh.h"
#include "texmanager.h"

using celestia::util::GetLogger;

Expand Down Expand Up @@ -298,7 +297,9 @@ ConvertTriangleMesh(const M3DTriangleMesh& mesh,
}

std::unique_ptr<cmod::Model>
Convert3DSModel(const M3DScene& scene, const std::filesystem::path& texPath)
Convert3DSModel(const M3DScene& scene,
const std::filesystem::path& texPath,
TexturePaths& texturePaths)
{
auto model = std::make_unique<cmod::Model>();

Expand Down Expand Up @@ -327,11 +328,11 @@ Convert3DSModel(const M3DScene& scene, const std::filesystem::path& texPath)

if (!material->getTextureMap().empty())
{
ResourceHandle tex = GetTextureManager()->getHandle(TextureInfo(material->getTextureMap(), texPath, TextureFlags::WrapTexture));
util::TextureHandle tex = texturePaths.getHandle(material->getTextureMap(), texPath, TextureFlags::WrapTexture);
newMaterial.setMap(cmod::TextureSemantic::DiffuseMap, tex);
}

model->addMaterial(std::move(newMaterial));
model->addMaterial(newMaterial);
}

// Convert all models in the scene. Some confusing terminology: a 3ds 'scene' is the same
Expand Down Expand Up @@ -360,13 +361,13 @@ Convert3DSModel(const M3DScene& scene, const std::filesystem::path& texPath)
}

std::unique_ptr<cmod::Model>
Load3DSModel(const GeometryInfo& info)
Load3DSModel(const GeometryInfo& info, TexturePaths& texturePaths)
{
std::unique_ptr<M3DScene> scene = Read3DSFile(info.path);
if (scene == nullptr)
return nullptr;

std::unique_ptr<cmod::Model> model = Convert3DSModel(*scene, info.directory);
std::unique_ptr<cmod::Model> model = Convert3DSModel(*scene, info.directory, texturePaths);

if (info.isNormalized)
model->normalize(info.center);
Expand All @@ -376,19 +377,38 @@ Load3DSModel(const GeometryInfo& info)
return model;
}

class ModelLoader final : public cmod::ModelLoader
{
public:
ModelLoader(TexturePaths&, const std::filesystem::path&);

protected:
celestia::util::TextureHandle getHandle(const std::filesystem::path& filename) override;

private:
TexturePaths& m_paths;
const std::filesystem::path& m_directory;
};

ModelLoader::ModelLoader(TexturePaths& paths, const std::filesystem::path& directory) :
m_paths(paths), m_directory(directory)
{
}

celestia::util::TextureHandle
ModelLoader::getHandle(const std::filesystem::path& filename)
{
return m_paths.getHandle(filename, m_directory, TextureFlags::WrapTexture);
}

std::unique_ptr<cmod::Model>
LoadCMODModel(const GeometryInfo& info)
LoadCMODModel(const GeometryInfo& info, engine::TexturePaths& paths)
{
std::ifstream in(info.path, std::ios::binary);
if (!in.good())
return nullptr;

std::unique_ptr<cmod::Model> model = cmod::LoadModel(
in,
[&info](const std::filesystem::path& name)
{
return GetTextureManager()->getHandle(TextureInfo(name, info.directory, TextureFlags::WrapTexture));
});
std::unique_ptr<cmod::Model> model = ModelLoader(paths, info.directory).load(in);

if (model == nullptr)
return nullptr;
Expand Down Expand Up @@ -548,8 +568,10 @@ GeometryPaths::getInfo(GeometryHandle handle, GeometryInfo& info) const
return true;
}

GeometryManager::GeometryManager(std::shared_ptr<GeometryPaths> paths) :
m_paths(paths)
GeometryManager::GeometryManager(std::shared_ptr<GeometryPaths> geometryPaths,
std::shared_ptr<TexturePaths> texturePaths) :
m_geometryPaths(geometryPaths),
m_texturePaths(texturePaths)
{
m_geometry.insert_or_assign(GeometryHandle::Empty, std::make_unique<EmptyGeometry>());
}
Expand All @@ -568,18 +590,18 @@ GeometryManager::find(GeometryHandle handle)
assert(handle != GeometryHandle::Empty);

GeometryInfo info;
if (!m_paths->getInfo(handle, info))
if (!m_geometryPaths->getInfo(handle, info))
return nullptr;

std::unique_ptr<cmod::Model> model;
switch (DetermineFileType(info.path))
{
case ContentType::_3DStudio:
model = Load3DSModel(info);
model = Load3DSModel(info, *m_texturePaths);
break;

case ContentType::CelestiaModel:
model = LoadCMODModel(info);
model = LoadCMODModel(info, *m_texturePaths);
break;

case ContentType::CelestiaMesh:
Expand Down Expand Up @@ -609,7 +631,7 @@ GeometryManager::find(GeometryHandle handle)
// Sort the submeshes roughly by opacity. This will eliminate a
// good number of the errors caused when translucent triangles are
// rendered before geometry that they cover.
model->sortMeshes(cmod::Model::OpacityComparator());
model->sortMeshes();

model->determineOpacity();

Expand Down
6 changes: 4 additions & 2 deletions src/celengine/meshmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <celutil/classops.h>
#include <celutil/fsutils.h>
#include "geometry.h"
#include "texmanager.h"

namespace celestia::engine
{
Expand Down Expand Up @@ -101,12 +102,13 @@ class GeometryPaths : private util::NoCopy
class GeometryManager
{
public:
explicit GeometryManager(std::shared_ptr<GeometryPaths>);
GeometryManager(std::shared_ptr<GeometryPaths>, std::shared_ptr<TexturePaths>);

const Geometry* find(GeometryHandle);

private:
std::shared_ptr<GeometryPaths> m_paths;
std::shared_ptr<GeometryPaths> m_geometryPaths;
std::shared_ptr<TexturePaths> m_texturePaths;
std::unordered_map<GeometryHandle, std::unique_ptr<const Geometry>> m_geometry;
};

Expand Down
7 changes: 4 additions & 3 deletions src/celengine/modelgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ convert(cmod::VertexAttributeSemantic semantic)
void
setVertexArrays(gl::VertexObject &vao, const gl::Buffer &vbo, const cmod::VertexDescription& desc)
{
for (const auto &attribute : desc.attributes)
auto attributes = desc.attributes();
for (const auto &attribute : attributes)
{
if (attribute.semantic == cmod::VertexAttributeSemantic::InvalidSemantic)
continue;
Expand All @@ -93,7 +94,7 @@ setVertexArrays(gl::VertexObject &vao, const gl::Buffer &vbo, const cmod::Vertex
GLComponentCounts[static_cast<std::size_t>(attribute.format)],
GLComponentTypes[static_cast<std::size_t>(attribute.format)],
GLComponentNormalized[static_cast<std::size_t>(attribute.format)],
desc.strideBytes,
desc.strideBytes(),
attribute.offsetWords * sizeof(cmod::VWord));
}
}
Expand Down Expand Up @@ -133,7 +134,7 @@ ModelRenderGeometry::ModelRenderGeometry(std::shared_ptr<const cmod::Model> mode

m_vbos.emplace_back(gl::Buffer::TargetHint::Array,
util::array_view<void>(mesh->getVertexData(),
mesh->getVertexCount() * vertexDesc.strideBytes));
mesh->getVertexCount() * vertexDesc.strideBytes()));

indices.reserve(std::max(indices.capacity(), static_cast<std::size_t>(mesh->getIndexCount())));
for (unsigned int groupIndex = 0; groupIndex < mesh->getGroupCount(); ++groupIndex)
Expand Down
104 changes: 0 additions & 104 deletions src/celengine/multitexture.cpp

This file was deleted.

Loading
Loading