void ABranchingLinesActor::GenerateMesh()
{
	// -------------------------------------------------------
	// Setup the random number generator and create the branching structure
	RngStream = FRandomStream::FRandomStream(RandomSeed);
	CreateSegments();

	// The number of vertices or polygons wont change at runtime, so we'll just allocate the arrays once
	if (!bHaveBuffersBeenInitialized)
	{
		SetupMeshBuffers();
		bHaveBuffersBeenInitialized = true;
	}

	// -------------------------------------------------------
	// Now lets loop through all the defined segments and create a cylinder for each
	int32 VertexIndex = 0;
	int32 TriangleIndex = 0;

	for (int32 i = 0; i < Segments.Num(); i++)
	{
		GenerateCylinder(Vertices, Triangles, Segments[i].Start, Segments[i].End, Segments[i].Width, RadialSegmentCount, VertexIndex, TriangleIndex, bSmoothNormals);
	}

	MeshComponent->ClearAllMeshSections();
	MeshComponent->CreateMeshSection(0, Vertices, Triangles, GetBounds(), false, EUpdateFrequency::Infrequent);
	MeshComponent->SetMaterial(0, Material);
}
Exemplo n.º 2
0
void Ass3::BuildGeometryBuffers()
{
	//create mesh object
	GeometryGenerator::MeshData myMesh;
	GenerateCylinder(myMesh, sliceCount, cylinderRadius, cylinderHeight, 0.0f);
	vertexCount = myMesh.Vertices.size();
	//set vertex settings
	std::vector<Vertex> vertices(vertexCount);
	UINT k = 0;
	for (size_t i = 0; i < vertexCount; ++i, ++k)
	{
		vertices[k].Pos = myMesh.Vertices[i].Position;
		vertices[k].Color = XMFLOAT4((i/(float)vertexCount), (i / (float)vertexCount), (i / (float)vertexCount), 1.0f);
	}
	
	//apply vertices
	D3D11_BUFFER_DESC vbd;
	vbd.Usage = D3D11_USAGE_DYNAMIC;
	vbd.ByteWidth = sizeof(Vertex) * vertexCount;
	vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	vbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	vbd.MiscFlags = 0;
	D3D11_SUBRESOURCE_DATA vinitData;
	vinitData.pSysMem = &vertices[0];
	HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mBoxVB));

	//create indices
	std::vector<UINT> indices;
	indices.insert(indices.end(), myMesh.Indices.begin(), myMesh.Indices.end());
	indexCount = myMesh.Indices.size();

	//apply indices
	D3D11_BUFFER_DESC ibd;
	ibd.Usage = D3D11_USAGE_IMMUTABLE;
	ibd.ByteWidth = sizeof(UINT) * indexCount;
	ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
	ibd.CPUAccessFlags = 0;
	ibd.MiscFlags = 0;
	ibd.StructureByteStride = 0;
	D3D11_SUBRESOURCE_DATA iinitData;
	iinitData.pSysMem = &indices[0];
	HR(md3dDevice->CreateBuffer(&ibd, &iinitData, &mBoxIB));	
}
void ASimpleCylinderActor::GenerateMesh()
{
	if (Height <= 0)
	{
		MeshComponent->ClearAllMeshSections();
		return;
	}

	// The number of vertices or polygons wont change at runtime, so we'll just allocate the arrays once
	if (!bHaveBuffersBeenInitialized)
	{
		SetupMeshBuffers();
		bHaveBuffersBeenInitialized = true;
	}

	FBox BoundingBox = FBox(FVector(-Radius, -Radius, 0), FVector(Radius, Radius, Height));
	GenerateCylinder(Vertices, Triangles, Height, Radius, RadialSegmentCount, bCapEnds, bDoubleSided, bSmoothNormals);
	
	MeshComponent->ClearAllMeshSections();
	MeshComponent->CreateMeshSection(0, Vertices, Triangles, BoundingBox, false, EUpdateFrequency::Infrequent);
	MeshComponent->SetMaterial(0, Material);
}