当前位置: 首页>>代码示例>>C++>>正文


C++ SubMesh::GetMaterial方法代码示例

本文整理汇总了C++中SubMesh::GetMaterial方法的典型用法代码示例。如果您正苦于以下问题:C++ SubMesh::GetMaterial方法的具体用法?C++ SubMesh::GetMaterial怎么用?C++ SubMesh::GetMaterial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SubMesh的用法示例。


在下文中一共展示了SubMesh::GetMaterial方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _update

	void PS_Mesh::_update(Particle * p)
	{
		Float3 Position = p->Position;
		if (mParent->IsLocalSpace())
			Position.TransformA(mParent->GetParent()->GetWorldTM());

		mMesh->SetPosition(Position);
		mMesh->SetOpacity(p->Color.a);
		mMesh->SetRotationEx(p->Rotation);
		mMesh->SetScale(p->Size);
		mMesh->_updateTM();

		int blendMode = mParent->GetBlendMode();

		for (int i = 0; i < mMesh->GetSubMeshCount(); ++i)
		{
			SubMesh * submesh = mMesh->GetSubMesh(i);
			Material * mtl = submesh->GetMaterial();
			
			mtl->diffuse = Float3(p->Color.r, p->Color.g, p->Color.b);
			if (mParent->_getTexture() != NULL)
			{
				mtl->maps[eMapType::DIFFUSE] = mParent->_getTexture();
			}

			if (mParent->GetShaderEnable())
			{
				mtl->depthMode = eDepthMode::N_LESS_EQUAL;

				if (blendMode == PS_BlendMode::ADD)
				{
					mtl->blendMode = eBlendMode::ADD;
				}
				else if (blendMode == PS_BlendMode::ALPHA_BLEND)
				{
					mtl->blendMode = eBlendMode::ALPHA_BLEND;
				}
				else if (blendMode == PS_BlendMode::COLOR_BLEND)
				{
					mtl->blendMode = eBlendMode::COLOR_BLEND;
				}
				else
				{
					mtl->blendMode = eBlendMode::OPACITY;
					mtl->depthMode = eDepthMode::LESS_EQUAL;
				}

				submesh->SetShaderFX(mParent->_getShaderFX());
				submesh->SetRenderCallBack(eRenderCallBack::SHADER, mParent->GetShader().c_ptr());
			}
		}
	}
开发者ID:MSoft1115,项目名称:Rad3D,代码行数:52,代码来源:PSMesh.cpp

示例2: _genMesh

	void MeshGroup::_genMesh(const Array<Mesh *> & arr, int first, int last, bool hasLightingColor)
	{
		MeshSourcePtr source = arr[0]->GetSource();
		Mesh * mesh = new Mesh;

		for (int i = 0; i < source->GetMeshBufferCount(); ++i)
		{
			SubMesh * submesh = mesh->NewSubMesh();
			VertexBufferPtr srcVB = source->GetMeshBuffer(i)->GetRenderOp()->vertexBuffers[0];
			IndexBufferPtr srcIB = source->GetMeshBuffer(i)->GetRenderOp()->indexBuffer;
			int p_offset = source->GetMeshBuffer(i)->GetRenderOp()->vertexDeclarations[0].GetElementOffset(eVertexSemantic::POSITION);
			int n_offset = source->GetMeshBuffer(i)->GetRenderOp()->vertexDeclarations[0].GetElementOffset(eVertexSemantic::NORMAL);
			int stride = srcVB->GetStride();

			VertexBufferPtr vb = HWBufferManager::Instance()->NewVertexBuffer(stride, srcVB->GetCount() * (last - first));
			
			const char * v_src = (const char *)srcVB->Lock(eLockFlag::READ);
			char * v_dest = (char *)vb->Lock(eLockFlag::WRITE);
			for (int j = first; j < last; ++j)
			{
				const Mat4 & worldTM = arr[j]->GetWorldTM();
				bool hasScale = arr[j]->GetWorldScale() != Float3(1, 1, 1);

				for (int k = 0; k < srcVB->GetCount(); ++k)
				{
					memcpy(v_dest, v_src, stride);

					Float3 * position = (Float3 *)(v_dest + p_offset);
					position->TransformA(worldTM);
					
					if (n_offset != -1)
					{
						Float3 * normal = (Float3 *)(v_dest + n_offset);
						normal->TransformN(worldTM);

						if (hasScale)
						{
							normal->Normalize();
						}
					}

					v_dest += stride;
					v_src += stride;
				}
			}
			vb->Unlock();
			srcVB->Unlock();

			IndexBufferPtr ib = HWBufferManager::Instance()->NewIndexBuffer(srcIB->GetCount() * (last - first));

			int startVertex = 0;
			const short * i_src = (const short *)srcIB->Lock(eLockFlag::READ);
			char * i_dest = (char *)ib->Lock(eLockFlag::WRITE);
			for (int j = first; j < last; ++j)
			{
				for (int k = 0; k < srcIB->GetCount(); ++k)
				{
					*i_dest++ = (*i_src++) + startVertex;
				}

				startVertex += srcVB->GetCount();
			}
			ib->Unlock();
			srcIB->Unlock();
			
			submesh->GetRenderOp()->vertexDeclarations[0] = source->GetMeshBuffer(i)->GetRenderOp()->vertexDeclarations[0];
			submesh->GetRenderOp()->vertexBuffers[0] = vb;
			submesh->GetRenderOp()->indexBuffer = ib;
			submesh->GetRenderOp()->primCount = ib->GetCount() / 3;
			submesh->GetRenderOp()->primType = ePrimType::TRIANGLE_LIST;

			if (hasLightingColor)
			{
				int count = submesh->GetRenderOp()->vertexBuffers[0]->GetCount();
				submesh->GetRenderOp()->vertexDeclarations[LIGHTING_COLOR_STREAM].AddElement(eVertexSemantic::LIGHTING_COLOR, eVertexType::UBYTE4);
				submesh->GetRenderOp()->vertexBuffers[LIGHTING_COLOR_STREAM] = HWBufferManager::Instance()->NewVertexBuffer(4, count);

				Array<Rgba32> lightColors;
				Rgba32 * data = (Rgba32 *)submesh->GetRenderOp()->vertexBuffers[LIGHTING_COLOR_STREAM]->Lock(eLockFlag::WRITE);
				for (int j = first; j < last; ++j)
				{
					arr[j]->GetLightingColor(lightColors);
					d_assert (lightColors.Size() > 0);

					memcpy(data, &lightColors[0], 4 * count);

					startVertex += count;
					lightColors.Clear();
				}
				submesh->GetRenderOp()->vertexBuffers[LIGHTING_COLOR_STREAM]->Unlock();
			}

			*submesh->GetMaterial() = *source->GetMeshBuffer(i)->GetMaterial();

			submesh->SetMeshShader(source->GetMeshBuffer(i)->GetShader());
		}

		mesh->SetSLMode(hasLightingColor ? eStaticLightingMode::LIGHTING_COLOR : eStaticLightingMode::NONE);

		mMeshes.PushBack(mesh);
//.........这里部分代码省略.........
开发者ID:MSoft1115,项目名称:Rad3D,代码行数:101,代码来源:MMeshGroup.cpp

示例3:

	Mesh * PS_MeshSet::_createClinder()
	{
		Float3 offset = mCenter;
		int rings = mRings;
		float radius = mRadius;
		float height = mHeight;

		if (rings < 1)
			return NULL;

		Mesh * pMesh = new Mesh;
		SubMesh * sm = pMesh->NewSubMesh();

		int iVertexCount = (rings + 1) * 2;
		int iIndexCount = rings * 6;
		int iPrimCount = iIndexCount / 3;

		d_assert(iIndexCount < 65536);

		sm->GetRenderOp()->vertexDeclarations[0].AddElement(eVertexSemantic::POSITION, eVertexType::FLOAT3);
		sm->GetRenderOp()->vertexDeclarations[0].AddElement(eVertexSemantic::TEXCOORD0, eVertexType::FLOAT2);

		VertexBufferPtr buffer = HWBufferManager::Instance()->NewVertexBuffer(20, iVertexCount);

		float * vert = (float *)buffer->Lock(eLockFlag::WRITE);
		{
			float r_step = (2 * PI / rings);
			float u_step = 1 / (float)rings;
			float x, z, rads;

			for (int i = 0; i <= rings; ++i)
			{
				rads = i * r_step;

				Math::SinCos(rads, z, x);

				x *= radius;
				z *= radius;

				*vert++ = x + offset.x;
				*vert++ = 0 + offset.y;
				*vert++ = z + offset.z;
				*vert++ = i * u_step;
				*vert++ = 1;

				*vert++ = x + offset.x;
				*vert++ = height + offset.y;
				*vert++ = z + offset.z;
				*vert++ = i * u_step;
				*vert++ = 0;
			}
		}
		buffer->Unlock();

		IndexBufferPtr ibuffer = HWBufferManager::Instance()->NewIndexBuffer(iIndexCount);
		short * indices = (short *)ibuffer->Lock(eLockFlag::WRITE);
		{
			for (short i = 0; i < rings; ++i)
			{
				int j = i * 2;

				*indices++ = j;
				*indices++ = j + 1;
				*indices++ = j + 2;

				*indices++ = j + 2;
				*indices++ = j + 1;
				*indices++ = j + 3;
			}
		}
		ibuffer->Unlock();

		sm->GetRenderOp()->vertexBuffers[0] = buffer;
		sm->GetRenderOp()->indexBuffer = ibuffer;
		sm->GetRenderOp()->primType = ePrimType::TRIANGLE_LIST;
		sm->GetRenderOp()->primCount = iPrimCount;

		sm->GetMaterial()->cullMode = eCullMode::NONE;
		sm->GetMaterial()->maps[eMapType::DIFFUSE] = RenderHelper::Instance()->GetWhiteTexture();

		pMesh->SetLocalAabb(Aabb(Float3(-radius, 0, -radius) + offset, Float3(radius, height, radius) + offset));

		return pMesh;
	}
开发者ID:MSoft1115,项目名称:Rad3D,代码行数:84,代码来源:PSMeshSet.cpp


注:本文中的SubMesh::GetMaterial方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。