本文整理汇总了C++中SMeshBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ SMeshBuffer类的具体用法?C++ SMeshBuffer怎么用?C++ SMeshBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SMeshBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: STreeMesh
STreeMesh* CTreeGenerator::generateTree( s32 radialSegments, s32 seed, bool addLeaves, s32 cutoffLevel )
{
STreeMesh* treeMesh = new STreeMesh();
Seed = seed;
LeafSeed = seed;
RadialSegments = radialSegments;
CutoffLevel = cutoffLevel;
AddLeaves = addLeaves;
SMeshBuffer* buffer = new SMeshBuffer();
treeMesh->setMeshBuffer( buffer );
SBranch* root = getBranchWithId( RootIdRef );
if ( root != 0 )
{
appendBranch( core::matrix4(), root, 1.0f, 1.0f, Levels, buffer, treeMesh->Leaves );
}
buffer->drop();
return treeMesh;
}
示例2: center_
Sprite::Sprite(std::string const& name, bool const& center)
:Object(name), center_(center), thismesh_(0)
{
if( !sprite_plane_ptr_ ) {
S3DVertex vertices[4];
u16 indices[6] = {0,2,3,3,1,0};
vertices[0].Pos = vector3df(0,-1,0);
vertices[1].Pos = vector3df(1,-1,0);
vertices[2].Pos = vector3df(0, 0,0);
vertices[3].Pos = vector3df(1, 0,0);
vertices[0].Normal = vector3df(0,0,-1);
vertices[1].Normal = vector3df(0,0,-1);
vertices[2].Normal = vector3df(0,0,-1);
vertices[3].Normal = vector3df(0,0,-1);
vertices[0].TCoords = vector2df(0,1);
vertices[1].TCoords = vector2df(1,1);
vertices[2].TCoords = vector2df(0,0);
vertices[3].TCoords = vector2df(1,0);
SMeshBuffer* buf = new SMeshBuffer();
buf->append(vertices, 4, indices, 6);
sprite_plane_.addMeshBuffer( buf );
sprite_plane_.recalculateBoundingBox();
sprite_plane_ptr_ = &sprite_plane_;
buf->drop(); //the addMeshBuffer method will grab it, so we can drop this ptr.
}
}
示例3: SMeshBuffer
IMesh* MeshTools::createMeshFromSoftBody(btSoftBody* softBody)
{
SMeshBuffer* buffer = new SMeshBuffer();
video::S3DVertex vtx;
vtx.Color.set(255,255,255,255);
/* Each soft body contain an array of vertices (nodes/particles_mass) */
btSoftBody::tNodeArray& nodes(softBody->m_nodes);
// Convert bullet nodes to vertices
for(int i=0;i<nodes.size();++i)
{
const btSoftBody::Node& n=nodes[i];
const btVector3 normal=n.m_n;
const btVector3 pos=n.m_x;
vtx.Pos.set(pos.getX(), pos.getY(), pos.getZ());
vtx.Normal.set(normal.getX(), normal.getY(), normal.getZ());
// TODO: calculate texture coords
//vtx.TCoords.set(tsx, tsy);
buffer->Vertices.push_back(vtx);
}
// Convert triangles of the softbody to an index list
for(int i=0;i<softBody->m_faces.size();++i)
{
auto faces = softBody->m_faces;
btSoftBody::Node* node_0=faces[i].m_n[0];
btSoftBody::Node* node_1=faces[i].m_n[1];
btSoftBody::Node* node_2=faces[i].m_n[2];
const int indices[] =
{
int(node_0-&nodes[0]),
int(node_1-&nodes[0]),
int(node_2-&nodes[0])
};
for(int j=0;j<3;++j)
buffer->Indices.push_back(indices[j]);
}
buffer->recalculateBoundingBox();
// Default the mesh to stream because most likely we will be updating
// the vertex positions every frame to deal with softbody movement.
buffer->setHardwareMappingHint(EHM_STREAM);
SMesh* mesh = new SMesh();
mesh->addMeshBuffer(buffer);
mesh->recalculateBoundingBox();
buffer->drop();
return mesh;
}
示例4: MeshBuffer_SetVertex
void MeshBuffer_SetVertex(IntPtr meshb, unsigned int nr, IntPtr vert)
{
SMeshBuffer *mb = ((SMeshBuffer*)meshb);
if(nr >= mb->getVertexCount())
{
mb->Vertices.push_back(*((S3DVertex*)vert));
MeshBuffer_SetVertex(meshb, nr, vert);
}
else
(((S3DVertex*)(mb->getVertices()))[nr]) = *((S3DVertex*)vert);
}
示例5: addstrip
void addstrip(const HeightMap &hm, colour_func cf, u16 y0, u16 y1, u32 bufNum)
{
SMeshBuffer *buf = 0;
if (bufNum<Mesh->getMeshBufferCount())
{
buf = (SMeshBuffer*)Mesh->getMeshBuffer(bufNum);
}
else
{
// create new buffer
buf = new SMeshBuffer();
Mesh->addMeshBuffer(buf);
// to simplify things we drop here but continue using buf
buf->drop();
}
buf->Vertices.set_used((1 + y1 - y0) * Width);
u32 i=0;
for (u16 y = y0; y <= y1; ++y)
{
for (u16 x = 0; x < Width; ++x)
{
const f32 z = hm.get(x, y);
const f32 xx = (f32)x/(f32)Width;
const f32 yy = (f32)y/(f32)Height;
S3DVertex& v = buf->Vertices[i++];
v.Pos.set(x, Scale * z, y);
v.Normal.set(hm.getnormal(x, y, Scale));
v.Color=cf(xx, yy, z);
v.TCoords.set(xx, yy);
}
}
buf->Indices.set_used(6 * (Width - 1) * (y1 - y0));
i=0;
for(u16 y = y0; y < y1; ++y)
{
for(u16 x = 0; x < Width - 1; ++x)
{
const u16 n = (y-y0) * Width + x;
buf->Indices[i]=n;
buf->Indices[++i]=n + Width;
buf->Indices[++i]=n + Width + 1;
buf->Indices[++i]=n + Width + 1;
buf->Indices[++i]=n + 1;
buf->Indices[++i]=n;
++i;
}
}
buf->recalculateBoundingBox();
}
示例6: MeshBuffer_SetColor
void MeshBuffer_SetColor(IntPtr meshb, M_SCOLOR color)
{
SMeshBuffer *mb = ((SMeshBuffer*)meshb);
int cnt = mb->getVertexCount();
//mb->grab();
for (int i=0;i<cnt;i++)
{
mb->Vertices[i].Color = MU_SCOLOR(color);
}
mb->setDirty(irr::scene::EBT_VERTEX);
}
示例7: IBillboardTextSceneNode
//! constructor
CBillboardTextSceneNode::CBillboardTextSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
gui::IGUIFont* font,const wchar_t* text,
const core::vector3df& position, const core::dimension2d<f32>& size,
video::SColor colorTop,video::SColor shade_bottom )
: IBillboardTextSceneNode(parent, mgr, id, position),
Font(0), ColorTop(colorTop), ColorBottom(shade_bottom), Mesh(0)
{
#ifdef _DEBUG
setDebugName("CBillboardTextSceneNode");
#endif
Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
Material.MaterialTypeParam = 1.f / 255.f;
Material.BackfaceCulling = false;
Material.Lighting = false;
Material.ZBuffer = video::ECFN_LESSEQUAL;
Material.ZWriteEnable = false;
if (font)
{
// doesn't support other font types
if (font->getType() == gui::EGFT_BITMAP)
{
Font = (gui::IGUIFontBitmap*)font;
Font->grab();
// mesh with one buffer per texture
Mesh = new SMesh();
for (u32 i=0; i<Font->getSpriteBank()->getTextureCount(); ++i)
{
SMeshBuffer *mb = new SMeshBuffer();
mb->Material = Material;
mb->Material.setTexture(0, Font->getSpriteBank()->getTexture(i));
Mesh->addMeshBuffer(mb);
mb->drop();
}
}
else
{
os::Printer::log("Sorry, CBillboardTextSceneNode does not support this font type", ELL_INFORMATION);
}
}
setText(text);
setSize(size);
setAutomaticCulling ( scene::EAC_BOX );
}
示例8: SMesh
IMeshSceneNode* CustomSceneNodeManager::CreateConeSceneNode(scene::ISceneManager* sceneManager, s32 id, SColor& color, unsigned int resolution, float radius, float height)
{
if (resolution >= 4)
{
/*IMesh* newConeMesh = sceneManager->getGeometryCreator()->createConeMesh(radius, height, resolution, color, color);
IMeshSceneNode* node = sceneManager->addMeshSceneNode(newConeMesh);
sceneManager->getMeshCache()->addMesh(irr::io::path("ConeMesh"), (irr::scene::IAnimatedMesh*)newConeMesh);
newConeMesh->drop();*/
SMesh* newConeMesh = new SMesh();
SMeshBuffer* buf = new SMeshBuffer();
newConeMesh->addMeshBuffer(buf);
buf->MappingHint_Vertex = EHM_STATIC;
buf->MappingHint_Index = EHM_STATIC;
buf->drop();
int noWarningSignedResolution = resolution;
float currentTheta = 0.0f;
float skipAmount = 2.0f*PI / (float)resolution;
float halfHeight = height / 2.0f;
S3DVertex temp1 = S3DVertex(Vector3(0.0f, halfHeight, 0.0f), Vector3_Zero, color, vector2d<f32>(0.0f, 0.0f));
S3DVertex temp2 = S3DVertex(Vector3(0.0f, -halfHeight, 0.0f), Vector3_Zero, color, vector2d<f32>(0.0f, 1.0f));
for(int i = 0; i < noWarningSignedResolution; i++)
{
float x = cosf(currentTheta) * radius;
float z = sinf(currentTheta) * radius;
temp2.Pos.X = x;
temp2.Pos.Z = z;
temp2.TCoords.X = currentTheta / 2.0f*PI;
buf->Vertices.push_back(temp2);
currentTheta += skipAmount;
}
buf->Vertices.push_back(temp1);
//Get side indices
for(int i = 0; i < noWarningSignedResolution - 1; i++)
{
buf->Indices.push_back(i);
buf->Indices.push_back(buf->Vertices.size()-1);
buf->Indices.push_back(i+1);
}
buf->Indices.push_back(buf->Vertices.size()-2);
buf->Indices.push_back(buf->Vertices.size()-1);
buf->Indices.push_back(0);
temp2.Pos.X = 0.0f;
temp2.Pos.Z = 0.0f;
buf->Vertices.push_back(temp2);
//Get bottom indices
for(int i = 0; i < noWarningSignedResolution - 1; i++)
{
buf->Indices.push_back(i);
buf->Indices.push_back(i+1);
buf->Indices.push_back(buf->Vertices.size()-1);
}
buf->Indices.push_back(buf->Vertices.size()-1);
buf->Indices.push_back(buf->Vertices.size()-3);
buf->Indices.push_back(0);
//Calculate normals
CalculateNormals(buf->Vertices, buf->Indices);
buf->recalculateBoundingBox();
newConeMesh->recalculateBoundingBox();
IMeshSceneNode* node = sceneManager->addMeshSceneNode(newConeMesh);
newConeMesh->drop();
return node;
}
return NULL;
}
示例9: SMesh
IAnimatedMesh* CGeometryCreator::createTerrainMesh(video::IImage* texture,
video::IImage* heightmap, const core::dimension2d<f32>& stretchSize,
f32 maxHeight, video::IVideoDriver* driver,
const core::dimension2d<s32> maxVtxBlockSize,
bool debugBorders)
{
u32 tm = os::Timer::getRealTime()/1000;
if (!texture || !heightmap)
return 0;
video::SMaterial material;
c8 textureName[64];
c8 tmp[255];
// debug border
s32 borderSkip = debugBorders ? 0 : 1;
video::S3DVertex vtx;
vtx.Color.set(255,255,255,255);
SMesh* mesh = new SMesh();
core::dimension2d<s32> hMapSize= heightmap->getDimension();
core::dimension2d<s32> tMapSize= texture->getDimension();
core::position2d<f32> thRel((f32)tMapSize.Width / (s32)hMapSize.Width, (f32)tMapSize.Height / (s32)hMapSize.Height);
core::position2d<s32> processed(0,0);
while (processed.Y<hMapSize.Height)
{
while(processed.X<hMapSize.Width)
{
core::dimension2d<s32> blockSize = maxVtxBlockSize;
if (processed.X + blockSize.Width > hMapSize.Width)
blockSize.Width = hMapSize.Width - processed.X;
if (processed.Y + blockSize.Height > hMapSize.Height)
blockSize.Height = hMapSize.Height - processed.Y;
SMeshBuffer* buffer = new SMeshBuffer();
s32 x,y;
// add vertices of vertex block
for (y=0; y<blockSize.Height; ++y)
for (x=0; x<blockSize.Width; ++x)
{
video::SColor clr = heightmap->getPixel(x+processed.X, y+processed.Y);
f32 height = ((clr.getRed() + clr.getGreen() + clr.getBlue()) / 3.0f)/255.0f * maxHeight;
vtx.Pos.set((f32)(x+processed.X) * stretchSize.Width,
height, (f32)(y+processed.Y) * stretchSize.Height);
vtx.TCoords.set((f32)(x+0.5f) / ((f32)blockSize.Width),
(f32)(y+0.5f) / ((f32)blockSize.Height));
buffer->Vertices.push_back(vtx);
}
// add indices of vertex block
for (y=0; y<blockSize.Height-1; ++y)
for (x=0; x<blockSize.Width-1; ++x)
{
s32 c = (y*blockSize.Width) + x;
buffer->Indices.push_back(c);
buffer->Indices.push_back(c + blockSize.Width);
buffer->Indices.push_back(c + 1);
buffer->Indices.push_back(c + 1);
buffer->Indices.push_back(c + blockSize.Width);
buffer->Indices.push_back(c + 1 + blockSize.Width);
}
// recalculate normals
for (s32 i=0; i<(s32)buffer->Indices.size(); i+=3)
{
core::plane3d<f32> p(
buffer->Vertices[buffer->Indices[i+0]].Pos,
buffer->Vertices[buffer->Indices[i+1]].Pos,
buffer->Vertices[buffer->Indices[i+2]].Pos);
p.Normal.normalize();
buffer->Vertices[buffer->Indices[i+0]].Normal = p.Normal;
buffer->Vertices[buffer->Indices[i+1]].Normal = p.Normal;
buffer->Vertices[buffer->Indices[i+2]].Normal = p.Normal;
}
if (buffer->Vertices.size())
{
// create texture for this block
video::IImage* img = new video::CImage(texture,
core::position2d<s32>((s32)(processed.X*thRel.X), (s32)(processed.Y*thRel.Y)),
core::dimension2d<s32>((s32)(blockSize.Width*thRel.X), (s32)(blockSize.Height*thRel.Y)));
sprintf(textureName, "terrain%d_%d", tm, mesh->getMeshBufferCount());
material.Texture1 = driver->addTexture(textureName, img);
if (material.Texture1)
{
//.........这里部分代码省略.........
示例10: SMeshBuffer
PlayerFrame::PlayerFrame(FrameInfo info, bool load_volumic)
{
// increase total number of loaded frames
PlayerFrame::totalLoadedFrames++;
device->getLogger()->log((stringw("Loading frame number ")+stringw(info.id)+L". Total of frames loaded : "+stringw(PlayerFrame::totalLoadedFrames)).c_str());
core::array<stringc> _lastEleFileNames;
core::array<stringc> _lastFaceFileNames;
core::array<scene::SMeshBuffer*> _lastBuffers;
// initialize some variables
this->id = info.id;
for (u32 o=0; o < info.nodefiles.size(); o++)
{
SMeshBuffer* buffer = new SMeshBuffer();
IMeshSceneNode* node = NULL;
stringc nodeFileName = info.nodefiles[o];
stringc faceFileName = info.facefiles[o];
stringc eleFileName = info.elefiles[o];
// LOADING
ifstream innode;
ifstream inele;
ifstream inface;
int nb_of_points, nb_of_tetrahedra, nb_of_faces;
int p1, p2, p3, p4;
yohan::base::DATA x, y, z;
// used to know if an error occured in the while loop
bool error = false;
// -----------------------------------------------------------------------
// - POINTS --------------------------------------------------------------
// -----------------------------------------------------------------------
innode.open(nodeFileName.c_str(), ios::in | ios::binary); // opens the nodes file
if (!innode || !innode.good())
{
device->getLogger()->log(( stringc("ERROR: This node file could not be opened : ") + nodeFileName ).c_str());
buffer->drop();
continue;
}
// first line data : innode >> nb_of_points >> dim >> nb_of_attr >> boundary_marker;
innode.read(reinterpret_cast < char * > (&nb_of_points), sizeof(int));
// we should have at least one tetrahedra (4 points) and each point should have 3 coordinates
if (nb_of_points > 65535 || nb_of_points < 4)
{
device->getLogger()->log("ERROR: a node file should not contain more than 65535 points and less than 4 points.");
buffer->drop();
continue;
}
device->getLogger()->log((stringw("Loading ")+stringw(nb_of_points)+L" points from "+stringw(nodeFileName.c_str())+L"...").c_str());
// default color
video::SColor clr(255,100,100,200);
// lets add the vertices to the buffer
buffer->Vertices.reallocate( nb_of_points );
// this is one line : innode >> index >> x >> y >> z;
innode.read(reinterpret_cast < char * > (&x), sizeof(yohan::base::DATA));
innode.read(reinterpret_cast < char * > (&y), sizeof(yohan::base::DATA));
innode.read(reinterpret_cast < char * > (&z), sizeof(yohan::base::DATA));
while (!innode.eof() && innode.good())// && (int)buffer->Vertices.size() < nb_of_points)
{
buffer->Vertices.push_back(video::S3DVertex((f32)x, (f32)y, (f32)z, 1,0,0, clr, 0,0));
// this is one line : innode >> index >> x >> y >> z;
innode.read(reinterpret_cast < char * > (&x), sizeof(yohan::base::DATA));
innode.read(reinterpret_cast < char * > (&y), sizeof(yohan::base::DATA));
innode.read(reinterpret_cast < char * > (&z), sizeof(yohan::base::DATA));
}
innode.close();
innode.clear();
// -----------------------------------------------------------------------
// lets check if verticies have been added well
if (buffer->Vertices.size() != nb_of_points)
{
device->getLogger()->log("ERROR: the node file does not seem to be valid.");
buffer->drop();
continue;
}
if (load_volumic)
{
// -----------------------------------------------------------------------
// - TETRAHEDRAS ---------------------------------------------------------
// -----------------------------------------------------------------------
// at first we check if the ele file has not been already opened
s32 eleLoadedIndex = -1;
for (u32 e=0; e < PlayerFrame::lastEleFileNames.size(); e++)
//.........这里部分代码省略.........
示例11: drawFrame
void drawFrame()
{
u32 i,color = 0;
Matrix4 rotX,rotY;
Vector4 objEyePos,objLightPos;
Matrix4 viewMatrix,modelMatrix,modelMatrixIT,modelViewMatrix;
Point3 lightPos = Point3(250.0f,150.0f,150.0f);
f32 globalAmbientColor[3] = {0.1f,0.1f,0.1f};
f32 lightColor[3] = {0.95f,0.95f,0.95f};
f32 materialColorDiffuse[3] = {0.5f,0.0f,0.0f};
f32 materialColorSpecular[3] = {0.7f,0.6f,0.6f};
f32 shininess = 17.8954f;
static f32 rot = 0.0f;
SMeshBuffer *mesh = NULL;
setTexture();
setDrawEnv();
rsxSetClearColor(context,color);
rsxSetClearDepthValue(context,0xffff);
rsxClearSurface(context,GCM_CLEAR_R |
GCM_CLEAR_G |
GCM_CLEAR_B |
GCM_CLEAR_A |
GCM_CLEAR_S |
GCM_CLEAR_Z);
rsxZControl(context,0,1,1);
for(i=0; i<8; i++)
rsxSetViewportClip(context,i,display_width,display_height);
viewMatrix = Matrix4::lookAt(eye_pos,eye_dir,up_vec);
mesh = sphere;
rotX = Matrix4::rotationX(DEGTORAD(30.0f));
rotY = Matrix4::rotationY(DEGTORAD(rot));
modelMatrix = rotX*rotY;
modelMatrixIT = inverse(modelMatrix);
modelViewMatrix = transpose(viewMatrix*modelMatrix);
objEyePos = modelMatrixIT*eye_pos;
objLightPos = modelMatrixIT*lightPos;
wait_signal_spu();
rsxBindVertexArrayAttrib(context,vertexPosition_id,mesh->pos_off,sizeof(S3DVertex),3,GCM_VERTEX_DATA_TYPE_F32,GCM_LOCATION_RSX);
rsxBindVertexArrayAttrib(context,vertexNormal_id,mesh->nrm_off,sizeof(S3DVertex),3,GCM_VERTEX_DATA_TYPE_F32,GCM_LOCATION_RSX);
rsxBindVertexArrayAttrib(context,vertexTexcoord_id,mesh->uv_off,sizeof(S3DVertex),2,GCM_VERTEX_DATA_TYPE_F32,GCM_LOCATION_RSX);
rsxLoadVertexProgram(context,vpo,vp_ucode);
rsxSetVertexProgramParameter(context,vpo,projMatrix_id,(float*)&P);
rsxSetVertexProgramParameter(context,vpo,modelViewMatrix_id,(float*)&modelViewMatrix);
rsxSetFragmentProgramParameter(context,fpo,eyePosition_id,(float*)&objEyePos,fp_offset);
rsxSetFragmentProgramParameter(context,fpo,globalAmbient_id,globalAmbientColor,fp_offset);
rsxSetFragmentProgramParameter(context,fpo,lightPosition_id,(float*)&objLightPos,fp_offset);
//rsxSetFragmentProgramParameter(context,fpo,lightColor_id,lightColor,fp_offset);
rsxSetFragmentProgramParameter(context,fpo,shininess_id,&shininess,fp_offset);
rsxSetFragmentProgramParameter(context,fpo,Kd_id,materialColorDiffuse,fp_offset);
rsxSetFragmentProgramParameter(context,fpo,Ks_id,materialColorSpecular,fp_offset);
rsxLoadFragmentProgramLocation(context,fpo,fp_offset,GCM_LOCATION_RSX);
rsxSetUserClipPlaneControl(context,GCM_USER_CLIP_PLANE_DISABLE,
GCM_USER_CLIP_PLANE_DISABLE,
GCM_USER_CLIP_PLANE_DISABLE,
GCM_USER_CLIP_PLANE_DISABLE,
GCM_USER_CLIP_PLANE_DISABLE,
GCM_USER_CLIP_PLANE_DISABLE);
rsxDrawIndexArray(context,GCM_TYPE_TRIANGLES,mesh->ind_off,mesh->getIndexCount(),GCM_INDEX_TYPE_32B,GCM_LOCATION_RSX);
mesh = donut;
rotX = Matrix4::rotationX(DEGTORAD(rot));
rotY = Matrix4::rotationY(DEGTORAD(30.0f));
modelMatrix = rotX*rotY;
modelMatrix.setTranslation(Vector3(3.0f,5.0f,-8.0f));
modelMatrixIT = inverse(modelMatrix);
modelViewMatrix = transpose(viewMatrix*modelMatrix);
objEyePos = modelMatrixIT*eye_pos;
objLightPos = modelMatrixIT*lightPos;
rsxBindVertexArrayAttrib(context,vertexPosition_id,mesh->pos_off,sizeof(S3DVertex),3,GCM_VERTEX_DATA_TYPE_F32,GCM_LOCATION_RSX);
rsxBindVertexArrayAttrib(context,vertexNormal_id,mesh->nrm_off,sizeof(S3DVertex),3,GCM_VERTEX_DATA_TYPE_F32,GCM_LOCATION_RSX);
rsxBindVertexArrayAttrib(context,vertexTexcoord_id,mesh->uv_off,sizeof(S3DVertex),2,GCM_VERTEX_DATA_TYPE_F32,GCM_LOCATION_RSX);
rsxLoadVertexProgram(context,vpo,vp_ucode);
rsxSetVertexProgramParameter(context,vpo,projMatrix_id,(float*)&P);
rsxSetVertexProgramParameter(context,vpo,modelViewMatrix_id,(float*)&modelViewMatrix);
rsxSetFragmentProgramParameter(context,fpo,eyePosition_id,(float*)&objEyePos,fp_offset);
rsxSetFragmentProgramParameter(context,fpo,globalAmbient_id,globalAmbientColor,fp_offset);
rsxSetFragmentProgramParameter(context,fpo,lightPosition_id,(float*)&objLightPos,fp_offset);
rsxSetFragmentProgramParameter(context,fpo,lightColor_id,lightColor,fp_offset);
rsxSetFragmentProgramParameter(context,fpo,shininess_id,&shininess,fp_offset);
//.........这里部分代码省略.........
示例12: SMesh
//! creates/loads an animated mesh from the file.
//! \return Pointer to the created mesh. Returns 0 if loading failed.
//! If you no longer need the mesh, you should call IAnimatedMesh::drop().
//! See IReferenceCounted::drop() for more information.
IAnimatedMesh* CSTLMeshFileLoader::createMesh(io::IReadFile* file)
{
const long filesize = file->getSize();
if (filesize < 6) // we need a header
return 0;
const u32 WORD_BUFFER_LENGTH = 512;
SMesh* mesh = new SMesh();
SMeshBuffer* meshBuffer = new SMeshBuffer();
mesh->addMeshBuffer(meshBuffer);
meshBuffer->drop();
core::vector3df vertex[3];
core::vector3df normal;
c8 buffer[WORD_BUFFER_LENGTH];
bool binary = false;
file->read(buffer, 5);
if (strncmp("solid", buffer, 5))
binary = true;
// read/skip header
u32 binFaceCount = 0;
if (binary)
{
file->seek(80);
file->read(&binFaceCount, 4);
#ifdef __BIG_ENDIAN__
binFaceCount = os::Byteswap::byteswap(binFaceCount);
#endif
}
else
goNextLine(file);
u16 attrib=0;
core::stringc token;
token.reserve(32);
while (file->getPos() < filesize)
{
if (!binary)
{
if (getNextToken(file, token) != "facet")
{
if (token=="endsolid")
break;
mesh->drop();
return 0;
}
if (getNextToken(file, token) != "normal")
{
mesh->drop();
return 0;
}
}
getNextVector(file, normal, binary);
if (!binary)
{
if (getNextToken(file, token) != "outer")
{
mesh->drop();
return 0;
}
if (getNextToken(file, token) != "loop")
{
mesh->drop();
return 0;
}
}
for (u32 i=0; i<3; ++i)
{
if (!binary)
{
if (getNextToken(file, token) != "vertex")
{
mesh->drop();
return 0;
}
}
getNextVector(file, vertex[i], binary);
}
if (!binary)
{
if (getNextToken(file, token) != "endloop")
{
mesh->drop();
return 0;
}
if (getNextToken(file, token) != "endfacet")
{
mesh->drop();
return 0;
}
}
else
//.........这里部分代码省略.........
示例13: crosses
//.........这里部分代码省略.........
}
};
Visitor visitor;
tree.triangulate(triangles, section, min_height, max_height, &visitor);
//tree.sweep(triangles, section, &visitor);
//cout << "num triangle points: " << triangles.size() << endl;
vector<QuadTreePtr> leaves;
tree.dumpLeaves(leaves);
//cout << "num leaves: " << leaves.size() << endl;
/*
for (QuadTreePtr p1 : leaves)
for (QuadTreePtr p2 : leaves)
if (p1 != p2)
if (p1->isAdjacent(p2))
if (!visitor.has(p1, p2))
{
auto sz1 = p1->region.getSize();
auto sz2 = p2->region.getSize();
auto c1 = p1->region.getCenter();
auto c2 = p2->region.getCenter();
char const* path1 = p1->getPath().c_str();
char const* path2 = p2->getPath().c_str();
cout << path1 << endl;
cout << path2 << endl;
cout << "Missing pair of adjacent vertices." << endl;
}
float x1 = section.UpperLeftCorner.X;
float x2 = section.LowerRightCorner.X;
float y1 = section.UpperLeftCorner.Y;
float y2 = section.LowerRightCorner.Y;
*/
/*
d---c
| / |
a---b
*/
/*
S3DVertex sa;
sa.Pos = vector3df(x1, y1, 0);
PsblVertPtr a = new PossibleVertex(sa);
S3DVertex sb;
sb.Pos = vector3df(x2, y1, 0);
PsblVertPtr b = new PossibleVertex(sb);
S3DVertex sc;
sc.Pos = vector3df(x2, y2, 0);
PsblVertPtr c = new PossibleVertex(sc);
S3DVertex sd;
sd.Pos = vector3df(x1, y2, 0);
PsblVertPtr d = new PossibleVertex(sd);
// a-b-c
// a-c-d
triangles.push_back(a);
triangles.push_back(b);
triangles.push_back(c);
triangles.push_back(a);
triangles.push_back(c);
triangles.push_back(d);
triangles.push_back(c);
triangles.push_back(b);
triangles.push_back(a);
triangles.push_back(d);
triangles.push_back(c);
triangles.push_back(a);
*/
SMeshBuffer* buffer = new SMeshBuffer();
for (auto pv : triangles)
pv->addToMeshBuf(buffer, vector3df());
if (buffer->getIndexCount() % 3 > 0)
throw std::logic_error("SurfaceQuadTree triangulation added a 'triangle' with less than 3 vertices in it.");
//cout << "num vertices " << buffer->getVertexCount() << endl;
//cout << "num indices " << buffer->getIndexCount() << endl;
buffer->recalculateBoundingBox();
buffer->setHardwareMappingHint(EHM_STATIC);
SMesh* mesh = new SMesh();
mesh->addMeshBuffer(buffer);
mesh->recalculateBoundingBox();
buffer->drop();
return mesh;
}
示例14: vector2di
IMesh* MeshTools::createMeshFromHeightmap(IImage* image, dimension2du tileSizeInPixels, vector2di tilePosInTiles, bool extraStripsOnEdges)
{
// Use top corner of image to get bias for centering the Z axis.
float imageZeroBias = image->getPixel(0,0).getAverage();
dimension2du imageDimension = image->getDimension();
// Easier to think of script working in whole tile units, so handle conversion to pixel pos in this method:
vector2di startAtPixel = tilePosInTiles * vector2di(tileSizeInPixels.Width, tileSizeInPixels.Height);
// However we're going to invert the image Y axis so that the bottom of the picture will be at 0,0 in world space,
// and the top of the picture will be at +Y in world space.
startAtPixel.Y = (imageDimension.Height-1) - startAtPixel.Y;
// Return nothing if the tile is outside the image, or if the resulting mesh would have only 0 or 1 rows or columns.
// Doing this check early prevents getting underflow when we clip the tile size to the image dimensions a few statements down.
if (startAtPixel.X < 0 || startAtPixel.X >= (imageDimension.Width-1) || startAtPixel.Y <= 0 || startAtPixel.Y > (imageDimension.Height-1))
return NULL;
// Calculate whether to use tile size or tile size + 1 (for generating overlap)
// Adding the extra strip amount before clipping to image dimensions prevents overflowing the image edges after clipping.
dimension2du useTileSize = tileSizeInPixels + (extraStripsOnEdges? dimension2du(1,1) : dimension2du(0,0));
// Clip the tile size if we're dealing with a "leftover" amount at the edge that's not a whole tile's width or height.
// Most heightmap implementations require exactly a power of 2 + 1 square dimensions like 257x257, but supporting
// image sizes that are not whole multiples of tile size is as simple as this one line of code and supporting
// image sizes that are not square is a nice feature for a platformer game so you can have levels that are longer
// than they are tall.
useTileSize.set(min(useTileSize.Width, imageDimension.Width-startAtPixel.X), min(useTileSize.Height, (u32)startAtPixel.Y+1));
SMeshBuffer* buffer = new SMeshBuffer();
// Preallocate vertex buffer to the size we know we'll need.
buffer->Vertices.set_used(useTileSize.Width*useTileSize.Height);
// Amount of TCoord per unit of x,y in image.
vector2df tCoordsScale(1.0f / useTileSize.Width, 1.0f / useTileSize.Height);
// Whether we put y on the outside or x on the outside, doesn't matter, because we are
// using getIndex() to find where x and y map too. However, I happen to know I made getIndex
// put x's together, y in rows, and looping in the same rank order might have better cache performance
// because it should access the vertices in the same order they are in the array.
for (u32 y=0; y < useTileSize.Height; ++y)
{
for (u32 x=0; x < useTileSize.Width; ++x)
{
u32 index = getIndex(useTileSize, x, y);
S3DVertex& vert = buffer->Vertices[index];
// No special coloration
vert.Color = SColor(255,255,255,255);
// Scale texture to tile.
vert.TCoords = vector2df(x,y) * tCoordsScale;
// y axis starts with 0 at image bottom and goes up.
vector2di pixelPos(
startAtPixel.X+x,
startAtPixel.Y-y
);
SColor heightColor = image->getPixel(pixelPos.X, pixelPos.Y);
float thisHeight = imageZeroBias - heightColor.getAverage();
vert.Pos.set(x, y, thisHeight);
// I'm only averaging normals along the 4 compass directions. It's
// arguable whether diagonals should count; I chose to ignore diagonals.
// Ignoring diagonals allows me to assume the "run" in rise/run is always
// just one unit; if you add diagonals here you'll also need to change
// the slope calculation to use the actual distance instead of assuming 1.
vector2di offsetsArray[] = {
vector2di( 1, 0), // 3 o'clock
vector2di( 0, 1), // 12 o'clock
vector2di(-1, 0), // 9 o'clock
vector2di( 0,-1) // 6 o'clock
};
// Calculate the normals of the surrounding slopes.
// Uses the image, not just the tile patch size, so it will
// calculate correct normals for vertices on tile edges.
for (size_t i=-0; i < 4; ++i)
{
vector2di offset = vector2di(x,y) + offsetsArray[i];
// Skip this offset if it's outside the image
if (offset.X < 0 || offset.Y < 0 || offset.X >= (s32)imageDimension.Width || offset.Y >= (s32)imageDimension.Height)
continue;
vector2di otherPixelPos(
startAtPixel.X+x+offset.X,
startAtPixel.Y-y-offset.Y
);
float otherHeight = 255 - image->getPixel((u32)otherPixelPos.X, (u32)otherPixelPos.Y).getAverage();
// The code Irrlicht's in terrain scene node does all kinds of complicated
// business with cross products and such - waaay over complicated. You don't need
// all that stuff. Dude it' s a heightmap: all you need to worray about is
// rise over run on unit intervals! Algebra 1 type stuff, y = mx + c
//.........这里部分代码省略.........
示例15: SMeshBuffer
// creates a hill plane
IAnimatedMesh* CGeometryCreator::createHillPlaneMesh(const core::dimension2d<f32>& tileSize, const core::dimension2d<s32>& tc,
video::SMaterial* material, f32 hillHeight, const core::dimension2d<f32>& ch,
const core::dimension2d<f32>& textureRepeatCount)
{
core::dimension2d<s32> tileCount = tc;
tileCount.Height += 1;
tileCount.Width += 1;
core::dimension2d<f32> countHills = ch;
SMeshBuffer* buffer = new SMeshBuffer();
SMesh* mesh = new SMesh();
video::S3DVertex vtx;
vtx.Color.set(255,255,255,255);
vtx.Normal.set(0,0,0);
if (countHills.Width < 0.01f) countHills.Width = 1;
if (countHills.Height < 0.01f) countHills.Height = 1;
f32 halfX = (tileSize.Width * tileCount.Width) / 2;
f32 halfY = (tileSize.Height * tileCount.Height) / 2;
// create vertices
s32 x = 0;
s32 y = 0;
core::dimension2d<f32> tx;
tx.Width = 1.0f / (tileCount.Width / textureRepeatCount.Width);
tx.Height = 1.0f / (tileCount.Height / textureRepeatCount.Height);
for (x=0; x<tileCount.Width; ++x)
for (y=0; y<tileCount.Height; ++y)
{
vtx.Pos.set(tileSize.Width * x - halfX, 0, tileSize.Height * y - halfY);
vtx.TCoords.set(-(f32)x * tx.Width, (f32)y * tx.Height);
if (hillHeight)
vtx.Pos.Y = (f32)(sin(vtx.Pos.X * countHills.Width * engine::core::PI / halfX) *
cos(vtx.Pos.Z * countHills.Height * engine::core::PI / halfY))
*hillHeight;
buffer->Vertices.push_back(vtx);
}
// create indices
for (x=0; x<tileCount.Width-1; ++x)
for (y=0; y<tileCount.Height-1; ++y)
{
s32 current = y*tileCount.Width + x;
buffer->Indices.push_back(current);
buffer->Indices.push_back(current + 1);
buffer->Indices.push_back(current + tileCount.Width);
buffer->Indices.push_back(current + 1);
buffer->Indices.push_back(current + 1 + tileCount.Width);
buffer->Indices.push_back(current + tileCount.Width);
}
// recalculate normals
for (s32 i=0; i<(s32)buffer->Indices.size(); i+=3)
{
core::plane3d<f32> p(
buffer->Vertices[buffer->Indices[i+0]].Pos,
buffer->Vertices[buffer->Indices[i+1]].Pos,
buffer->Vertices[buffer->Indices[i+2]].Pos);
p.Normal.normalize();
buffer->Vertices[buffer->Indices[i+0]].Normal = p.Normal;
buffer->Vertices[buffer->Indices[i+1]].Normal = p.Normal;
buffer->Vertices[buffer->Indices[i+2]].Normal = p.Normal;
}
if (material)
buffer->Material = *material;
buffer->recalculateBoundingBox();
SAnimatedMesh* animatedMesh = new SAnimatedMesh();
mesh->addMeshBuffer(buffer);
mesh->recalculateBoundingBox();
animatedMesh->addMesh(mesh);
animatedMesh->recalculateBoundingBox();
mesh->drop();
buffer->drop();
return animatedMesh;
}