Compare commits

..

No commits in common. "5f3bed1c583399f815f32d830575acef46e249c8" and "10d69ce7ac10b490080eba674181af1b18c518ef" have entirely different histories.

25 changed files with 74 additions and 315 deletions

View file

@ -8,8 +8,6 @@ add_executable(autogen
src/object/codegen.cpp src/object/codegen.cpp
src/data/analysis.cpp src/data/analysis.cpp
src/data/codegen.cpp src/data/codegen.cpp
src/enum/analysis.cpp
src/enum/codegen.cpp
) )
set_target_properties(autogen PROPERTIES OUTPUT_NAME "autogen") set_target_properties(autogen PROPERTIES OUTPUT_NAME "autogen")

View file

@ -1,89 +0,0 @@
#include "analysis.h"
#include "../util.h"
#include <clang-c/CXFile.h>
#include <clang-c/CXSourceLocation.h>
#include <clang-c/Index.h>
#include <cstdio>
#include <optional>
using namespace enum_;
static int findEnumEntryValue(CXCursor cur, bool* success = nullptr) {
int ret = -1;
if (success != nullptr) *success = false;
x_clang_visitChildren(cur, [&](CXCursor cur, CXCursor parent) {
CXCursorKind kind = clang_getCursorKind(cur);
if (kind != CXCursor_IntegerLiteral) return CXChildVisit_Recurse;
// https://stackoverflow.com/a/63859988/16255372
auto res = clang_Cursor_Evaluate(cur);
ret = clang_EvalResult_getAsInt(res);
clang_EvalResult_dispose(res);
if (success != nullptr) *success = true;
return CXChildVisit_Break;
});
return ret;
}
static void processEnumEntry(CXCursor cur, EnumAnalysis* state, int* lastValue) {
EnumEntry anly;
std::string name = x_clang_toString(clang_getCursorSpelling(cur));
bool success;
int value = findEnumEntryValue(cur, &success);
// Default to lastValue + 1
if (!success) value = ++(*lastValue);
*lastValue = value;
anly.name = name;
anly.value = value;
state->entries.push_back(anly);
}
static void processEnum(CXCursor cur, AnalysisState* state, std::string className, std::string srcRoot) {
EnumAnalysis anly;
anly.name = className;
int lastValue = -1;
x_clang_visitChildren(cur, [&](CXCursor cur, CXCursor parent) {
CXCursorKind kind = clang_getCursorKind(cur);
if (kind == CXCursor_EnumConstantDecl) {
processEnumEntry(cur, &anly, &lastValue);
}
return CXChildVisit_Continue;
});
state->classes[className] = anly;
}
bool enum_::analyzeClasses(CXCursor cursor, std::string srcRoot, AnalysisState* state) {
// Search for classes
x_clang_visitChildren(cursor, [&](CXCursor cur, CXCursor parent) {
CXCursorKind kind = clang_getCursorKind(cur);
if (kind == CXCursor_Namespace) return CXChildVisit_Recurse;
if (kind != CXCursor_EnumDecl) return CXChildVisit_Continue;
CXSourceLocation loc = clang_getCursorLocation(cur);
if (!clang_Location_isFromMainFile(loc)) return CXChildVisit_Continue; // This class is not from this header. Skip
std::string className = x_clang_toString(clang_getCursorDisplayName(cur));
// Forward-decls can slip through the cracks, this prevents that, but also allows us to filter non-instance classes in the src/objects directory
if (!findAnnotation(cur, "OB::def_enum")) return CXChildVisit_Continue; // Class is not "primary" declaration/is not instance, skip
if (state->classes.count(className) > 0) return CXChildVisit_Continue; // Class has already been analyzed, skip...
processEnum(cur, state, className, srcRoot);
return CXChildVisit_Continue;
});
return true;
}

View file

@ -1,26 +0,0 @@
#pragma once
#include <clang-c/Index.h>
#include <map>
#include <string>
#include <vector>
namespace enum_ {
struct EnumEntry {
std::string name;
int value;
};
struct EnumAnalysis {
std::string name;
std::vector<EnumEntry> entries;
};
struct AnalysisState {
std::map<std::string, EnumAnalysis> classes;
};
bool analyzeClasses(CXCursor cursor, std::string srcRoot, AnalysisState* state);
}

View file

@ -1,31 +0,0 @@
#include "codegen.h"
#include "analysis.h"
#include <fstream>
#include <string>
#include <vector>
using namespace enum_;
void enum_::writeCodeForClass(std::ofstream& out, std::string headerPath, EnumAnalysis& state) {
out << "#include \"datatypes/enum.h\"\n\n";
out << "static std::pair<int, std::string> __values_" << state.name << "[] = {\n";
for (auto entry : state.entries) {
out << " { " << entry.value << ", \"" << entry.name << "\" },\n";
}
out << "};\n\n";
out << "static _EnumData __data_" << state.name << " = {\n"
<< " \"" << state.name << "\",\n"
<< " __values_" << state.name << ",\n"
<< " " << state.entries.size() << "\n"
<< "};\n\n";
out << "namespace EnumType {\n"
// extern is necessary here too to prevent "const" from marking Enum as implicitly static
// https://stackoverflow.com/questions/2190919/mixing-extern-and-const#comment2509591_2190981
<< " extern const Enum " << state.name << "(&__data_" << state.name << ");\n"
<< "}\n\n";
}

View file

@ -1,10 +0,0 @@
#pragma once
#include "analysis.h"
#include <fstream>
namespace enum_ {
void writeCodeForClass(std::ofstream& out, std::string headerPath, EnumAnalysis& state);
}

View file

@ -6,8 +6,6 @@
#include <cstdio> #include <cstdio>
#include <fstream> #include <fstream>
#include <filesystem> #include <filesystem>
#include "enum/analysis.h"
#include "enum/codegen.h"
#include "object/analysis.h" #include "object/analysis.h"
#include "object/codegen.h" #include "object/codegen.h"
#include "data/analysis.h" #include "data/analysis.h"
@ -52,13 +50,11 @@ int processHeader(fs::path srcRoot, fs::path srcPath, fs::path outPath) {
object::AnalysisState objectAnlyState; object::AnalysisState objectAnlyState;
data::AnalysisState dataAnlyState; data::AnalysisState dataAnlyState;
enum_::AnalysisState enumAnlyState;
fs::path relpath = fs::relative(srcPath, srcRoot); fs::path relpath = fs::relative(srcPath, srcRoot);
printf("[AUTOGEN] Processing file %s...\n", relpath.c_str()); printf("[AUTOGEN] Processing file %s...\n", relpath.c_str());
object::analyzeClasses(cursor, srcRoot, &objectAnlyState); object::analyzeClasses(cursor, srcRoot, &objectAnlyState);
data::analyzeClasses(cursor, srcRoot, &dataAnlyState); analyzeClasses(cursor, srcRoot, &dataAnlyState);
enum_::analyzeClasses(cursor, srcRoot, &enumAnlyState);
fs::create_directories(outPath.parent_path()); // Make sure generated dir exists before we try writing to it fs::create_directories(outPath.parent_path()); // Make sure generated dir exists before we try writing to it
@ -76,11 +72,7 @@ int processHeader(fs::path srcRoot, fs::path srcPath, fs::path outPath) {
} }
for (auto& [_, clazz] : dataAnlyState.classes) { for (auto& [_, clazz] : dataAnlyState.classes) {
data::writeCodeForClass(outStream, relpath, clazz); writeCodeForClass(outStream, relpath, clazz);
}
for (auto& [_, clazz] : enumAnlyState.classes) {
enum_::writeCodeForClass(outStream, relpath, clazz);
} }
outStream.close(); outStream.close();

View file

@ -80,13 +80,7 @@ static void processField(CXCursor cur, ClassAnalysis* state) {
anly.flags = anly.flags | PropertyFlags::PropertyFlag_Readonly; anly.flags = anly.flags | PropertyFlags::PropertyFlag_Readonly;
CXType type = clang_getCursorType(cur); CXType type = clang_getCursorType(cur);
anly.backingFieldType = x_clang_toString(clang_getTypeSpelling(type)); anly.backingFieldType = x_clang_toString(clang_getTypeSpelling(type)).c_str();
CXCursor typeCur = clang_getTypeDeclaration(type);
bool isEnum = findAnnotation(typeCur, "OB::def_enum").has_value();
if (isEnum) {
anly.backingFieldType = "EnumItem";
anly.backingFieldEnum = x_clang_toString(clang_getTypeSpelling(type));
}
state->properties.push_back(anly); state->properties.push_back(anly);

View file

@ -31,7 +31,6 @@ struct PropertyAnalysis {
std::string fieldName; std::string fieldName;
CFrameMember cframeMember = CFrameMember_None; // for cframe_position_prop etc. CFrameMember cframeMember = CFrameMember_None; // for cframe_position_prop etc.
std::string backingFieldType; std::string backingFieldType;
std::string backingFieldEnum;
std::string onUpdateCallback; std::string onUpdateCallback;
std::string category; std::string category;
PropertyFlags flags = (PropertyFlags)0; PropertyFlags flags = (PropertyFlags)0;

View file

@ -89,8 +89,6 @@ static void writePropertySetHandler(std::ofstream& out, ClassAnalysis state) {
} else if (!subtype.empty()) { } else if (!subtype.empty()) {
out << "\n std::weak_ptr<Instance> ref = value.get<InstanceRef>();" out << "\n std::weak_ptr<Instance> ref = value.get<InstanceRef>();"
<< "\n this->" << prop.fieldName << " = ref.expired() ? std::weak_ptr<" << subtype << ">() : std::dynamic_pointer_cast<" << subtype << ">(ref.lock());"; << "\n this->" << prop.fieldName << " = ref.expired() ? std::weak_ptr<" << subtype << ">() : std::dynamic_pointer_cast<" << subtype << ">(ref.lock());";
} else if (prop.backingFieldType == "EnumItem") {
out << "\n this->" << prop.fieldName << " = (" << prop.backingFieldEnum << ")value.get<EnumItem>().Value();";
} else { } else {
out << "\n this->" << prop.fieldName << " = " << castFromVariant("value", prop.backingFieldType) << ";"; out << "\n this->" << prop.fieldName << " = " << castFromVariant("value", prop.backingFieldType) << ";";
} }
@ -145,8 +143,6 @@ static void writePropertyGetHandler(std::ofstream& out, ClassAnalysis state) {
out << "\n return Variant(" << prop.fieldName << ".Position());"; out << "\n return Variant(" << prop.fieldName << ".Position());";
} else if (prop.cframeMember == CFrameMember_Rotation) { } else if (prop.cframeMember == CFrameMember_Rotation) {
out << "\n return Variant(" << prop.fieldName << ".ToEulerAnglesXYZ());"; out << "\n return Variant(" << prop.fieldName << ".ToEulerAnglesXYZ());";
} else if (prop.backingFieldType == "EnumItem") {
out << "\n return Variant(EnumType::" << prop.backingFieldEnum << ".FromValueInternal((int)" << prop.fieldName << "));";
} else { } else {
out << "\n return Variant(" << castToVariant(prop.fieldName, prop.backingFieldType) << ");"; out << "\n return Variant(" << castToVariant(prop.fieldName, prop.backingFieldType) << ");";
} }
@ -197,7 +193,7 @@ static void writePropertyMetaHandler(std::ofstream& out, ClassAnalysis state) {
std::string typeInfo = TYPEINFO_REFS[prop.backingFieldType]; std::string typeInfo = TYPEINFO_REFS[prop.backingFieldType];
if (typeInfo.empty()) typeInfo = prop.backingFieldType + "::TYPE"; if (typeInfo.empty()) typeInfo = prop.backingFieldType + "::TYPE";
if (!parseWeakPtr(prop.backingFieldType).empty()) typeInfo = "InstanceRef::TYPE"; if (!parseWeakPtr(prop.backingFieldType).empty()) typeInfo = "InstanceRef::TYPE";
if (prop.backingFieldType == "EnumItem") typeInfo = "EnumType::" + prop.backingFieldEnum; if (prop.backingFieldType == "SurfaceType") typeInfo = "INT_TYPE";
std::string strFlags; std::string strFlags;
if (prop.flags & PropertyFlag_Readonly) if (prop.flags & PropertyFlag_Readonly)
@ -260,8 +256,8 @@ void object::writeCodeForClass(std::ofstream& out, std::string headerPath, Class
out << "#define __AUTOGEN_EXTRA_INCLUDES__\n"; out << "#define __AUTOGEN_EXTRA_INCLUDES__\n";
out << "#include \"" << state.headerPath << "\"\n\n"; out << "#include \"" << state.headerPath << "\"\n\n";
out << "#include \"datatypes/variant.h\"\n"; out << "#include \"datatypes/variant.h\"\n\n";
out << "#include \"datatypes/primitives.h\"\n"; out << "#include \"datatypes/primitives.h\"\n\n";
out << "const InstanceType " << state.name << "::TYPE = {\n" out << "const InstanceType " << state.name << "::TYPE = {\n"
<< " .super = &" << state.baseClass << "::TYPE,\n" << " .super = &" << state.baseClass << "::TYPE,\n"
<< " .className = \"" << state.name << "\",\n" << " .className = \"" << state.name << "\",\n"

View file

@ -16,7 +16,7 @@ find_package(PkgConfig REQUIRED)
pkg_check_modules(LUAJIT REQUIRED luajit) pkg_check_modules(LUAJIT REQUIRED luajit)
# Run autogen # Run autogen
file(GLOB_RECURSE AUTOGEN_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/src" "src/objects/*.h" "src/datatypes/*.h" "src/enum/*.h") file(GLOB_RECURSE AUTOGEN_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/src" "src/objects/*.h" "src/datatypes/*.h")
# https://cmake.org/cmake/help/book/mastering-cmake/chapter/Custom%20Commands.html # https://cmake.org/cmake/help/book/mastering-cmake/chapter/Custom%20Commands.html
foreach (SRC ${AUTOGEN_SOURCES}) foreach (SRC ${AUTOGEN_SOURCES})

View file

@ -38,11 +38,11 @@ struct InstanceType;
struct TypeMeta { struct TypeMeta {
const TypeDesc* descriptor; const TypeDesc* descriptor;
union { union {
const Enum* enum_; // Applicable for EnumItem Enum* enum_; // Applicable for EnumItem
const InstanceType* instType; // Applicable for InstanceRef InstanceType* instType; // Applicable for InstanceRef
}; };
inline TypeMeta(const TypeDesc* descriptor) : descriptor(descriptor) {} inline TypeMeta(const TypeDesc* descriptor) : descriptor(descriptor) {}
TypeMeta(const Enum*); TypeMeta(Enum*);
TypeMeta(const InstanceType*); TypeMeta(InstanceType*);
}; };

View file

@ -4,7 +4,7 @@
#include "error/data.h" #include "error/data.h"
#include <pugixml.hpp> #include <pugixml.hpp>
TypeMeta::TypeMeta(const Enum* enum_) : enum_(enum_), descriptor(&EnumItem::TYPE) {} TypeMeta::TypeMeta(Enum* enum_) : enum_(enum_), descriptor(&EnumItem::TYPE) {}
Enum::Enum(_EnumData* data) : data(data) {} Enum::Enum(_EnumData* data) : data(data) {}
@ -34,12 +34,6 @@ std::optional<EnumItem> Enum::FromValue(int value) const {
return {}; return {};
} }
EnumItem Enum::FromValueInternal(int value) const {
auto result = this->FromValue(value);
if (!result) return EnumItem(data, "", value);
return result.value();
}
EnumItem::EnumItem(_EnumData* parentData, std::string name, int value) : parentData(parentData), name(name), value(value) {} EnumItem::EnumItem(_EnumData* parentData, std::string name, int value) : parentData(parentData), name(name), value(value) {}
// //

View file

@ -9,8 +9,8 @@
#include "lua.h" #include "lua.h"
struct _EnumData { struct _EnumData {
std::string name;
std::pair<int, std::string>* values; std::pair<int, std::string>* values;
std::string name;
int count; int count;
}; };
@ -28,8 +28,6 @@ public:
std::optional<EnumItem> FromName(std::string) const; std::optional<EnumItem> FromName(std::string) const;
std::optional<EnumItem> FromValue(int) const; std::optional<EnumItem> FromValue(int) const;
EnumItem FromValueInternal(int) const;
std::string ToString() const; std::string ToString() const;
void PushLuaValue(lua_State*) const; void PushLuaValue(lua_State*) const;
static result<Variant, LuaCastError> FromLuaValue(lua_State*, int); static result<Variant, LuaCastError> FromLuaValue(lua_State*, int);

View file

@ -10,7 +10,7 @@
#include "objects/base/member.h" #include "objects/base/member.h"
#include <pugixml.hpp> #include <pugixml.hpp>
TypeMeta::TypeMeta(const InstanceType* instType) : instType(instType), descriptor(&InstanceRef::TYPE) {} TypeMeta::TypeMeta(InstanceType* instType) : instType(instType), descriptor(&InstanceRef::TYPE) {}
InstanceRef::InstanceRef() {}; InstanceRef::InstanceRef() {};
InstanceRef::InstanceRef(std::weak_ptr<Instance> instance) : ref(instance) {}; InstanceRef::InstanceRef(std::weak_ptr<Instance> instance) : ref(instance) {};

View file

@ -1,13 +0,0 @@
#pragma once
// Markers for the autogen engine to generate getters, setters, lua, etc.
// Base macros
#ifdef __AUTOGEN__
#define def_enum(...) clang::annotate("OB::def_enum", #__VA_ARGS__)
#else
#define def_enum(...)
#endif
// Helper macros
#define DEF_ENUM [[ def_enum() ]]

View file

@ -1,3 +0,0 @@
#pragma once
#include "surface.h"

View file

@ -1,33 +0,0 @@
#pragma once
#include "datatypes/enum.h"
#include "enum/annotation.h"
enum DEF_ENUM NormalId {
Right = 0,
Top = 1,
Back = 2,
Left = 3,
Bottom = 4,
Front = 5
};
enum class DEF_ENUM SurfaceType {
Smooth = 0,
Glue = 1,
Weld = 2,
Studs = 3,
Inlet = 4,
Universal = 5,
Hinge = 6,
Motor = 7,
};
namespace EnumType {
extern const Enum NormalId;
extern const Enum SurfaceType;
};
class Vector3;
NormalId faceFromNormal(Vector3);
Vector3 normalFromFace(NormalId);

View file

@ -13,7 +13,7 @@
#include "objects/joint/jointinstance.h" #include "objects/joint/jointinstance.h"
#include "objects/joint/snap.h" #include "objects/joint/snap.h"
#include "rendering/renderer.h" #include "rendering/renderer.h"
#include "enum/surface.h" #include "rendering/surface.h"
#include <cstdio> #include <cstdio>
#include <glm/common.hpp> #include <glm/common.hpp>
#include <memory> #include <memory>
@ -120,7 +120,7 @@ SurfaceType Part::surfaceFromFace(NormalId face) {
case Front: return frontSurface; case Front: return frontSurface;
case Back: return backSurface; case Back: return backSurface;
} }
return SurfaceType::Smooth; // Unreachable return SurfaceSmooth; // Unreachable
} }
float Part::GetSurfaceParamA(Vector3 face) { float Part::GetSurfaceParamA(Vector3 face) {
@ -199,14 +199,14 @@ bool Part::checkSurfacesTouching(CFrame surfaceFrame, Vector3 size, Vector3 myFa
} }
std::optional<std::shared_ptr<JointInstance>> makeJointFromSurfaces(SurfaceType a, SurfaceType b) { std::optional<std::shared_ptr<JointInstance>> makeJointFromSurfaces(SurfaceType a, SurfaceType b) {
if (a == SurfaceType::Weld || b == SurfaceType::Weld || a == SurfaceType::Glue || b == SurfaceType::Glue) return Weld::New(); if (a == SurfaceWeld || b == SurfaceWeld || a == SurfaceGlue || b == SurfaceGlue) return Weld::New();
if ((a == SurfaceType::Studs && (b == SurfaceType::Inlet || b == SurfaceType::Universal)) if ((a == SurfaceStuds && (b == SurfaceInlets || b == SurfaceUniversal))
|| (a == SurfaceType::Inlet && (b == SurfaceType::Studs || b == SurfaceType::Universal)) || (a == SurfaceInlets && (b == SurfaceStuds || b == SurfaceUniversal))
|| (a == SurfaceType::Universal && (b == SurfaceType::Studs || b == SurfaceType::Inlet || b == SurfaceType::Universal))) || (a == SurfaceUniversal && (b == SurfaceStuds || b == SurfaceInlets || b == SurfaceUniversal)))
return Snap::New(); return Snap::New();
if (a == SurfaceType::Hinge) if (a == SurfaceHinge)
return Rotate::New(); return Rotate::New();
if (a == SurfaceType::Motor) if (a == SurfaceMotor)
return RotateV::New(); return RotateV::New();
return std::nullopt; return std::nullopt;
} }
@ -251,7 +251,7 @@ void Part::MakeJoints() {
SurfaceType otherSurface = surfaceFromFace(faceFromNormal(otherFace)); SurfaceType otherSurface = surfaceFromFace(faceFromNormal(otherFace));
// If it is a hinge, only attach if actually touching the "hinge" // If it is a hinge, only attach if actually touching the "hinge"
if ((mySurface == SurfaceType::Hinge || mySurface == SurfaceType::Motor) && !checkSurfacesTouching(surfaceFrame, Vector3(0.4, 0.4, 0.4), myFace, otherFace, otherPart)) continue; if ((mySurface == SurfaceHinge || mySurface == SurfaceMotor) && !checkSurfacesTouching(surfaceFrame, Vector3(0.4, 0.4, 0.4), myFace, otherFace, otherPart)) continue;
// Create contacts // Create contacts
// Contact always occurs at the center of Part0's surface (even if that point does not overlap both surfaces) // Contact always occurs at the center of Part0's surface (even if that point does not overlap both surfaces)

View file

@ -8,7 +8,7 @@
#include "datatypes/signal.h" #include "datatypes/signal.h"
#include "datatypes/vector.h" #include "datatypes/vector.h"
#include "objects/base/instance.h" #include "objects/base/instance.h"
#include "enum/surface.h" #include "rendering/surface.h"
#include <optional> #include <optional>
#include <reactphysics3d/reactphysics3d.h> #include <reactphysics3d/reactphysics3d.h>
#include <vector> #include <vector>
@ -70,12 +70,12 @@ public:
DEF_PROP bool locked = false; DEF_PROP bool locked = false;
DEF_PROP_CATEGORY(SURFACE) DEF_PROP_CATEGORY(SURFACE)
DEF_PROP SurfaceType topSurface = SurfaceType::Studs; DEF_PROP SurfaceType topSurface = SurfaceType::SurfaceStuds;
DEF_PROP SurfaceType bottomSurface = SurfaceType::Inlet; DEF_PROP SurfaceType bottomSurface = SurfaceType::SurfaceInlets;
DEF_PROP SurfaceType leftSurface = SurfaceType::Smooth; DEF_PROP SurfaceType leftSurface = SurfaceType::SurfaceSmooth;
DEF_PROP SurfaceType rightSurface = SurfaceType::Smooth; DEF_PROP SurfaceType rightSurface = SurfaceType::SurfaceSmooth;
DEF_PROP SurfaceType frontSurface = SurfaceType::Smooth; DEF_PROP SurfaceType frontSurface = SurfaceType::SurfaceSmooth;
DEF_PROP SurfaceType backSurface = SurfaceType::Smooth; DEF_PROP SurfaceType backSurface = SurfaceType::SurfaceSmooth;
DEF_PROP_CATEGORY(SURFACE_INPUT) DEF_PROP_CATEGORY(SURFACE_INPUT)
DEF_PROP float topParamA = -0.5; DEF_PROP float topParamA = -0.5;

View file

@ -28,7 +28,7 @@
#include "../common.h" #include "../common.h"
#include "../objects/part.h" #include "../objects/part.h"
#include "skybox.h" #include "skybox.h"
#include "enum/surface.h" #include "surface.h"
#include "texture3d.h" #include "texture3d.h"
#include "renderer.h" #include "renderer.h"
@ -154,12 +154,12 @@ void renderParts() {
shader->set("texScale", part->size); shader->set("texScale", part->size);
shader->set("transparency", part->transparency); shader->set("transparency", part->transparency);
shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", (int)part->rightSurface); shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", part->rightSurface);
shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", (int)part->topSurface); shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", part->topSurface);
shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", (int)part->backSurface); shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", part->backSurface);
shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", (int)part->leftSurface); shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", part->leftSurface);
shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", (int)part->bottomSurface); shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", part->bottomSurface);
shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", (int)part->frontSurface); shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", part->frontSurface);
CUBE_MESH->bind(); CUBE_MESH->bind();
glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount); glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount);
@ -184,12 +184,12 @@ void renderParts() {
shader->set("texScale", part->size); shader->set("texScale", part->size);
shader->set("transparency", part->transparency); shader->set("transparency", part->transparency);
shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", (int)part->rightSurface); shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", part->rightSurface);
shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", (int)part->topSurface); shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", part->topSurface);
shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", (int)part->backSurface); shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", part->backSurface);
shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", (int)part->leftSurface); shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", part->leftSurface);
shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", (int)part->bottomSurface); shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", part->bottomSurface);
shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", (int)part->frontSurface); shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", part->frontSurface);
CUBE_MESH->bind(); CUBE_MESH->bind();
glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount); glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount);
@ -233,7 +233,7 @@ void renderSurfaceExtras() {
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
NormalId face = (NormalId)i; NormalId face = (NormalId)i;
SurfaceType type = part->GetSurfaceFromFace(face); SurfaceType type = part->GetSurfaceFromFace(face);
if (type <= SurfaceType::Universal) continue; if (type <= SurfaceType::SurfaceUniversal) continue;
Vector3 surfaceCenter = part->cframe * (normalFromFace(face) * part->size / 2.f); Vector3 surfaceCenter = part->cframe * (normalFromFace(face) * part->size / 2.f);

View file

@ -0,0 +1,25 @@
#pragma once
enum NormalId {
Right = 0,
Top = 1,
Back = 2,
Left = 3,
Bottom = 4,
Front = 5
};
enum SurfaceType {
SurfaceSmooth = 0,
SurfaceGlue = 1,
SurfaceWeld = 2,
SurfaceStuds = 3,
SurfaceInlets = 4,
SurfaceUniversal = 5,
SurfaceHinge = 6,
SurfaceMotor = 7,
};
class Vector3;
NormalId faceFromNormal(Vector3);
Vector3 normalFromFace(NormalId);

View file

@ -387,9 +387,9 @@ void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
// raycast part // raycast part
std::optional<const RaycastResult> rayHit = gWorkspace()->CastRayNearest(camera.cameraPos, pointDir, 50000); std::optional<const RaycastResult> rayHit = gWorkspace()->CastRayNearest(camera.cameraPos, pointDir, 50000);
if (!rayHit || !partFromBody(rayHit->body)) { setSelection({}); return; } if (!rayHit || !partFromBody(rayHit->body)) return;
std::shared_ptr<Part> part = partFromBody(rayHit->body); std::shared_ptr<Part> part = partFromBody(rayHit->body);
if (part->locked) { setSelection({}); return; } if (part->locked) return;
initialFrame = part->cframe; initialFrame = part->cframe;
initialHitPos = rayHit->worldPoint; initialHitPos = rayHit->worldPoint;
initialHitNormal = rayHit->worldNormal; initialHitNormal = rayHit->worldNormal;

View file

@ -7,14 +7,12 @@
#include "objects/base/member.h" #include "objects/base/member.h"
#include <QColorDialog> #include <QColorDialog>
#include <QComboBox>
#include <QLineEdit> #include <QLineEdit>
#include <QSpinBox> #include <QSpinBox>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QPainter> #include <QPainter>
#include <QTime> #include <QTime>
#include <functional> #include <functional>
#include <qcombobox.h>
#include <qnamespace.h> #include <qnamespace.h>
#include <qtreewidget.h> #include <qtreewidget.h>
@ -97,18 +95,6 @@ public:
colorDialog->setCurrentColor(QColor::fromRgbF(color.R(), color.G(), color.B())); colorDialog->setCurrentColor(QColor::fromRgbF(color.R(), color.G(), color.B()));
return colorDialog; return colorDialog;
} else if (meta.type.descriptor == &EnumItem::TYPE) {
QComboBox* comboBox = new QComboBox(parent);
EnumItem enumItem = currentValue.get<EnumItem>();
std::vector<EnumItem> siblingItems = meta.type.enum_->GetEnumItems();
for (int i = 0; i < siblingItems.size(); i++) {
comboBox->addItem(QString::fromStdString(siblingItems[i].Name()));
if (siblingItems[i].Value() == enumItem.Value())
comboBox->setCurrentIndex(i);
}
return comboBox;
} else if (meta.type.descriptor->fromString) { } else if (meta.type.descriptor->fromString) {
QLineEdit* lineEdit = new QLineEdit(parent); QLineEdit* lineEdit = new QLineEdit(parent);
lineEdit->setText(QString::fromStdString(currentValue.ToString())); lineEdit->setText(QString::fromStdString(currentValue.ToString()));
@ -164,15 +150,6 @@ public:
Color3 color = currentValue.get<Color3>(); Color3 color = currentValue.get<Color3>();
colorDialog->setCurrentColor(QColor::fromRgbF(color.R(), color.G(), color.B())); colorDialog->setCurrentColor(QColor::fromRgbF(color.R(), color.G(), color.B()));
} else if (meta.type.descriptor == &EnumItem::TYPE) {
QComboBox* comboBox = dynamic_cast<QComboBox*>(editor);
EnumItem enumItem = currentValue.get<EnumItem>();
std::vector<EnumItem> siblingItems = meta.type.enum_->GetEnumItems();
for (int i = 0; i < siblingItems.size(); i++) {
if (siblingItems[i].Value() == enumItem.Value())
comboBox->setCurrentIndex(i);
}
} else if (meta.type.descriptor->fromString) { } else if (meta.type.descriptor->fromString) {
QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(editor); QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(editor);
@ -234,13 +211,6 @@ public:
inst->SetPropertyValue(propertyName, color3).expect(); inst->SetPropertyValue(propertyName, color3).expect();
model->setData(index, QString::fromStdString(color3.ToString()), Qt::DisplayRole); model->setData(index, QString::fromStdString(color3.ToString()), Qt::DisplayRole);
model->setData(index, color, Qt::DecorationRole); model->setData(index, color, Qt::DecorationRole);
} else if (meta.type.descriptor == &EnumItem::TYPE) {
QComboBox* comboBox = dynamic_cast<QComboBox*>(editor);
std::vector<EnumItem> siblingItems = meta.type.enum_->GetEnumItems();
EnumItem newItem = siblingItems[comboBox->currentIndex()];
inst->SetPropertyValue(propertyName, newItem).expect("Failed to set enum value in properties pane");
model->setData(index, QString::fromStdString(newItem.Name()), Qt::DisplayRole);
} else if (meta.type.descriptor->fromString) { } else if (meta.type.descriptor->fromString) {
QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(editor); QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(editor);
@ -349,9 +319,7 @@ void PropertiesView::setSelected(std::optional<std::shared_ptr<Instance>> instan
// } else if (meta.type.descriptor == &CFrame::TYPE) { // } else if (meta.type.descriptor == &CFrame::TYPE) {
// Vector3 vector = currentValue.get<CFrame>().Position(); // Vector3 vector = currentValue.get<CFrame>().Position();
// item->setData(1, Qt::DisplayRole, QString::fromStdString(currentValue.ToString())); // item->setData(1, Qt::DisplayRole, QString::fromStdString(currentValue.ToString()));
} else if (meta.type.descriptor == &EnumItem::TYPE) { } else {
item->setData(1, Qt::DisplayRole, QString::fromStdString(currentValue.get<EnumItem>().Name()));
} else {
item->setData(1, Qt::DisplayRole, QString::fromStdString(currentValue.ToString())); item->setData(1, Qt::DisplayRole, QString::fromStdString(currentValue.ToString()));
} }

View file

@ -5,7 +5,7 @@
#include "objects/joint/snap.h" #include "objects/joint/snap.h"
#include "objects/script.h" #include "objects/script.h"
#include "objects/script/scriptcontext.h" #include "objects/script/scriptcontext.h"
#include "enum/surface.h" #include "rendering/surface.h"
#include <cstdio> #include <cstdio>
#include <memory> #include <memory>
#include <qboxlayout.h> #include <qboxlayout.h>
@ -131,7 +131,7 @@ void PlaceDocument::init() {
// part1->frontSurface = SurfaceWeld; // part1->frontSurface = SurfaceWeld;
// part0->backSurface = SurfaceHinge; // part0->backSurface = SurfaceHinge;
part0->backSurface = SurfaceType::Motor; part0->backSurface = SurfaceMotor;
// part1->frontSurface = SurfaceHinge; // part1->frontSurface = SurfaceHinge;
std::shared_ptr<Script> script = Script::New(); std::shared_ptr<Script> script = Script::New();