New object property which allows changing the color and alpha of mesh materials. Due to the current lighting systems it doesn't work yet, but the full implementation is there
Framework for the attachment system, with no actual functionality yet
Send bone and player object to the setAttachment function in content_sao.cpp, but we need a way to translate it there and send it to the client
I will also want position and rotation offsets to be possible to apply to attachments
Network object ID from server to client. This will be used to identify the parent client-side and know what to attach to
visual = "cube"/"sprite"/"upright_sprite"/"mesh",
visual_size = {x=1, y=1},
mesh = "model",
- animation_bone_position = {"", {x=0, y=0, z=0}}, -- bone name followed by position vector
- animation_bone_rotation = {"", {x=0, y=0, z=0}}, -- bone name followed by rotation vector
textures = {}, -- number of required textures depends on visual
+ colors = {}, -- number of required colors depends on visual
spritediv = {x=1, y=1},
initial_sprite_basepos = {x=0, y=0},
is_visible = true,
std::string m_name;
bool m_is_player;
bool m_is_local_player; // determined locally
+ int m_id;
// Property-ish things
ObjectProperties m_prop;
//
//
m_is_player(false),
m_is_local_player(false),
+ m_id(0),
//
m_smgr(NULL),
m_irr(NULL),
}
m_name = deSerializeString(is);
m_is_player = readU8(is);
+ m_id = readS16(is);
m_position = readV3F1000(is);
m_yaw = readF1000(is);
m_hp = readS16(is);
addToScene(m_smgr, m_gamedef->tsrc(), m_irr);
updateAnimations();
updateBonePosRot();
+ updateAttachment();
}
if(m_prop.physical){
texturestring += mod;
m_spritenode->setMaterialTexture(0,
tsrc->getTextureRaw(texturestring));
+
+ // Does not work yet with the current lighting settings
+ m_meshnode->getMaterial(0).AmbientColor = m_prop.colors[0];
+ m_meshnode->getMaterial(0).DiffuseColor = m_prop.colors[0];
}
}
if(m_animated_meshnode)
material.setFlag(video::EMF_LIGHTING, false);
material.setFlag(video::EMF_BILINEAR_FILTER, false);
}
+ for (u32 i = 0; i < m_prop.colors.size(); ++i)
+ {
+ // Does not work yet with the current lighting settings
+ m_animated_meshnode->getMaterial(i).AmbientColor = m_prop.colors[i];
+ m_animated_meshnode->getMaterial(i).DiffuseColor = m_prop.colors[i];
+ }
}
}
if(m_meshnode)
material.setTexture(0, atlas);
material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
+
+ // Does not work yet with the current lighting settings
+ m_meshnode->getMaterial(i).AmbientColor = m_prop.colors[i];
+ m_meshnode->getMaterial(i).DiffuseColor = m_prop.colors[i];
}
}
else if(m_prop.visual == "upright_sprite")
scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
buf->getMaterial().setTexture(0,
tsrc->getTextureRaw(tname));
+
+ // Does not work yet with the current lighting settings
+ m_meshnode->getMaterial(0).AmbientColor = m_prop.colors[0];
+ m_meshnode->getMaterial(0).DiffuseColor = m_prop.colors[0];
}
{
std::string tname = "unknown_object.png";
scene::IMeshBuffer *buf = mesh->getMeshBuffer(1);
buf->getMaterial().setTexture(0,
tsrc->getTextureRaw(tname));
+
+ // Does not work yet with the current lighting settings
+ m_meshnode->getMaterial(1).AmbientColor = m_prop.colors[1];
+ m_meshnode->getMaterial(1).DiffuseColor = m_prop.colors[1];
}
}
}
}
}
+ void updateAttachment()
+ {
+ // Code for attachments goes here
+ }
+
void processMessage(const std::string &data)
{
//infostream<<"GenericCAO: Got message"<<std::endl;
updateBonePosRot();
expireVisuals();
}
+ else if(cmd == GENERIC_CMD_SET_ATTACHMENT)
+ {
+ // Part of the attachment structure, not used yet!
+
+ // Get properties here.
+
+ updateAttachment();
+ expireVisuals();
+ }
else if(cmd == GENERIC_CMD_PUNCHED)
{
/*s16 damage =*/ readS16(is);
std::ostringstream os(std::ios::binary);
writeU8(os, 0); // version
os<<serializeString(""); // name
+ writeS16(os, getId()); //id
writeU8(os, 0); // is_player
writeV3F1000(os, m_base_position);
writeF1000(os, m_yaw);
m_messages_out.push_back(aom);
}
+// Part of the attachment structure, not used yet!
+void LuaEntitySAO::setAttachment(ServerActiveObject *parent, std::string bone, v3f position, v3f rotation)
+{
+ // Parent should be translated from a ServerActiveObject into something
+ // the client will recognize (as a ClientActiveObject) then sent in
+ // gob_cmd_set_attachment that way.
+
+ std::string str = gob_cmd_set_attachment(); // <- parameters here
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), true, str);
+ m_messages_out.push_back(aom);
+}
+
ObjectProperties* LuaEntitySAO::accessObjectProperties()
{
return &m_prop;
m_prop.textures.clear();
m_prop.textures.push_back("player.png");
m_prop.textures.push_back("player_back.png");
+ m_prop.colors.clear();
+ m_prop.colors.push_back(video::SColor(255, 255, 255, 255));
m_prop.spritediv = v2s16(1,1);
// end of default appearance
m_prop.is_visible = (getHP() != 0); // TODO: Use a death animation instead for mesh players
writeU8(os, 0); // version
os<<serializeString(m_player->getName()); // name
writeU8(os, 1); // is_player
+ writeS16(os, getId()); //id
writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0));
writeF1000(os, m_player->getYaw());
writeS16(os, getHP());
m_messages_out.push_back(aom);
}
+// Part of the attachment structure, not used yet!
+void PlayerSAO::setAttachment(ServerActiveObject *parent, std::string bone, v3f position, v3f rotation)
+{
+ std::string str = gob_cmd_set_attachment(); // <- parameters here
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), true, str);
+ m_messages_out.push_back(aom);
+}
+
ObjectProperties* PlayerSAO::accessObjectProperties()
{
return &m_prop;
void setArmorGroups(const ItemGroupList &armor_groups);
void setAnimations(v2f frames, float frame_speed, float frame_blend);
void setBonePosRot(std::string bone, v3f position, v3f rotation);
+ void setAttachment(ServerActiveObject *parent, std::string bone, v3f position, v3f rotation);
ObjectProperties* accessObjectProperties();
void notifyObjectPropertiesModified();
/* LuaEntitySAO-specific */
void setArmorGroups(const ItemGroupList &armor_groups);
void setAnimations(v2f frames, float frame_speed, float frame_blend);
void setBonePosRot(std::string bone, v3f position, v3f rotation);
+ void setAttachment(ServerActiveObject *parent, std::string bone, v3f position, v3f rotation);
ObjectProperties* accessObjectProperties();
void notifyObjectPropertiesModified();
return os.str();
}
+// Part of the attachment structure, not used yet!
+std::string gob_cmd_set_attachment() // <- parameters here
+{
+ std::ostringstream os(std::ios::binary);
+ // command
+ writeU8(os, GENERIC_CMD_SET_ATTACHMENT);
+ // parameters
+ // Parameters go here
+ return os.str();
+}
+
std::string gob_cmd_set_bone_posrot(std::string bone, v3f position, v3f rotation)
{
std::ostringstream os(std::ios::binary);
#define GENERIC_CMD_SET_SPRITE 3
#define GENERIC_CMD_SET_ANIMATIONS 4
#define GENERIC_CMD_SET_BONE_POSROT 5
-#define GENERIC_CMD_PUNCHED 6
-#define GENERIC_CMD_UPDATE_ARMOR_GROUPS 7
+#define GENERIC_CMD_SET_ATTACHMENT 6
+#define GENERIC_CMD_PUNCHED 7
+#define GENERIC_CMD_UPDATE_ARMOR_GROUPS 8
#include "object_properties.h"
std::string gob_cmd_set_properties(const ObjectProperties &prop);
std::string gob_cmd_set_bone_posrot(std::string bone, v3f position, v3f rotation);
+std::string gob_cmd_set_attachment(); // <- parameters here
+
std::string gob_cmd_punched(s16 damage, s16 result_hp);
#include "itemgroup.h"
*/
#include "object_properties.h"
+#include "irrlichttypes_bloated.h"
#include "util/serialize.h"
#include <sstream>
#include <map>
automatic_rotate(0)
{
textures.push_back("unknown_object.png");
+ colors.push_back(video::SColor(255,255,255,255));
}
std::string ObjectProperties::dump()
os<<"\""<<textures[i]<<"\" ";
}
os<<"]";
+ os<<", colors=[";
+ for(u32 i=0; i<colors.size(); i++){
+ os<<"\""<<colors[i].getAlpha()<<","<<colors[i].getRed()<<","<<colors[i].getGreen()<<","<<colors[i].getBlue()<<"\" ";
+ }
+ os<<"]";
os<<", spritediv="<<PP2(spritediv);
os<<", initial_sprite_basepos="<<PP2(initial_sprite_basepos);
os<<", is_visible="<<is_visible;
for(u32 i=0; i<textures.size(); i++){
os<<serializeString(textures[i]);
}
+ writeU16(os, colors.size());
+ for(u32 i=0; i<colors.size(); i++){
+ writeARGB8(os, colors[i]);
+ }
writeV2S16(os, spritediv);
writeV2S16(os, initial_sprite_basepos);
writeU8(os, is_visible);
for(u32 i=0; i<texture_count; i++){
textures.push_back(deSerializeString(is));
}
+ u32 color_count = readU16(is);
+ for(u32 i=0; i<color_count; i++){
+ colors.push_back(readARGB8(is));
+ }
spritediv = readV2S16(is);
initial_sprite_basepos = readV2S16(is);
is_visible = readU8(is);
std::string mesh;
v2f visual_size;
core::array<std::string> textures;
+ core::array<video::SColor> colors;
v2s16 spritediv;
v2s16 initial_sprite_basepos;
bool is_visible;
}
}
lua_pop(L, 1);
+
+ lua_getfield(L, -1, "colors");
+ if(lua_istable(L, -1)){
+ prop->colors.clear();
+ int table = lua_gettop(L);
+ lua_pushnil(L);
+ while(lua_next(L, table) != 0){
+ // key at index -2 and value at index -1
+ if(lua_isstring(L, -1))
+ prop->colors.push_back(readARGB8(L, -1));
+ else
+ prop->colors.push_back(video::SColor(255, 255, 255, 255));
+ // removes value, keeps key for next iteration
+ lua_pop(L, 1);
+ }
+ }
+ lua_pop(L, 1);
lua_getfield(L, -1, "spritediv");
if(lua_istable(L, -1))
return 0;
}
+// Part of the attachment structure, not used yet!
+ // set_attachment() // <- parameters here
+ static int l_set_attachment(lua_State *L)
+ {
+ ObjectRef *ref = checkobject(L, 1);
+ ObjectRef *parent_ref = checkobject(L, 2);
+ ServerActiveObject *co = getobject(ref);
+ ServerActiveObject *parent = getobject(parent_ref);
+ if(co == NULL) return 0;
+ if(parent == NULL) return 0;
+ std::string bone = "";
+ if(!lua_isnil(L, 3))
+ bone = lua_tostring(L, 3);
+ v3f position = v3f(0, 0, 0);
+ if(!lua_isnil(L, 4))
+ position = read_v3f(L, 4);
+ v3f rotation = v3f(0, 0, 0);
+ if(!lua_isnil(L, 5))
+ rotation = read_v3f(L, 5);
+ // Do it
+
+//lua_pushnumber(L, cobj->getId()); // Push id
+
+ co->setAttachment(parent, bone, position, rotation);
+ return 0;
+ }
+
// set_properties(self, properties)
static int l_set_properties(lua_State *L)
{
method(ObjectRef, set_armor_groups),
method(ObjectRef, set_animations),
method(ObjectRef, set_bone_posrot),
+ method(ObjectRef, set_attachment),
method(ObjectRef, set_properties),
// LuaEntitySAO-only
method(ObjectRef, setvelocity),
{}
virtual void setBonePosRot(std::string bone, v3f position, v3f rotation)
{}
+ virtual void setAttachment(ServerActiveObject *parent, std::string bone, v3f position, v3f rotation)
+ {}
virtual ObjectProperties* accessObjectProperties()
{ return NULL; }
virtual void notifyObjectPropertiesModified()
#define UTIL_SERIALIZE_HEADER
#include "../irrlichttypes.h"
+#include "../irrlichttypes_bloated.h"
#include "../irr_v2d.h"
#include "../irr_v3d.h"
#include <iostream>
return p;
}
+inline void writeARGB8(u8 *data, video::SColor p)
+{
+ writeU8(&data[0], p.getAlpha());
+ writeU8(&data[1], p.getRed());
+ writeU8(&data[2], p.getGreen());
+ writeU8(&data[3], p.getBlue());
+}
+
+inline video::SColor readARGB8(u8 *data)
+{
+ video::SColor p;
+ p.setAlpha(readU8(&data[0]));
+ p.setRed(readU8(&data[1]));
+ p.setGreen(readU8(&data[2]));
+ p.setBlue(readU8(&data[3]));
+ return p;
+}
+
/*
The above stuff directly interfaced to iostream
*/
return readV3S16((u8*)buf);
}
+inline void writeARGB8(std::ostream &os, video::SColor p)
+{
+ char buf[4] = {0};
+ writeARGB8((u8*)buf, p);
+ os.write(buf, 4);
+}
+
+inline video::SColor readARGB8(std::istream &is)
+{
+ char buf[4] = {0};
+ is.read(buf, 4);
+ return readARGB8((u8*)buf);
+}
+
/*
More serialization stuff
*/