Example #1
0
void AHair::UpdateSegment(AHairSegment* InSegment)
{
	if (!InSegment || InSegment->Spline->GetNumberOfSplinePoints() < 2) return;
	InSegment->ProceduralMesh->ClearAllMeshSections();
	ClearMeshData(InSegment);

	// Update node rotations to match spline
	for (int i = 0; i < InSegment->Spline->GetNumberOfSplinePoints(); i++)
	{
		FRotator Rot = InSegment->Spline->GetRotationAtSplinePoint(i, ESplineCoordinateSpace::World);
		InSegment->Nodes[i]->SetActorRotation(Rot);
	}

	// Populate new data
	if (!MiddleMeshData) return;
	for (int i = 0; i <= InSegment->NumSegments; i++)
	{
		float TotalDistance = InSegment->Spline->GetSplineLength();
		float Distance = (TotalDistance / InSegment->NumSegments)*i;
		float NextDistance = (TotalDistance / InSegment->NumSegments)*i+1;
		AssignPositions(InSegment->Spline->GetLocationAtDistanceAlongSpline(Distance, ESplineCoordinateSpace::Local),
			InSegment->Spline->GetLocationAtDistanceAlongSpline(NextDistance, ESplineCoordinateSpace::Local));

		//Weight = 1.0f - Distance / TotalDistance;
		
		float Displacement = InSegment->FallOff - 1.0f;
		Weight = 1.0f + (Distance / TotalDistance)*Displacement;

		// Interpolate distance to closest spline point index
		float Delta = ((InSegment->Spline->GetNumberOfSplinePoints() - 1)*1.0f) / (InSegment->NumSegments*1.0f);
		int Index = FGenericPlatformMath::RoundToInt(i*Delta);
		if (i == 0)
		{
			AddVertices(0, MiddleMeshData->Vertices, InSegment, Distance);
			AddTriangles(InSegment);
			AddUVs(InSegment, true);
		}
		else
		{
			AddVertices(2, MiddleMeshData->Vertices, InSegment, Distance);
			AddTriangles(InSegment);
			AddUVs(InSegment, false);
		}
	}
	// Create mesh 
	InSegment->ProceduralMesh->CreateMeshSection(0, InSegment->ProceduralMeshData->Vertices,
													InSegment->ProceduralMeshData->Triangles,
													TArray<FVector>(), 
													InSegment->ProceduralMeshData->UVs,
													TArray<FColor>(), TArray<FProcMeshTangent>(), true);
	// Duplicate for outline as custom depth not available for translucent materials
	InSegment->OutlineMesh->CreateMeshSection(0, InSegment->ProceduralMeshData->Vertices,
													InSegment->ProceduralMeshData->Triangles,
													TArray<FVector>(),
													InSegment->ProceduralMeshData->UVs,
													TArray<FColor>(), TArray<FProcMeshTangent>(), true);
}
Example #2
0
/*
 * Assign positions starting at a particular value.
 */
static int AssignPositions(TreeCCNode *node, int posn)
{
	TreeCCNode *child;

	/* Assign positions to the children */
	child = node->firstChild;
	while(child != 0)
	{
		posn = AssignPositions(child, posn);
		child = child->nextSibling;
	}

	/* Assign a position to this node */
	node->position = posn;
	return posn + 1;
}
Example #3
0
App::App(std::wstring app_name, int window_width, int window_height):
m_background(L"images/background.bmp")
{
	if (!m_positions_assigned) {
		AssignPositions();

		m_positions_assigned = true;
	}

	srand(time(NULL));

	m_app_name = app_name;
	m_window_width = window_width;
	m_window_height = window_height;

	// Making 5 bunnies initially
	for (int i = 0; i < 5; i++) {
		Bunny* temp_bunny = new Bunny;
		
		temp_bunny->set_pos(FindFreePos());

		m_bunnies.push_back(temp_bunny);
	}
}
Example #4
0
int TreeCCNodeAssignPositions(TreeCCNode *node)
{
	return AssignPositions(node, 0);
}