Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gpu instancing check if tags not null #79

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions src/GPUTileHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,24 @@ public static byte[] GetGPUTile(List<Instance> instances, bool UseScaleNonUnifor
settings.GpuMeshInstancingMinCount = 0;
var model = sceneBuilder.ToGltf2(settings);

var schema = AddMetadataSchema(model);

var distinctModels = instances.Select(s => s.Model).Distinct();
// check if one of the instances has tags
if (instances.Any(s => s.Tags != null))
{
var schema = AddMetadataSchema(model);

var i = 0;
var distinctModels = instances.Select(s => s.Model).Distinct();

foreach (var distinctModel in distinctModels)
{
var modelInstances = instances.Where(s => s.Model.Equals(distinctModel)).ToList();
var featureIdBuilder = GetFeatureIdBuilder(schema, modelInstances);
var node = model.LogicalNodes[i];
node.AddInstanceFeatureIds(featureIdBuilder);
i++;
var i = 0;

foreach (var distinctModel in distinctModels)
{
var modelInstances = instances.Where(s => s.Model.Equals(distinctModel)).ToList();
var featureIdBuilder = GetFeatureIdBuilder(schema, modelInstances);
var node = model.LogicalNodes[i];
node.AddInstanceFeatureIds(featureIdBuilder);
i++;
}
}

foreach (var node in model.LogicalNodes)
Expand Down Expand Up @@ -83,17 +88,28 @@ private static SceneBuilder AddModels(IEnumerable<Instance> instances, Vector3 t
return sceneBuilder;
}


private static void AddModelInstancesToScene(SceneBuilder sceneBuilder, IEnumerable<Instance> instances, bool UseScaleNonUniform, Vector3 translation, string model)
{
var modelInstances = instances.Where(s => s.Model.Equals(model)).ToList();
var modelRoot = ModelRoot.Load(model);
var meshBuilder = modelRoot.LogicalMeshes.First().ToMeshBuilder(); // todo: what if there are multiple meshes?
var pointId = 0;

var meshbuilders = new List<IMeshBuilder<MaterialBuilder>>();
foreach (var mesh in modelRoot.LogicalMeshes)
{
var meshBuilder = mesh.ToMeshBuilder();
meshbuilders.Add(meshBuilder);
}

foreach (var instance in modelInstances)
{
var sceneBuilderModel = GetSceneBuilder(meshBuilder, instance, UseScaleNonUniform, translation, pointId);
sceneBuilder.AddScene(sceneBuilderModel, Matrix4x4.Identity);
foreach (var meshBuilder in meshbuilders)
{
var sceneBuilderModel = GetSceneBuilder(meshBuilder, instance, UseScaleNonUniform, translation, pointId);
sceneBuilder.AddScene(sceneBuilderModel, Matrix4x4.Identity);
}

pointId++;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ImplicitTiling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using subtree;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Wkx;
Expand Down Expand Up @@ -95,8 +96,7 @@ private static byte[] CreateTile(Options o, NpgsqlConnection conn, BoundingBox t

if (useGpuInstancing)
{

tile = GPUTileHandler.GetGPUTile(instances, (bool)o.UseScaleNonUniform);
tile = GPUTileHandler.GetGPUTile(instances, (bool)o.UseScaleNonUniform);
}
else if(!useI3dm)
{
Expand Down
1 change: 0 additions & 1 deletion src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ static void Main(string[] args)
{
Console.WriteLine($"Query: {o.Query}");
}

var bbox = InstancesRepository.GetBoundingBoxForTable(conn, o.Table, geom_column, heights, o.Query);

var bbox_wgs84 = bbox.bbox;
Expand Down