MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Draw

Method Draw

Source/Engine/Level/Actors/SplineModel.cpp:385–479  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

383}
384
385void SplineModel::Draw(RenderContext& renderContext)
386{
387 const DrawPass actorDrawModes = DrawModes & renderContext.View.Pass;
388 if (!_spline || !Model || !Model->IsLoaded() || !Model->CanBeRendered() || actorDrawModes == DrawPass::None)
389 return;
390 auto model = Model.Get();
391 if (renderContext.View.Pass == DrawPass::GlobalSDF)
392 return; // TODO: Spline Model rendering to Global SDF
393 if (renderContext.View.Pass == DrawPass::GlobalSurfaceAtlas)
394 return; // TODO: Spline Model rendering to Global Surface Atlas
395 if (!Entries.IsValidFor(model))
396 Entries.Setup(model);
397
398 // Build mesh deformation buffer for the whole spline
399 if (_deformationDirty)
400 {
401 RenderContext::GPULocker.Lock();
402 UpdateDeformationBuffer();
403 RenderContext::GPULocker.Unlock();
404 }
405
406 // Draw all segments
407 DrawCall drawCall;
408 drawCall.InstanceCount = 1;
409 drawCall.Deformable.SplineDeformation = _deformationBuffer;
410 drawCall.Deformable.ChunksPerSegment = _chunksPerSegment;
411 drawCall.Deformable.MeshMinZ = _meshMinZ;
412 drawCall.Deformable.MeshMaxZ = _meshMaxZ;
413 drawCall.Deformable.GeometrySize = _box.GetSize();
414 drawCall.PerInstanceRandom = GetPerInstanceRandom();
415 drawCall.SetStencilValue(_layer);
416 _preTransform.GetWorld(drawCall.Deformable.LocalMatrix);
417 const Transform splineTransform = GetTransform();
418 renderContext.View.GetWorldMatrix(splineTransform, drawCall.World);
419 drawCall.ObjectPosition = drawCall.World.GetTranslation() + drawCall.Deformable.LocalMatrix.GetTranslation();
420 drawCall.ObjectRadius = (float)_sphere.Radius; // TODO: use radius for the spline chunk rather than whole spline
421 for (int32 segment = 0; segment < _instances.Count(); segment++)
422 {
423 auto& instance = _instances[segment];
424 BoundingSphere instanceSphere(instance.Sphere.Center - renderContext.View.Origin, instance.Sphere.Radius);
425 if (!(renderContext.View.IsCullingDisabled || renderContext.View.CullingFrustum.Intersects(instanceSphere)))
426 continue;
427 drawCall.Deformable.Segment = (float)segment;
428
429 // Select a proper LOD index (model may be culled)
430 int32 lodIndex;
431 if (_forcedLod != -1)
432 {
433 lodIndex = _forcedLod;
434 }
435 else
436 {
437 lodIndex = RenderTools::ComputeModelLOD(model, instanceSphere.Center, (float)instanceSphere.Radius, renderContext);
438 if (lodIndex == -1)
439 continue;
440 }
441 lodIndex += _lodBias + renderContext.View.ModelLODBias;
442 lodIndex = model->ClampLODIndex(lodIndex);

Callers

nothing calls this directly

Calls 15

IsValidForMethod · 0.80
LockMethod · 0.80
UnlockMethod · 0.80
GetDrawCallGeometryMethod · 0.80
AddDrawCallMethod · 0.80
IsLoadedMethod · 0.45
GetMethod · 0.45
SetupMethod · 0.45
GetSizeMethod · 0.45
SetStencilValueMethod · 0.45
GetWorldMethod · 0.45

Tested by

no test coverage detected