Skip to content

Commit

Permalink
WIP JointsService
Browse files Browse the repository at this point in the history
  • Loading branch information
floralrainfall committed Jul 22, 2023
1 parent 1eeaad9 commit 2f34afd
Show file tree
Hide file tree
Showing 18 changed files with 342 additions and 40 deletions.
7 changes: 7 additions & 0 deletions Content/RNR/materials/InstancedMaterial.material
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
vertex_program InstancedMaterial/VertexProgram glsl
{
source shaders/InstancedShaer_f.glsl
syntax glsl330

}

// generated by blender2ogre 0.8.3 on 2023-07-20 04:32:47
material InstancedMaterial {
receive_shadows on
Expand Down
3 changes: 1 addition & 2 deletions Content/RNR/materials/partinstanced.material
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ material materials/PartInstanced

technique
{
shadow_caster_material materials/PartInstanced/shadow_caster

pass
{
specular 1 1 1 1 12.5
specular 1 1 1 1 64.5
lighting on

texture_unit
Expand Down
Empty file.
25 changes: 3 additions & 22 deletions Content/RNR/meshes/Cube.scene
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- exporter: blender2ogre 0.8.3 -->
<!-- export_time: Thu, 20 Jul 2023 08:20:08 +0000 -->
<!-- previous_export_time: Mon, 17 Jul 2023 06:58:22 +0000 -->
<!-- export_time: Sat, 22 Jul 2023 02:01:11 +0000 -->
<!-- previous_export_time: Thu, 20 Jul 2023 08:20:08 +0000 -->
<scene author="caesium" formatVersion="1.1" >
<nodes >
<node name="Cube" >
Expand All @@ -13,26 +13,7 @@
</entity>
</node>
</nodes>
<externals >
<item type="material" >
<file name="TopMaterial.material" />
</item>
<item type="material" >
<file name="BackMaterial.material" />
</item>
<item type="material" >
<file name="BottomMaterial.material" />
</item>
<item type="material" >
<file name="FrontMaterial.material" />
</item>
<item type="material" >
<file name="LeftMaterial.material" />
</item>
<item type="material" >
<file name="RightMaterial.material" />
</item>
</externals>
<externals />
<environment >
<colourBackground b="0.050876" g="0.050876" r="0.050876" />
</environment>
Expand Down
Binary file modified Content/RNR/textures/studio/icons/PointLight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/RNR/textures/studio/icons/Weld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Projects/Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ add_library(Engine STATIC
Header/App/V8/Tree/ModelInstance.hpp
Header/App/V8/World/World.hpp
Header/App/V8/World/Weld.hpp
Header/App/V8/World/JointsService.hpp
Header/App/V8/World/ComPlicitNgine.hpp
Header/App/CoordinateFrame.hpp
Header/App/BrickColor.hpp
Expand Down Expand Up @@ -67,6 +68,7 @@ add_library(Engine STATIC
Source/App/InputManager.cpp
Source/App/V8/World/World.cpp
Source/App/V8/World/Weld.cpp
Source/App/V8/World/JointsService.cpp
Source/App/V8/World/ComPlicitNgine.cpp
Source/Network/GUID.cpp
Source/Network/Player.cpp
Expand Down
39 changes: 38 additions & 1 deletion Projects/Engine/Header/App/V8/DataModel/PartInstance.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
#pragma once
#include <App/V8/Tree/PVInstance.hpp>
#include <App/BrickColor.hpp>
#include <Helpers/NormalId.hpp>
#include <OGRE/Ogre.h>

#define STUD_HEIGHT 1.18

namespace RNR
{
enum PartSurfaceType
{
SURFACE_SMOOTH,
SURFACE_GLUE,
SURFACE_WELD,
SURFACE_STUDS,
SURFACE_INLET,
SURFACE_UNIVERSAL,
SURFACE_HINGE,
SURFACE_MOTOR,
SURFACE_STEPPINGMOTOR,
SURFACE_UNJOINABLE,
__SURFACE_COUNT,
};

struct PartSurfaceInfo
{
public:
NormalId face;
PartSurfaceType type;

Ogre::Vector2 start;
Ogre::Vector2 end;
float plane;

bool intersects(PartSurfaceInfo other);
bool links(PartSurfaceInfo other);
};

class PartInstance : public PVInstance
{
protected:
int m_brickColor;
float m_transparency;
float m_reflectance;
bool m_anchored;
PartSurfaceInfo m_surfaces[__NORM_COUNT];
Ogre::Matrix4 m_matrix;
Ogre::Vector3 m_position;
Ogre::Vector3 m_size;
Expand All @@ -25,9 +56,11 @@ namespace RNR
PartInstance();

void updateMatrix();
PartSurfaceInfo& getSurface(NormalId normal) { return m_surfaces[normal]; };
void setSurface(NormalId normal, PartSurfaceInfo surface) { m_surfaces[normal] = surface; }

virtual std::string getClassName() { return "Part"; }
void setSize(Ogre::Vector3 size) { m_size = size; }
void setSize(Ogre::Vector3 size) { m_size = size; updateSurfaces(); }
Ogre::Vector3 getSize() { return m_size; }
Ogre::Vector4 getColor() { return m_color; }

Expand All @@ -38,6 +71,10 @@ namespace RNR
void setAnchored(bool anchored) { m_anchored = anchored; }
bool getAnchored() { return m_anchored; }

void makeJoints();
void breakJoints();
void updateSurfaces();

Ogre::Vector3 getOgreCenter() { return m_position + (m_size / 2.f); }

void setBrickColor(int brickcolor) { m_brickColor = brickcolor; }
Expand Down
2 changes: 1 addition & 1 deletion Projects/Engine/Header/App/V8/DataModel/RunService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace RNR
virtual void addProperties(std::vector<ReflectionProperty>& properties);
public:
RunService();

virtual std::string getClassName() { return "RunService"; }

bool getRunning() { return m_running; }
Expand Down
1 change: 1 addition & 0 deletions Projects/Engine/Header/App/V8/DataModel/Workspace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace RNR
virtual void onDescendantRemoved(RNR::Instance* childRemoved);

void buildGeom();
void makeJoints();

Camera* getCurrentCamera() const;
void setCurrentCamera(Camera *value);
Expand Down
23 changes: 23 additions & 0 deletions Projects/Engine/Header/App/V8/World/JointsService.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include <App/V8/Tree/Instance.hpp>
#include <App/V8/DataModel/PartInstance.hpp>
#include <App/V8/World/Weld.hpp>

namespace RNR
{
class JointsService : public Instance
{
public:
JointsService();
virtual std::string getClassName() { return "JointsService"; }
Snap* snap(PartInstance* a, PartInstance* b);

void makeJoints(Instance* w, PartInstance* p);
void makeJoints(PartInstance* p);

void fixWelds();

void breakJoints(PartInstance* b);
bool isWelded(PartInstance* a, PartInstance* b);
};
}
15 changes: 14 additions & 1 deletion Projects/Engine/Header/App/V8/World/Weld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,28 @@ namespace RNR
PartInstance* m_bInstance;

btFixedConstraint* m_constraint;

virtual void addProperties(std::vector<ReflectionProperty>& properties);
virtual void deserializeProperty(char* prop_name, pugi::xml_node prop);
public:
Weld();
~Weld();
virtual std::string getClassName() { return "Weld"; }

void weld(PartInstance* a, PartInstance* b);
void create();
bool create();
void destroy();

bool getBroken();
PartInstance* getPartA() { return m_aInstance; }
PartInstance* getPartB() { return m_bInstance; }
};

class Snap : public Weld
{
// they're basically the same
public:
virtual std::string getClassName() { return "Snap"; }
virtual std::string getExplorerIcon() { return "Weld"; }
};
}
15 changes: 8 additions & 7 deletions Projects/Engine/Header/Helpers/NormalId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
namespace RNR {
enum NormalId
{
NORM_X,
NORM_Y,
NORM_Z,
NORM_X_NEG,
NORM_Y_NEG,
NORM_Z_NEG,
NORM_UNDEFINED
NORM_X, NORM_RIGHT = NORM_X,
NORM_Y, NORM_UP = NORM_Y,
NORM_Z, NORM_BACK = NORM_Z,
NORM_X_NEG, NORM_LEFT = NORM_X_NEG,
NORM_Y_NEG, NORM_DOWN = NORM_Y_NEG,
NORM_Z_NEG, NORM_FRONT = NORM_Z_NEG,
__NORM_COUNT,
NORM_UNDEFINED,
};

bool validNormalId(NormalId normalId);
Expand Down
92 changes: 92 additions & 0 deletions Projects/Engine/Source/App/V8/DataModel/PartInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@

namespace RNR
{
bool PartSurfaceInfo::intersects(PartSurfaceInfo other)
{
if(other.plane != plane)
return false;
if(start.x > other.end.x || other.start.x > end.x)
return false;
if(end.y > other.start.y || other.end.y > start.y)
return false;
return true;
}

bool PartSurfaceInfo::links(PartSurfaceInfo other)
{
bool allowed_surf[__SURFACE_COUNT][__SURFACE_COUNT] = {
// SMOOTH, GLUE, WELD, STUDS, INLET, UNIVERSAL, HINGE, MOTOR, STEPPINGMOTOR, UNJOINABLE
{ false, false, false, false, false, false, false, false, false, false }, // SMOOTH
{ true, true, true, true, true, true, false, false, false, false }, // GLUE
{ true, true, true, true, true, true, false, false, false, false }, // WELD
{ false, false, false, false, true, true, false, false, false, false }, // STUDS
{ false, false, false, true, false, true, false, false, false, false }, // INLET
{ false, false, true, true, true, true, false, false, false, false }, // UNIVERSAL
{ true, true, true, true, true, true, false, false, false, false }, // HINGE
{ true, true, true, true, true, true, false, false, false, false }, // MOTOR
{ true, true, true, true, true, true, false, false, false, false }, // STEPPINGMOTOR
{ false, false, false, false, false, false, false, false, false, false }, // UNJOINABLE
};

return allowed_surf[type][other.type];
}

PartInstance::PartInstance() : m_matrix(), PVInstance(), m_size(2.f, STUD_HEIGHT, 4.f)
{
setName("Part");
Expand All @@ -16,6 +46,23 @@ namespace RNR
setObject(world->getOgreSceneManager()->createEntity("meshes/Cube.mesh"));
getNode()->attachObject(getObject());

for(int i = 0; i < __NORM_COUNT; i++)
{
NormalId n = (NormalId)i;
switch(n)
{
case NORM_UP:
m_surfaces[i].type = SURFACE_STUDS;
break;
case NORM_DOWN:
m_surfaces[i].type = SURFACE_INLET;
break;
default:
m_surfaces[i].type = SURFACE_SMOOTH;
break;
}
}

updateMatrix();
}

Expand Down Expand Up @@ -52,6 +99,51 @@ namespace RNR
entity->setCastShadows(true);
}

void PartInstance::updateSurfaces()
{
for(int i = 0; i < __NORM_COUNT; i++)
{
m_surfaces[i].face = (NormalId)i;
PartSurfaceInfo& surf = m_surfaces[i];
Ogre::Vector3 size = ((getSize() / 2.f) * getRotation());
Ogre::Vector3 pos = getPosition();
switch(m_surfaces[i].face)
{
case NORM_DOWN:
surf.start = Ogre::Vector2(pos.x-size.x,pos.z-size.z);
surf.end = Ogre::Vector2(pos.x+size.x,pos.z+size.z);
surf.plane = pos.y - size.y;
break;
case NORM_UP:
surf.start = Ogre::Vector2(pos.x-size.x,pos.z-size.z);
surf.end = Ogre::Vector2(pos.x+size.x,pos.z+size.z);
surf.plane = pos.y + size.y;
break;
case NORM_LEFT:
surf.start = Ogre::Vector2(pos.z-size.z,pos.y-size.y);
surf.end = Ogre::Vector2(pos.z+size.z,pos.y+size.y);
surf.plane = pos.z - size.z;
break;
case NORM_RIGHT:
surf.start = Ogre::Vector2(pos.z-size.z,pos.y-size.y);
surf.end = Ogre::Vector2(pos.z+size.z,pos.y+size.y);
surf.plane = pos.z + size.z;
break;
case NORM_FRONT:
surf.start = Ogre::Vector2(pos.z-size.z,pos.y-size.y);
surf.end = Ogre::Vector2(pos.z+size.z,pos.y+size.y);
surf.plane = pos.x + size.x;
break;
case NORM_BACK:
surf.start = Ogre::Vector2(pos.z-size.z,pos.y-size.y);
surf.end = Ogre::Vector2(pos.z+size.z,pos.y+size.y);
surf.plane = pos.x - size.x;
break;
}
}

}

void PartInstance::deserializeProperty(char* prop_name, pugi::xml_node node)
{
if(prop_name == std::string("size"))
Expand Down
3 changes: 3 additions & 0 deletions Projects/Engine/Source/App/V8/DataModel/Workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace RNR
{
case BATCH_INSTANCED:
m_instanceManager = world->getOgreSceneManager()->createInstanceManager("workspaceInstanceManager", "meshes/Cube_Instanced.mesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::InstanceManager::InstancingTechnique::HWInstancingBasic, 255);
m_instanceManager->setNumCustomParams(2);
break;
case BATCH_STATIC_GEOMETRY:
m_geom = world->getOgreSceneManager()->createStaticGeometry("workspaceGeom");
Expand Down Expand Up @@ -43,6 +44,7 @@ namespace RNR
replica->setOrientation(part->getCFrame().getRotation());
replica->setScale(part->getSize());
replica->setCastShadows(true);
replica->setCustomParam(0, Ogre::Vector4f(part->getSize().x, part->getSize().y, part->getSize().z, 0));
m_worldspawn->attachObject(replica);
childAdded->setObject(replica);
child_node->setVisible(false);
Expand All @@ -56,6 +58,7 @@ namespace RNR
child_node->setVisible(false);
m_geomDirty = true;
break;
default:
case BATCH_DONT:
child_node->setVisible(true);
break;
Expand Down
Loading

0 comments on commit 2f34afd

Please sign in to comment.