2001-11-27 18:50:04 -07:00
|
|
|
// 3dsmodel.h
|
2018-03-11 07:12:58 -06:00
|
|
|
//
|
2001-11-27 18:50:04 -07:00
|
|
|
// Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
|
2021-10-29 10:56:50 -06:00
|
|
|
#pragma once
|
2001-11-27 18:50:04 -07:00
|
|
|
|
2021-10-29 10:56:50 -06:00
|
|
|
#include <cstdint>
|
2001-11-27 18:50:04 -07:00
|
|
|
#include <string>
|
2021-10-29 10:56:50 -06:00
|
|
|
#include <vector>
|
|
|
|
|
2009-07-22 20:58:10 -06:00
|
|
|
#include <Eigen/Core>
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
class M3DColor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
M3DColor();
|
|
|
|
M3DColor(float, float, float);
|
|
|
|
|
|
|
|
public:
|
|
|
|
float red, green, blue;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class M3DMaterial
|
|
|
|
{
|
|
|
|
public:
|
2021-11-27 04:01:41 -07:00
|
|
|
M3DMaterial() = default;
|
|
|
|
~M3DMaterial() = default;
|
|
|
|
M3DMaterial(const M3DMaterial&) = delete;
|
|
|
|
M3DMaterial& operator=(const M3DMaterial&) = delete;
|
|
|
|
M3DMaterial(M3DMaterial&&) = default;
|
|
|
|
M3DMaterial& operator=(M3DMaterial&&) = default;
|
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
std::string getName() const;
|
2021-11-27 04:01:41 -07:00
|
|
|
void setName(std::string&&);
|
2001-11-27 18:50:04 -07:00
|
|
|
M3DColor getAmbientColor() const;
|
|
|
|
void setAmbientColor(M3DColor);
|
|
|
|
M3DColor getDiffuseColor() const;
|
|
|
|
void setDiffuseColor(M3DColor);
|
|
|
|
M3DColor getSpecularColor() const;
|
|
|
|
void setSpecularColor(M3DColor);
|
2002-01-08 00:48:35 -07:00
|
|
|
float getShininess() const;
|
|
|
|
void setShininess(float);
|
2002-03-05 14:24:31 -07:00
|
|
|
float getOpacity() const;
|
|
|
|
void setOpacity(float);
|
2002-01-08 01:12:54 -07:00
|
|
|
std::string getTextureMap() const;
|
|
|
|
void setTextureMap(const std::string&);
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
private:
|
2021-10-29 15:43:37 -06:00
|
|
|
std::string name{};
|
|
|
|
std::string texmap{};
|
2018-09-22 07:13:49 -06:00
|
|
|
M3DColor ambient{ 0, 0, 0 };
|
|
|
|
M3DColor diffuse{ 0, 0, 0 };
|
|
|
|
M3DColor specular{ 0, 0, 0 };
|
|
|
|
float shininess{ 1.0f };
|
|
|
|
float opacity{};
|
2001-11-27 18:50:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-02-05 13:05:18 -07:00
|
|
|
class M3DMeshMaterialGroup
|
|
|
|
{
|
2021-11-27 04:01:41 -07:00
|
|
|
public:
|
|
|
|
M3DMeshMaterialGroup() = default;
|
|
|
|
~M3DMeshMaterialGroup() = default;
|
|
|
|
M3DMeshMaterialGroup(const M3DMeshMaterialGroup&) = delete;
|
|
|
|
M3DMeshMaterialGroup& operator=(const M3DMeshMaterialGroup&) = delete;
|
|
|
|
M3DMeshMaterialGroup(M3DMeshMaterialGroup&&) = default;
|
|
|
|
M3DMeshMaterialGroup& operator=(M3DMeshMaterialGroup&&) = default;
|
|
|
|
|
2010-02-05 13:05:18 -07:00
|
|
|
std::string materialName;
|
2021-10-29 10:56:50 -06:00
|
|
|
std::vector<std::uint16_t> faces;
|
2010-02-05 13:05:18 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
class M3DTriangleMesh
|
|
|
|
{
|
|
|
|
public:
|
2021-11-27 04:01:41 -07:00
|
|
|
M3DTriangleMesh() = default;
|
|
|
|
~M3DTriangleMesh() = default;
|
|
|
|
M3DTriangleMesh(const M3DTriangleMesh&) = delete;
|
|
|
|
M3DTriangleMesh& operator=(const M3DTriangleMesh&) = delete;
|
|
|
|
M3DTriangleMesh(M3DTriangleMesh&&) = default;
|
|
|
|
M3DTriangleMesh& operator=(M3DTriangleMesh&&) = default;
|
|
|
|
|
2009-07-22 20:58:10 -06:00
|
|
|
Eigen::Matrix4f getMatrix() const;
|
|
|
|
void setMatrix(const Eigen::Matrix4f&);
|
2001-11-27 18:50:04 -07:00
|
|
|
|
2021-10-29 10:56:50 -06:00
|
|
|
Eigen::Vector3f getVertex(std::uint16_t) const;
|
|
|
|
std::uint16_t getVertexCount() const;
|
2009-07-22 20:58:10 -06:00
|
|
|
void addVertex(const Eigen::Vector3f&);
|
2001-11-27 18:50:04 -07:00
|
|
|
|
2021-10-29 10:56:50 -06:00
|
|
|
Eigen::Vector2f getTexCoord(std::uint16_t) const;
|
|
|
|
std::uint16_t getTexCoordCount() const;
|
2009-07-22 20:58:10 -06:00
|
|
|
void addTexCoord(const Eigen::Vector2f&);
|
2001-11-27 18:50:04 -07:00
|
|
|
|
2021-10-29 10:56:50 -06:00
|
|
|
void getFace(std::uint16_t, std::uint16_t&, std::uint16_t&, std::uint16_t&) const;
|
|
|
|
std::uint16_t getFaceCount() const;
|
|
|
|
void addFace(std::uint16_t, std::uint16_t, std::uint16_t);
|
2001-11-27 18:50:04 -07:00
|
|
|
|
2021-10-29 10:56:50 -06:00
|
|
|
void addSmoothingGroups(std::uint32_t);
|
|
|
|
std::uint32_t getSmoothingGroups(std::uint16_t) const;
|
|
|
|
std::uint16_t getSmoothingGroupCount() const;
|
2001-11-27 18:50:04 -07:00
|
|
|
|
2021-11-27 04:01:41 -07:00
|
|
|
void addMeshMaterialGroup(M3DMeshMaterialGroup&& matGroup);
|
|
|
|
const M3DMeshMaterialGroup* getMeshMaterialGroup(std::uint32_t) const;
|
2021-10-29 10:56:50 -06:00
|
|
|
std::uint32_t getMeshMaterialGroupCount() const;
|
2018-03-11 07:12:58 -06:00
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
private:
|
2021-10-29 15:43:37 -06:00
|
|
|
std::vector<Eigen::Vector3f> points{};
|
2021-12-15 07:14:58 -07:00
|
|
|
std::vector<Eigen::Vector2f> texCoords{};
|
2021-10-29 15:43:37 -06:00
|
|
|
std::vector<std::uint16_t> faces{};
|
|
|
|
std::vector<std::uint32_t> smoothingGroups{};
|
2021-11-27 04:01:41 -07:00
|
|
|
std::vector<M3DMeshMaterialGroup> meshMaterialGroups{};
|
2021-10-29 15:43:37 -06:00
|
|
|
Eigen::Matrix4f matrix{ Eigen::Matrix4f::Identity() };
|
2001-11-27 18:50:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class M3DModel
|
|
|
|
{
|
|
|
|
public:
|
2021-11-27 04:01:41 -07:00
|
|
|
M3DModel() = default;
|
|
|
|
~M3DModel() = default;
|
|
|
|
M3DModel(const M3DModel&) = delete;
|
|
|
|
M3DModel& operator=(const M3DModel&) = delete;
|
|
|
|
M3DModel(M3DModel&&) = default;
|
|
|
|
M3DModel& operator=(M3DModel&&) = default;
|
|
|
|
|
|
|
|
const M3DTriangleMesh* getTriMesh(std::uint32_t) const;
|
|
|
|
std::uint32_t getTriMeshCount() const;
|
|
|
|
void addTriMesh(M3DTriangleMesh&&);
|
2018-09-22 07:13:49 -06:00
|
|
|
void setName(const std::string&);
|
2021-11-27 04:01:41 -07:00
|
|
|
std::string getName() const;
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
private:
|
2021-10-29 15:43:37 -06:00
|
|
|
std::string name{};
|
2021-11-27 04:01:41 -07:00
|
|
|
std::vector<M3DTriangleMesh> triMeshes{};
|
2001-11-27 18:50:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class M3DScene
|
|
|
|
{
|
|
|
|
public:
|
2021-11-27 04:01:41 -07:00
|
|
|
M3DScene() = default;
|
|
|
|
~M3DScene() = default;
|
|
|
|
M3DScene(const M3DScene&) = delete;
|
|
|
|
M3DScene& operator=(const M3DScene&) = delete;
|
|
|
|
M3DScene(M3DScene&&) = default;
|
|
|
|
M3DScene& operator=(M3DScene&&) = default;
|
|
|
|
|
|
|
|
const M3DModel* getModel(std::uint32_t) const;
|
2021-10-29 14:48:09 -06:00
|
|
|
std::uint32_t getModelCount() const;
|
2021-11-27 04:01:41 -07:00
|
|
|
void addModel(M3DModel&&);
|
2001-11-27 18:50:04 -07:00
|
|
|
|
2021-11-27 04:01:41 -07:00
|
|
|
const M3DMaterial* getMaterial(std::uint32_t) const;
|
2021-10-29 14:48:09 -06:00
|
|
|
std::uint32_t getMaterialCount() const;
|
2021-11-27 04:01:41 -07:00
|
|
|
void addMaterial(M3DMaterial&&);
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
M3DColor getBackgroundColor() const;
|
|
|
|
void setBackgroundColor(M3DColor);
|
|
|
|
|
|
|
|
private:
|
2021-11-27 04:01:41 -07:00
|
|
|
std::vector<M3DModel> models{};
|
|
|
|
std::vector<M3DMaterial> materials{};
|
2021-10-29 15:43:37 -06:00
|
|
|
M3DColor backgroundColor{};
|
2001-11-27 18:50:04 -07:00
|
|
|
};
|