Skip to content

globallightingdata/l3d.net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 

Repository files navigation

L3D .NET library

OnPublishedRelease
OnPush develop
NuGet Status L3D.Net on fuget.org

Intro

.NET Standard 2.0 library for the Luminaire 3D L3D

With the library it is possible to read and build L3D container files. For that the library exposes two classes 'Builder' and 'Reader'. The Builder has a fluent API for defining all the luminaire parts and build the target container file. With the Reader is is possible to read the content of a L3D container and to parse the containing .obj files at once. So there is no other .obj parser needed.

How to get started

Requirements

Nuget package

Add the package within your IDE or using the CLI

dotnet add package L3D.Net

Building a L3D container

Simple builder exmaple.

var luminaire = new Luminaire();
luminaire.Header = new Header
{
    CreatedWithApplication = "Example-Tool"
};

var geometryDefinition = new GeometryFileDefinition
{
    GeometryId = "PN.Ab12",
    Units = GeometricUnits.m,
    Model = ObjParser.Parse(cubeObjPath, NullLogger.Instance),
    FileName = cubeObjPath
};

luminaire.GeometryDefinitions = new List<GeometryFileDefinition>
{
    geometryDefinition
};

luminaire.Parts = new List<GeometryPart>
{
    new()
    {
        Name = "luminaire",
        LightEmittingObjects = new List<LightEmittingPart>
        {
            new()
            {
                Name = "leo",
                Shape = new Rectangle
                {
                    SizeX = 0.5,
                    SizeY = 0.25
                }
            }
        },
        LightEmittingSurfaces = new List<LightEmittingSurfacePart>
        {
            new()
            {
                Name = "les",
                FaceAssignments = new List<FaceAssignment>
                {
                    new SingleFaceAssignment
                    {
                        FaceIndex = 3
                    }
                },
                LightEmittingPartIntensityMapping = new Dictionary<string, double>
                {
                    ["leo"] = 1
                }
            }
        },
        GeometryReference = geometryDefinition
    }
};

IWriter writer = new Writer();
var bytes = writer.WriteToByteArray(luminaire);

Reading a L3D container

Read an L3D container from disk:

var reader = new Reader();
var container = reader.ReadContainer("path/to/container.l3d");

foreach (var geometryPartDto in container.Parts)
{
    // ...
    var model = geometryPartDto.GeometryDefinition.Model;
    foreach (var vertex in model.Vertices)
    {
        // .obj-Model vertices
    }

    // ...
    
    foreach (var lightEmittingPartDto in geometryPartDto.LightEmittingObjects)
    {
        // do something for light emitting part 
    }

    // ...
}

Read an L3D container already read from disk in byte array (byte[]) format:

var reader = new Reader();
byte[] l3dContainer = // Get a byte[] representation of an L3D container;
var container = reader.ReadContainer(l3dContainer);

foreach (var geometryPartDto in container.Parts)
{
    // From here on out everything is identical to the reading an L3D container from disk example,
    // see the code sample above.
}

Validating a L3D container

Validation of an L3D container from disk:

var validator = new Validator();
var validationHints = validator.ValidateContainer("path/to/container.l3d");

if (!validationHints.Any())
    // Container validation successful
else
    // Container validation unsuccessful

Validation of an L3D container already read from disk in byte array (byte[]) format:

var validator = new Validator();
byte[] l3dContainer = // Get a byte[] representation of an L3D container;
var validationHints = validator.ValidateContainer(l3dContainer);

if (!validationHints.Any())
    // Container validation successful
else
    // Container validation unsuccessful

Compatibility

L3D.NET is able to read old and new unknown versions, with the exception of a new major version.

When a new minor version is read, it is possible that optional information is not read. If the L3D is saved again, this information is not written either and the version is set to the latest version of the L3D.NET component.

The following table explains this behaviour summarized:

File version L3D.NET version Can read Can write Read and write changes the file
1.0.0.0 0.9.0.0 no no N/A
0.9.0.0 1.0.0.0 yes yes* yes - the version is updated and the content accordingly too
1.0.0.0 1.0.0.0 yes yes no
0.9.2.0 0.9.0.0 yes* yes* yes - some optional information may not be read or written
0.9.0.0 0.9.2.0 yes yes* yes - the version is updated and the content accordingly too

Questions, Issues & Contribution

Please use the discussion section for questions or create issues, when something seems to be wrong. PRs are welcome.