本文整理汇总了C++中ITextureSource类的典型用法代码示例。如果您正苦于以下问题:C++ ITextureSource类的具体用法?C++ ITextureSource怎么用?C++ ITextureSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ITextureSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: myrand_range
bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_ratio)
{
if(!m_has_animation)
{
m_animation_force_timer = 100000;
return false;
}
m_animation_force_timer = myrand_range(5, 100);
// Cracks
if(crack != m_last_crack)
{
for(std::map<u32, std::string>::iterator
i = m_crack_materials.begin();
i != m_crack_materials.end(); i++)
{
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i->first);
std::string basename = i->second;
// Create new texture name from original
ITextureSource *tsrc = m_gamedef->getTextureSource();
std::ostringstream os;
os<<basename<<crack;
AtlasPointer ap = tsrc->getTexture(os.str());
buf->getMaterial().setTexture(0, ap.atlas);
}
m_last_crack = crack;
}
// Day-night transition
if(daynight_ratio != m_last_daynight_ratio)
{
for(std::map<u32, std::map<u32, std::pair<u8, u8> > >::iterator
i = m_daynight_diffs.begin();
i != m_daynight_diffs.end(); i++)
{
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i->first);
video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
for(std::map<u32, std::pair<u8, u8 > >::iterator
j = i->second.begin();
j != i->second.end(); j++)
{
u32 vertexIndex = j->first;
u8 day = j->second.first;
u8 night = j->second.second;
finalColorBlend(vertices[vertexIndex].Color,
day, night, daynight_ratio);
}
}
m_last_daynight_ratio = daynight_ratio;
}
return true;
}
示例2: IGUIElement
GUIChatConsole::GUIChatConsole(
gui::IGUIEnvironment* env,
gui::IGUIElement* parent,
s32 id,
ChatBackend* backend,
Client* client,
IMenuManager* menumgr
):
IGUIElement(gui::EGUIET_ELEMENT, env, parent, id,
core::rect<s32>(0,0,100,100)),
m_chat_backend(backend),
m_client(client),
m_menumgr(menumgr),
m_animate_time_old(porting::getTimeMs())
{
// load background settings
s32 console_alpha = g_settings->getS32("console_alpha");
m_background_color.setAlpha(clamp_u8(console_alpha));
// load the background texture depending on settings
ITextureSource *tsrc = client->getTextureSource();
if (tsrc->isKnownSourceImage("background_chat.jpg")) {
m_background = tsrc->getTexture("background_chat.jpg");
m_background_color.setRed(255);
m_background_color.setGreen(255);
m_background_color.setBlue(255);
} else {
v3f console_color = g_settings->getV3F("console_color");
m_background_color.setRed(clamp_u8(myround(console_color.X)));
m_background_color.setGreen(clamp_u8(myround(console_color.Y)));
m_background_color.setBlue(clamp_u8(myround(console_color.Z)));
}
m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, FM_Mono);
if (!m_font) {
errorstream << "GUIChatConsole: Unable to load mono font ";
} else {
core::dimension2d<u32> dim = m_font->getDimension(L"M");
m_fontsize = v2u32(dim.Width, dim.Height);
m_font->grab();
}
m_fontsize.X = MYMAX(m_fontsize.X, 1);
m_fontsize.Y = MYMAX(m_fontsize.Y, 1);
// set default cursor options
setCursor(true, true, 2.0, 0.1);
}
示例3: createClientCachedDirect
ClientCached* createClientCachedDirect(const std::string &name,
Client *client) const
{
infostream<<"Lazily creating item texture and mesh for \""
<<name<<"\""<<std::endl;
// This is not thread-safe
sanity_check(std::this_thread::get_id() == m_main_thread);
// Skip if already in cache
ClientCached *cc = NULL;
m_clientcached.get(name, &cc);
if(cc)
return cc;
ITextureSource *tsrc = client->getTextureSource();
const ItemDefinition &def = get(name);
// Create new ClientCached
cc = new ClientCached();
// Create an inventory texture
cc->inventory_texture = NULL;
if (!def.inventory_image.empty())
cc->inventory_texture = tsrc->getTexture(def.inventory_image);
ItemStack item = ItemStack();
item.name = def.name;
getItemMesh(client, item, &(cc->wield_mesh));
cc->palette = tsrc->getPalette(def.palette_image);
// Put in cache
m_clientcached.set(name, cc);
return cc;
}
示例4: createClientCachedDirect
ClientCached* createClientCachedDirect(const std::string &name,
IGameDef *gamedef) const
{
infostream<<"Lazily creating item texture and mesh for \""
<<name<<"\""<<std::endl;
// This is not thread-safe
sanity_check(thr_is_current_thread(m_main_thread));
// Skip if already in cache
ClientCached *cc = NULL;
m_clientcached.get(name, &cc);
if(cc)
return cc;
ITextureSource *tsrc = gamedef->getTextureSource();
const ItemDefinition &def = get(name);
// Create new ClientCached
cc = new ClientCached();
// Create an inventory texture
cc->inventory_texture = NULL;
if(def.inventory_image != "")
cc->inventory_texture = tsrc->getTexture(def.inventory_image);
ItemStack item = ItemStack();
item.name = def.name;
scene::IMesh *mesh = getItemMesh(gamedef, item);
cc->wield_mesh = mesh;
// Put in cache
m_clientcached.set(name, cc);
return cc;
}
示例5: getItemMesh
void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
{
ITextureSource *tsrc = client->getTextureSource();
IItemDefManager *idef = client->getItemDefManager();
const NodeDefManager *ndef = client->getNodeDefManager();
const ItemDefinition &def = item.getDefinition(idef);
const ContentFeatures &f = ndef->get(def.name);
content_t id = ndef->getId(def.name);
FATAL_ERROR_IF(!g_extrusion_mesh_cache, "Extrusion mesh cache is not yet initialized");
scene::SMesh *mesh = nullptr;
// Shading is on by default
result->needs_shading = true;
// If inventory_image is defined, it overrides everything else
if (!def.inventory_image.empty()) {
mesh = getExtrudedMesh(tsrc, def.inventory_image,
def.inventory_overlay);
result->buffer_colors.emplace_back();
// overlay is white, if present
result->buffer_colors.emplace_back(true, video::SColor(0xFFFFFFFF));
// Items with inventory images do not need shading
result->needs_shading = false;
} else if (def.type == ITEM_NODE) {
if (f.mesh_ptr[0]) {
mesh = cloneMesh(f.mesh_ptr[0]);
scaleMesh(mesh, v3f(0.12, 0.12, 0.12));
postProcessNodeMesh(mesh, f, false, false, nullptr,
&result->buffer_colors);
} else {
switch (f.drawtype) {
case NDT_PLANTLIKE: {
mesh = getExtrudedMesh(tsrc,
tsrc->getTextureName(f.tiles[0].layers[0].texture_id),
tsrc->getTextureName(f.tiles[0].layers[1].texture_id));
// Add color
const TileLayer &l0 = f.tiles[0].layers[0];
result->buffer_colors.emplace_back(l0.has_color, l0.color);
const TileLayer &l1 = f.tiles[0].layers[1];
result->buffer_colors.emplace_back(l1.has_color, l1.color);
break;
}
case NDT_PLANTLIKE_ROOTED: {
mesh = getExtrudedMesh(tsrc,
tsrc->getTextureName(f.special_tiles[0].layers[0].texture_id), "");
// Add color
const TileLayer &l0 = f.special_tiles[0].layers[0];
result->buffer_colors.emplace_back(l0.has_color, l0.color);
break;
}
case NDT_NORMAL:
case NDT_ALLFACES:
case NDT_LIQUID:
case NDT_FLOWINGLIQUID: {
scene::IMesh *cube = g_extrusion_mesh_cache->createCube();
mesh = cloneMesh(cube);
cube->drop();
scaleMesh(mesh, v3f(1.2, 1.2, 1.2));
// add overlays
postProcessNodeMesh(mesh, f, false, false, nullptr,
&result->buffer_colors);
break;
}
default: {
mesh = createSpecialNodeMesh(client, id, &result->buffer_colors);
scaleMesh(mesh, v3f(0.12, 0.12, 0.12));
}
}
}
u32 mc = mesh->getMeshBufferCount();
for (u32 i = 0; i < mc; ++i) {
scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
video::SMaterial &material = buf->getMaterial();
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
material.setFlag(video::EMF_BILINEAR_FILTER, false);
material.setFlag(video::EMF_TRILINEAR_FILTER, false);
material.setFlag(video::EMF_BACK_FACE_CULLING, true);
material.setFlag(video::EMF_LIGHTING, false);
}
rotateMeshXZby(mesh, -45);
rotateMeshYZby(mesh, -30);
}
result->mesh = mesh;
}
示例6: setItem
void WieldMeshSceneNode::setItem(const ItemStack &item, Client *client)
{
ITextureSource *tsrc = client->getTextureSource();
IItemDefManager *idef = client->getItemDefManager();
IShaderSource *shdrsrc = client->getShaderSource();
const NodeDefManager *ndef = client->getNodeDefManager();
const ItemDefinition &def = item.getDefinition(idef);
const ContentFeatures &f = ndef->get(def.name);
content_t id = ndef->getId(def.name);
scene::SMesh *mesh = nullptr;
if (m_enable_shaders) {
u32 shader_id = shdrsrc->getShader("wielded_shader", TILE_MATERIAL_BASIC, NDT_NORMAL);
m_material_type = shdrsrc->getShaderInfo(shader_id).material;
}
// Color-related
m_colors.clear();
m_base_color = idef->getItemstackColor(item, client);
// If wield_image is defined, it overrides everything else
if (!def.wield_image.empty()) {
setExtruded(def.wield_image, def.wield_overlay, def.wield_scale, tsrc,
1);
m_colors.emplace_back();
// overlay is white, if present
m_colors.emplace_back(true, video::SColor(0xFFFFFFFF));
return;
}
// Handle nodes
// See also CItemDefManager::createClientCached()
if (def.type == ITEM_NODE) {
if (f.mesh_ptr[0]) {
// e.g. mesh nodes and nodeboxes
mesh = cloneMesh(f.mesh_ptr[0]);
postProcessNodeMesh(mesh, f, m_enable_shaders, true,
&m_material_type, &m_colors);
changeToMesh(mesh);
mesh->drop();
// mesh is pre-scaled by BS * f->visual_scale
m_meshnode->setScale(
def.wield_scale * WIELD_SCALE_FACTOR
/ (BS * f.visual_scale));
} else {
switch (f.drawtype) {
case NDT_AIRLIKE: {
changeToMesh(nullptr);
break;
}
case NDT_PLANTLIKE: {
setExtruded(tsrc->getTextureName(f.tiles[0].layers[0].texture_id),
tsrc->getTextureName(f.tiles[0].layers[1].texture_id),
def.wield_scale, tsrc,
f.tiles[0].layers[0].animation_frame_count);
// Add color
const TileLayer &l0 = f.tiles[0].layers[0];
m_colors.emplace_back(l0.has_color, l0.color);
const TileLayer &l1 = f.tiles[0].layers[1];
m_colors.emplace_back(l1.has_color, l1.color);
break;
}
case NDT_PLANTLIKE_ROOTED: {
setExtruded(tsrc->getTextureName(f.special_tiles[0].layers[0].texture_id),
"", def.wield_scale, tsrc,
f.special_tiles[0].layers[0].animation_frame_count);
// Add color
const TileLayer &l0 = f.special_tiles[0].layers[0];
m_colors.emplace_back(l0.has_color, l0.color);
break;
}
case NDT_NORMAL:
case NDT_ALLFACES:
case NDT_LIQUID:
case NDT_FLOWINGLIQUID: {
setCube(f, def.wield_scale);
break;
}
default: {
mesh = createSpecialNodeMesh(client, id, &m_colors);
changeToMesh(mesh);
mesh->drop();
m_meshnode->setScale(
def.wield_scale * WIELD_SCALE_FACTOR
/ (BS * f.visual_scale));
}
}
}
u32 material_count = m_meshnode->getMaterialCount();
for (u32 i = 0; i < material_count; ++i) {
video::SMaterial &material = m_meshnode->getMaterial(i);
material.MaterialType = m_material_type;
material.setFlag(video::EMF_BACK_FACE_CULLING, true);
material.setFlag(video::EMF_BILINEAR_FILTER, m_bilinear_filter);
material.setFlag(video::EMF_TRILINEAR_FILTER, m_trilinear_filter);
}
return;
}
else if (!def.inventory_image.empty()) {
//.........这里部分代码省略.........
示例7: myrand_range
bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_ratio)
{
if(!m_has_animation)
{
m_animation_force_timer = 100000;
return false;
}
m_animation_force_timer = myrand_range(5, 100);
// Cracks
if(crack != m_last_crack)
{
for(std::map<u32, std::string>::iterator
i = m_crack_materials.begin();
i != m_crack_materials.end(); i++)
{
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i->first);
std::string basename = i->second;
// Create new texture name from original
ITextureSource *tsrc = m_gamedef->getTextureSource();
std::ostringstream os;
os<<basename<<crack;
u32 new_texture_id = 0;
video::ITexture *new_texture =
tsrc->getTexture(os.str(), &new_texture_id);
buf->getMaterial().setTexture(0, new_texture);
// If the current material is also animated,
// update animation info
std::map<u32, TileSpec>::iterator anim_iter =
m_animation_tiles.find(i->first);
if(anim_iter != m_animation_tiles.end()){
TileSpec &tile = anim_iter->second;
tile.texture = new_texture;
tile.texture_id = new_texture_id;
// force animation update
m_animation_frames[i->first] = -1;
}
}
m_last_crack = crack;
}
// Texture animation
for(std::map<u32, TileSpec>::iterator
i = m_animation_tiles.begin();
i != m_animation_tiles.end(); i++)
{
const TileSpec &tile = i->second;
// Figure out current frame
int frameoffset = m_animation_frame_offsets[i->first];
int frame = (int)(time * 1000 / tile.animation_frame_length_ms
+ frameoffset) % (tile.animation_frame_count ? tile.animation_frame_count : 1);
// If frame doesn't change, skip
if(frame == m_animation_frames[i->first])
continue;
m_animation_frames[i->first] = frame;
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i->first);
ITextureSource *tsrc = m_gamedef->getTextureSource();
FrameSpec animation_frame = tile.frames.find(frame)->second;
buf->getMaterial().setTexture(0, animation_frame.texture);
if (m_enable_shaders) {
if (animation_frame.normal_texture) {
buf->getMaterial().setTexture(1, animation_frame.normal_texture);
buf->getMaterial().setTexture(2, tsrc->getTexture("enable_img.png"));
} else {
buf->getMaterial().setTexture(2, tsrc->getTexture("disable_img.png"));
}
}
}
// Day-night transition
if(!m_enable_shaders && (daynight_ratio != m_last_daynight_ratio))
{
for(std::map<u32, std::map<u32, std::pair<u8, u8> > >::iterator
i = m_daynight_diffs.begin();
i != m_daynight_diffs.end(); i++)
{
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i->first);
buf->setDirty(irr::scene::EBT_VERTEX);
video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
for(std::map<u32, std::pair<u8, u8 > >::iterator
j = i->second.begin();
j != i->second.end(); j++)
{
u32 vertexIndex = j->first;
u8 day = j->second.first;
u8 night = j->second.second;
finalColorBlend(vertices[vertexIndex].Color,
day, night, daynight_ratio);
}
}
m_last_daynight_ratio = daynight_ratio;
}
//.........这里部分代码省略.........
示例8: clearHardwareBuffer
MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
clearHardwareBuffer(false),
step(data->step),
timestamp(data->timestamp),
m_mesh(new scene::SMesh()),
m_gamedef(data->m_gamedef),
m_animation_force_timer(0), // force initial animation
m_last_crack(-1),
m_crack_materials(),
m_highlighted_materials(),
m_last_daynight_ratio((u32) -1),
m_daynight_diffs(),
m_usage_timer(0)
{
m_enable_shaders = g_settings->getBool("enable_shaders");
m_enable_highlighting = g_settings->getBool("enable_node_highlighting");
// 4-21ms for MAP_BLOCKSIZE=16 (NOTE: probably outdated)
// 24-155ms for MAP_BLOCKSIZE=32 (NOTE: probably outdated)
//TimeTaker timer1("MapBlockMesh()");
data->fill_data();
std::vector<FastFace> fastfaces_new;
/*
We are including the faces of the trailing edges of the block.
This means that when something changes, the caller must
also update the meshes of the blocks at the leading edges.
NOTE: This is the slowest part of this method.
*/
{
// 4-23ms for MAP_BLOCKSIZE=16 (NOTE: probably outdated)
//TimeTaker timer2("updateAllFastFaceRows()");
updateAllFastFaceRows(data, fastfaces_new, step);
}
// End of slow part
//if (data->debug) infostream<<" step="<<step<<" fastfaces_new.size="<<fastfaces_new.size()<<std::endl;
/*
Convert FastFaces to MeshCollector
*/
MeshCollector collector;
{
// avg 0ms (100ms spikes when loading textures the first time)
// (NOTE: probably outdated)
//TimeTaker timer2("MeshCollector building");
for(u32 i=0; i<fastfaces_new.size(); i++)
{
FastFace &f = fastfaces_new[i];
const u16 indices[] = {0,1,2,2,3,0};
const u16 indices_alternate[] = {0,1,3,2,3,1};
if(f.tile.texture == NULL)
continue;
const u16 *indices_p = indices;
/*
Revert triangles for nicer looking gradient if vertices
1 and 3 have same color or 0 and 2 have different color.
getRed() is the day color.
*/
if(f.vertices[0].Color.getRed() != f.vertices[2].Color.getRed()
|| f.vertices[1].Color.getRed() == f.vertices[3].Color.getRed())
indices_p = indices_alternate;
collector.append(f.tile, f.vertices, 4, indices_p, 6);
}
}
/*
Add special graphics:
- torches
- flowing water
- fences
- whatever
*/
if(step <= 1)
mapblock_mesh_generate_special(data, collector);
m_highlight_mesh_color = data->m_highlight_mesh_color;
/*
Convert MeshCollector to SMesh
*/
ITextureSource *tsrc = m_gamedef->tsrc();
IShaderSource *shdrsrc = m_gamedef->getShaderSource();
for(u32 i = 0; i < collector.prebuffers.size(); i++)
{
PreMeshBuffer &p = collector.prebuffers[i];
//.........这里部分代码省略.........
示例9: m_mesh
//.........这里部分代码省略.........
/*
Convert MeshCollector to SMesh
*/
bool enable_shaders = g_settings->getBool("enable_shaders");
bool enable_bumpmapping = g_settings->getBool("enable_bumpmapping");
bool enable_parallax_occlusion = g_settings->getBool("enable_parallax_occlusion");
video::E_MATERIAL_TYPE shadermat1, shadermat2, shadermat3,
shadermat4, shadermat5;
shadermat1 = shadermat2 = shadermat3 = shadermat4 = shadermat5 =
video::EMT_SOLID;
if (enable_shaders) {
IShaderSource *shdrsrc = m_gamedef->getShaderSource();
shadermat1 = shdrsrc->getShader("solids_shader").material;
shadermat2 = shdrsrc->getShader("liquids_shader").material;
shadermat3 = shdrsrc->getShader("alpha_shader").material;
shadermat4 = shdrsrc->getShader("leaves_shader").material;
shadermat5 = shdrsrc->getShader("plants_shader").material;
}
for(u32 i = 0; i < collector.prebuffers.size(); i++)
{
PreMeshBuffer &p = collector.prebuffers[i];
/*dstream<<"p.vertices.size()="<<p.vertices.size()
<<", p.indices.size()="<<p.indices.size()
<<std::endl;*/
// Generate animation data
// - Cracks
if(p.tile.material_flags & MATERIAL_FLAG_CRACK)
{
ITextureSource *tsrc = data->m_gamedef->tsrc();
// Find the texture name plus ^[crack:N:
std::ostringstream os(std::ios::binary);
os<<tsrc->getTextureName(p.tile.texture_id)<<"^[crack";
if(p.tile.material_flags & MATERIAL_FLAG_CRACK_OVERLAY)
os<<"o"; // use ^[cracko
os<<":"<<(u32)p.tile.animation_frame_count<<":";
m_crack_materials.insert(std::make_pair(i, os.str()));
// Replace tile texture with the cracked one
p.tile.texture = tsrc->getTexture(
os.str()+"0",
&p.tile.texture_id);
}
// - Texture animation
if(p.tile.material_flags & MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES)
{
ITextureSource *tsrc = data->m_gamedef->tsrc();
// Add to MapBlockMesh in order to animate these tiles
m_animation_tiles[i] = p.tile;
m_animation_frames[i] = 0;
if(g_settings->getBool("desynchronize_mapblock_texture_animation")){
// Get starting position from noise
m_animation_frame_offsets[i] = 100000 * (2.0 + noise3d(
data->m_blockpos.X, data->m_blockpos.Y,
data->m_blockpos.Z, 0));
} else {
// Play all synchronized
m_animation_frame_offsets[i] = 0;
}
// Replace tile texture with the first animation frame
std::ostringstream os(std::ios::binary);
os<<tsrc->getTextureName(p.tile.texture_id);
os<<"^[verticalframe:"<<(int)p.tile.animation_frame_count<<":0";
示例10: myrand_range
bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_ratio)
{
if(!m_has_animation)
{
m_animation_force_timer = 100000;
return false;
}
m_animation_force_timer = myrand_range(5, 100);
// Cracks
if(crack != m_last_crack)
{
for(std::map<u32, std::string>::iterator
i = m_crack_materials.begin();
i != m_crack_materials.end(); i++)
{
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i->first);
std::string basename = i->second;
// Create new texture name from original
ITextureSource *tsrc = m_gamedef->getTextureSource();
std::ostringstream os;
os<<basename<<crack;
AtlasPointer ap = tsrc->getTexture(os.str());
buf->getMaterial().setTexture(0, ap.atlas);
}
m_last_crack = crack;
}
// Texture animation
for(std::map<u32, TileSpec>::iterator
i = m_animation_tiles.begin();
i != m_animation_tiles.end(); i++)
{
const TileSpec &tile = i->second;
// Figure out current frame
int frameoffset = m_animation_frame_offsets[i->first];
int frame = (int)(time * 1000 / tile.animation_frame_length_ms
+ frameoffset) % tile.animation_frame_count;
// If frame doesn't change, skip
if(frame == m_animation_frames[i->first])
continue;
m_animation_frames[i->first] = frame;
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i->first);
ITextureSource *tsrc = m_gamedef->getTextureSource();
// Create new texture name from original
std::ostringstream os(std::ios::binary);
os<<tsrc->getTextureName(tile.texture.id);
os<<"^[verticalframe:"<<(int)tile.animation_frame_count<<":"<<frame;
// Set the texture
AtlasPointer ap = tsrc->getTexture(os.str());
buf->getMaterial().setTexture(0, ap.atlas);
}
// Day-night transition
if(daynight_ratio != m_last_daynight_ratio)
{
for(std::map<u32, std::map<u32, std::pair<u8, u8> > >::iterator
i = m_daynight_diffs.begin();
i != m_daynight_diffs.end(); i++)
{
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(i->first);
video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
for(std::map<u32, std::pair<u8, u8 > >::iterator
j = i->second.begin();
j != i->second.end(); j++)
{
u32 vertexIndex = j->first;
u8 day = j->second.first;
u8 night = j->second.second;
finalColorBlend(vertices[vertexIndex].Color,
day, night, daynight_ratio);
// Brighten topside (no shaders)
if(vertices[vertexIndex].Normal.Y > 0.5)
{
video::SColor &vc = vertices[vertexIndex].Color;
vc.setRed (srgb_linear_multiply(vc.getRed(), 1.3, 255.0));
vc.setGreen(srgb_linear_multiply(vc.getGreen(), 1.3, 255.0));
vc.setBlue (srgb_linear_multiply(vc.getBlue(), 1.3, 255.0));
}
}
}
m_last_daynight_ratio = daynight_ratio;
}
return true;
}
示例11: createClientCachedDirect
ClientCached* createClientCachedDirect(const std::string &name,
IGameDef *gamedef) const
{
infostream<<"Lazily creating item texture and mesh for \""
<<name<<"\""<<std::endl;
// This is not thread-safe
sanity_check(get_current_thread_id() == m_main_thread);
// Skip if already in cache
ClientCached *cc = NULL;
m_clientcached.get(name, &cc);
if(cc)
return cc;
ITextureSource *tsrc = gamedef->getTextureSource();
INodeDefManager *nodedef = gamedef->getNodeDefManager();
const ItemDefinition &def = get(name);
// Create new ClientCached
cc = new ClientCached();
// Create an inventory texture
cc->inventory_texture = NULL;
if(def.inventory_image != "")
cc->inventory_texture = tsrc->getTexture(def.inventory_image);
// Additional processing for nodes:
// - Create a wield mesh if WieldMeshSceneNode can't render
// the node on its own.
// - If inventory_texture isn't set yet, create one using
// render-to-texture.
if (def.type == ITEM_NODE) {
// Get node properties
content_t id = nodedef->getId(name);
const ContentFeatures &f = nodedef->get(id);
bool need_rtt_mesh = cc->inventory_texture == NULL;
// Keep this in sync with WieldMeshSceneNode::setItem()
bool need_wield_mesh =
!(f.mesh_ptr[0] ||
f.drawtype == NDT_NORMAL ||
f.drawtype == NDT_ALLFACES ||
f.drawtype == NDT_AIRLIKE);
scene::IMesh *node_mesh = NULL;
if (need_rtt_mesh || need_wield_mesh) {
u8 param1 = 0;
if (f.param_type == CPT_LIGHT)
param1 = 0xee;
/*
Make a mesh from the node
*/
MeshMakeData mesh_make_data(gamedef, false);
u8 param2 = 0;
if (f.param_type_2 == CPT2_WALLMOUNTED)
param2 = 1;
MapNode mesh_make_node(id, param1, param2);
mesh_make_data.fillSingleNode(&mesh_make_node);
MapBlockMesh mapblock_mesh(&mesh_make_data, v3s16(0, 0, 0));
node_mesh = mapblock_mesh.getMesh();
node_mesh->grab();
video::SColor c(255, 255, 255, 255);
setMeshColor(node_mesh, c);
// scale and translate the mesh so it's a
// unit cube centered on the origin
scaleMesh(node_mesh, v3f(1.0/BS, 1.0/BS, 1.0/BS));
translateMesh(node_mesh, v3f(-1.0, -1.0, -1.0));
}
/*
Draw node mesh into a render target texture
*/
if (need_rtt_mesh) {
TextureFromMeshParams params;
params.mesh = node_mesh;
params.dim.set(64, 64);
params.rtt_texture_name = "INVENTORY_"
+ def.name + "_RTT";
params.delete_texture_on_shutdown = true;
params.camera_position.set(0, 1.0, -1.5);
params.camera_position.rotateXZBy(45);
params.camera_lookat.set(0, 0, 0);
// Set orthogonal projection
params.camera_projection_matrix.buildProjectionMatrixOrthoLH(
1.65, 1.65, 0, 100);
params.ambient_light.set(1.0, 0.2, 0.2, 0.2);
params.light_position.set(10, 100, -50);
params.light_color.set(1.0, 0.5, 0.5, 0.5);
params.light_radius = 1000;
#ifdef __ANDROID__
params.camera_position.set(0, -1.0, -1.5);
params.camera_position.rotateXZBy(45);
params.light_position.set(10, -100, -50);
#endif
//.........这里部分代码省略.........
示例12: updateTexturesAndMeshes
virtual void updateTexturesAndMeshes(IGameDef *gamedef)
{
#ifndef SERVER
infostream<<"ItemDefManager::updateTexturesAndMeshes(): Updating "
<<"textures and meshes in item definitions"<<std::endl;
ITextureSource *tsrc = gamedef->getTextureSource();
INodeDefManager *nodedef = gamedef->getNodeDefManager();
IrrlichtDevice *device = tsrc->getDevice();
video::IVideoDriver *driver = device->getVideoDriver();
for(std::map<std::string, ItemDefinition*>::iterator
i = m_item_definitions.begin();
i != m_item_definitions.end(); i++)
{
ItemDefinition *def = i->second;
bool need_node_mesh = false;
// Create an inventory texture
def->inventory_texture = NULL;
if(def->inventory_image != "")
{
def->inventory_texture = tsrc->getTextureRaw(def->inventory_image);
}
else if(def->type == ITEM_NODE)
{
need_node_mesh = true;
}
// Create a wield mesh
if(def->wield_mesh != NULL)
{
def->wield_mesh->drop();
def->wield_mesh = NULL;
}
if(def->type == ITEM_NODE && def->wield_image == "")
{
need_node_mesh = true;
}
else if(def->wield_image != "" || def->inventory_image != "")
{
// Extrude the wield image into a mesh
std::string imagename;
if(def->wield_image != "")
imagename = def->wield_image;
else
imagename = def->inventory_image;
def->wield_mesh = createExtrudedMesh(
tsrc->getTextureRaw(imagename),
driver,
def->wield_scale * v3f(40.0, 40.0, 4.0));
if(def->wield_mesh == NULL)
{
infostream<<"ItemDefManager: WARNING: "
<<"updateTexturesAndMeshes(): "
<<"Unable to create extruded mesh for item "
<<def->name<<std::endl;
}
}
if(need_node_mesh)
{
/*
Get node properties
*/
content_t id = nodedef->getId(def->name);
const ContentFeatures &f = nodedef->get(id);
u8 param1 = 0;
if(f.param_type == CPT_LIGHT)
param1 = 0xee;
/*
Make a mesh from the node
*/
MeshMakeData mesh_make_data(gamedef);
MapNode mesh_make_node(id, param1, 0);
mesh_make_data.fillSingleNode(&mesh_make_node);
MapBlockMesh mapblock_mesh(&mesh_make_data);
scene::IMesh *node_mesh = mapblock_mesh.getMesh();
assert(node_mesh);
setMeshColor(node_mesh, video::SColor(255, 255, 255, 255));
/*
Scale and translate the mesh so it's a unit cube
centered on the origin
*/
scaleMesh(node_mesh, v3f(1.0/BS, 1.0/BS, 1.0/BS));
translateMesh(node_mesh, v3f(-1.0, -1.0, -1.0));
/*
Draw node mesh into a render target texture
*/
if(def->inventory_texture == NULL)
{
core::dimension2d<u32> dim(64,64);
//.........这里部分代码省略.........
示例13: setItem
void WieldMeshSceneNode::setItem(const ItemStack &item, IGameDef *gamedef)
{
ITextureSource *tsrc = gamedef->getTextureSource();
IItemDefManager *idef = gamedef->getItemDefManager();
//IShaderSource *shdrsrc = gamedef->getShaderSource();
INodeDefManager *ndef = gamedef->getNodeDefManager();
const ItemDefinition &def = item.getDefinition(idef);
const ContentFeatures &f = ndef->get(def.name);
content_t id = ndef->getId(def.name);
#if 0
//// TODO(RealBadAngel): Reactivate when shader is added for wield items
if (m_enable_shaders) {
u32 shader_id = shdrsrc->getShader("nodes_shader", TILE_MATERIAL_BASIC, NDT_NORMAL);
m_material_type = shdrsrc->getShaderInfo(shader_id).material;
}
#endif
// If wield_image is defined, it overrides everything else
if (def.wield_image != "") {
setExtruded(def.wield_image, def.wield_scale, tsrc, 1);
return;
}
// Handle nodes
// See also CItemDefManager::createClientCached()
else if (def.type == ITEM_NODE) {
if (f.mesh_ptr[0]) {
// e.g. mesh nodes and nodeboxes
changeToMesh(f.mesh_ptr[0]);
// mesh_ptr[0] is pre-scaled by BS * f->visual_scale
m_meshnode->setScale(
def.wield_scale * WIELD_SCALE_FACTOR
/ (BS * f.visual_scale));
} else if (f.drawtype == NDT_AIRLIKE) {
changeToMesh(NULL);
} else if (f.drawtype == NDT_PLANTLIKE) {
setExtruded(tsrc->getTextureName(f.tiles[0].texture_id), def.wield_scale, tsrc, f.tiles[0].animation_frame_count);
} else if (f.drawtype == NDT_NORMAL || f.drawtype == NDT_ALLFACES) {
setCube(f.tiles, def.wield_scale, tsrc);
} else {
//// TODO: Change false in the following constructor args to
//// appropriate value when shader is added for wield items (if applicable)
MeshMakeData mesh_make_data(gamedef, false);
MapNode mesh_make_node(id, 255, 0);
mesh_make_data.fillSingleNode(&mesh_make_node);
MapBlockMesh mapblock_mesh(&mesh_make_data, v3s16(0, 0, 0));
changeToMesh(mapblock_mesh.getMesh());
translateMesh(m_meshnode->getMesh(), v3f(-BS, -BS, -BS));
m_meshnode->setScale(
def.wield_scale * WIELD_SCALE_FACTOR
/ (BS * f.visual_scale));
}
u32 material_count = m_meshnode->getMaterialCount();
if (material_count > 6) {
errorstream << "WieldMeshSceneNode::setItem: Invalid material "
"count " << material_count << ", truncating to 6" << std::endl;
material_count = 6;
}
for (u32 i = 0; i < material_count; ++i) {
video::SMaterial &material = m_meshnode->getMaterial(i);
material.setFlag(video::EMF_BACK_FACE_CULLING, true);
material.setFlag(video::EMF_BILINEAR_FILTER, m_bilinear_filter);
material.setFlag(video::EMF_TRILINEAR_FILTER, m_trilinear_filter);
bool animated = (f.tiles[i].animation_frame_count > 1);
if (animated) {
FrameSpec animation_frame = f.tiles[i].frames[0];
material.setTexture(0, animation_frame.texture);
} else {
material.setTexture(0, f.tiles[i].texture);
}
material.MaterialType = m_material_type;
#if 0
//// TODO(RealBadAngel): Reactivate when shader is added for wield items
if (m_enable_shaders) {
if (f.tiles[i].normal_texture) {
if (animated) {
FrameSpec animation_frame = f.tiles[i].frames[0];
material.setTexture(1, animation_frame.normal_texture);
} else {
material.setTexture(1, f.tiles[i].normal_texture);
}
material.setTexture(2, tsrc->getTexture("enable_img.png"));
} else {
material.setTexture(2, tsrc->getTexture("disable_img.png"));
}
}
#endif
}
return;
}
else if (def.inventory_image != "") {
setExtruded(def.inventory_image, def.wield_scale, tsrc, 1);
return;
}
// no wield mesh found
changeToMesh(NULL);
}
示例14: m_mesh
MapBlockMesh::MapBlockMesh(MeshMakeData *data):
m_mesh(new scene::SMesh()),
m_gamedef(data->m_gamedef),
m_animation_force_timer(0), // force initial animation
m_last_crack(-1),
m_crack_materials(),
m_last_daynight_ratio((u32) -1),
m_daynight_diffs()
{
// 4-21ms for MAP_BLOCKSIZE=16 (NOTE: probably outdated)
// 24-155ms for MAP_BLOCKSIZE=32 (NOTE: probably outdated)
//TimeTaker timer1("MapBlockMesh()");
core::array<FastFace> fastfaces_new;
/*
We are including the faces of the trailing edges of the block.
This means that when something changes, the caller must
also update the meshes of the blocks at the leading edges.
NOTE: This is the slowest part of this method.
*/
{
// 4-23ms for MAP_BLOCKSIZE=16 (NOTE: probably outdated)
//TimeTaker timer2("updateAllFastFaceRows()");
updateAllFastFaceRows(data, fastfaces_new);
}
// End of slow part
/*
Convert FastFaces to MeshCollector
*/
MeshCollector collector;
{
// avg 0ms (100ms spikes when loading textures the first time)
// (NOTE: probably outdated)
//TimeTaker timer2("MeshCollector building");
for(u32 i=0; i<fastfaces_new.size(); i++)
{
FastFace &f = fastfaces_new[i];
const u16 indices[] = {0,1,2,2,3,0};
const u16 indices_alternate[] = {0,1,3,2,3,1};
if(f.tile.texture.atlas == NULL)
continue;
const u16 *indices_p = indices;
/*
Revert triangles for nicer looking gradient if vertices
1 and 3 have same color or 0 and 2 have different color.
getRed() is the day color.
*/
if(f.vertices[0].Color.getRed() != f.vertices[2].Color.getRed()
|| f.vertices[1].Color.getRed() == f.vertices[3].Color.getRed())
indices_p = indices_alternate;
collector.append(f.tile, f.vertices, 4, indices_p, 6);
}
}
/*
Add special graphics:
- torches
- flowing water
- fences
- whatever
*/
mapblock_mesh_generate_special(data, collector);
/*
Convert MeshCollector to SMesh
Also store animation info
*/
for(u32 i = 0; i < collector.prebuffers.size(); i++)
{
PreMeshBuffer &p = collector.prebuffers[i];
/*dstream<<"p.vertices.size()="<<p.vertices.size()
<<", p.indices.size()="<<p.indices.size()
<<std::endl;*/
// Generate animation data
// - Cracks
if(p.tile.material_flags & MATERIAL_FLAG_CRACK)
{
ITextureSource *tsrc = data->m_gamedef->tsrc();
std::string crack_basename = tsrc->getTextureName(p.tile.texture.id);
if(p.tile.material_flags & MATERIAL_FLAG_CRACK_OVERLAY)
crack_basename += "^[cracko";
else
crack_basename += "^[crack";
m_crack_materials.insert(std::make_pair(i, crack_basename));
}
// - Lighting
//.........这里部分代码省略.........
示例15: createClientCachedDirect
ClientCached* createClientCachedDirect(const std::string &name,
IGameDef *gamedef) const
{
infostream<<"Lazily creating item texture and mesh for \""
<<name<<"\""<<std::endl;
// This is not thread-safe
assert(get_current_thread_id() == m_main_thread);
// Skip if already in cache
ClientCached *cc = NULL;
m_clientcached.get(name, &cc);
if(cc)
return cc;
ITextureSource *tsrc = gamedef->getTextureSource();
INodeDefManager *nodedef = gamedef->getNodeDefManager();
IrrlichtDevice *device = tsrc->getDevice();
video::IVideoDriver *driver = device->getVideoDriver();
const ItemDefinition *def = &get(name);
// Create new ClientCached
cc = new ClientCached();
bool need_node_mesh = false;
// Create an inventory texture
cc->inventory_texture = NULL;
if(def->inventory_image != "")
{
cc->inventory_texture = tsrc->getTextureRaw(def->inventory_image);
}
else if(def->type == ITEM_NODE)
{
need_node_mesh = true;
}
// Create a wield mesh
assert(cc->wield_mesh == NULL);
if(def->type == ITEM_NODE && def->wield_image == "")
{
need_node_mesh = true;
}
else if(def->wield_image != "" || def->inventory_image != "")
{
// Extrude the wield image into a mesh
std::string imagename;
if(def->wield_image != "")
imagename = def->wield_image;
else
imagename = def->inventory_image;
cc->wield_mesh = createExtrudedMesh(
tsrc->getTextureRaw(imagename),
driver,
def->wield_scale * v3f(40.0, 40.0, 4.0));
if(cc->wield_mesh == NULL)
{
infostream<<"ItemDefManager: WARNING: "
<<"updateTexturesAndMeshes(): "
<<"Unable to create extruded mesh for item "
<<def->name<<std::endl;
}
}
if(need_node_mesh)
{
/*
Get node properties
*/
content_t id = nodedef->getId(def->name);
const ContentFeatures &f = nodedef->get(id);
u8 param1 = 0;
if(f.param_type == CPT_LIGHT)
param1 = 0xee;
/*
Make a mesh from the node
*/
MeshMakeData mesh_make_data(gamedef);
MapNode mesh_make_node(id, param1, 0);
mesh_make_data.fillSingleNode(&mesh_make_node);
MapBlockMesh mapblock_mesh(&mesh_make_data);
scene::IMesh *node_mesh = mapblock_mesh.getMesh();
assert(node_mesh);
video::SColor c(255, 255, 255, 255);
if(g_settings->getS32("enable_shaders") != 0)
c = MapBlock_LightColor(255, 0xffff, decode_light(f.light_source));
setMeshColor(node_mesh, c);
/*
Scale and translate the mesh so it's a unit cube
centered on the origin
*/
scaleMesh(node_mesh, v3f(1.0/BS, 1.0/BS, 1.0/BS));
translateMesh(node_mesh, v3f(-1.0, -1.0, -1.0));
//.........这里部分代码省略.........