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

BRAYNS-662 Add engine endpoints v3 #1291

Merged
merged 40 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0847d05
Added info to remove default values.
Adrien4193 Sep 12, 2024
469c650
C++ side cleanup.
Adrien4193 Sep 26, 2024
7ab80a6
formatting.
Adrien4193 Sep 26, 2024
9afdb7d
Use array for boxes.
Adrien4193 Sep 26, 2024
8cda95a
Python side + tests.
Adrien4193 Oct 4, 2024
97f2887
Minor changes.
Adrien4193 Oct 4, 2024
ca708e6
Simplified tasks.
Adrien4193 Oct 4, 2024
66e50fe
Rewrite task system.
Adrien4193 Nov 1, 2024
055d632
Changed data model.
Adrien4193 Nov 4, 2024
881ad34
Checkpoint geometry objects.
Adrien4193 Nov 15, 2024
984e716
Checkpoint all curves.
Adrien4193 Nov 15, 2024
0dce15a
All geometry objects.
Adrien4193 Nov 18, 2024
fa5e04d
Geometry endpoints.
Adrien4193 Nov 18, 2024
74502e6
Python side geometry.
Adrien4193 Nov 18, 2024
c149c10
Quad mesh tested.
Adrien4193 Nov 18, 2024
d1740b3
All geometries tested.
Adrien4193 Nov 19, 2024
53ab48d
Texture endpoints.
Adrien4193 Nov 21, 2024
9ef5a54
Use different types for binary and text data.
Adrien4193 Nov 21, 2024
bed0c3f
Fixed bug.
Adrien4193 Nov 21, 2024
ab799fd
Python textures.
Adrien4193 Nov 21, 2024
ce0816e
Material checkpoint.
Adrien4193 Nov 22, 2024
2fde4c3
All material objects.
Adrien4193 Nov 22, 2024
f1b43cc
Materials tested.
Adrien4193 Nov 26, 2024
6949c25
Light endpoints implemented.
Adrien4193 Nov 27, 2024
16dc4a7
Lights tested.
Adrien4193 Nov 28, 2024
c3eb060
Fixed material texture ownership.
Adrien4193 Nov 29, 2024
ab3c676
Task endpoints.
Adrien4193 Dec 2, 2024
5ebac46
Renderer objects.
Adrien4193 Dec 3, 2024
4c75ced
Renderer endpoints.
Adrien4193 Dec 3, 2024
a0bae75
Renderer python.
Adrien4193 Dec 3, 2024
7c70853
Renderer tested.
Adrien4193 Dec 3, 2024
4645085
Material validation in renderer.
Adrien4193 Dec 3, 2024
a906faf
Scene objects.
Adrien4193 Dec 4, 2024
01ae791
Add scene endpoints.
Adrien4193 Dec 4, 2024
8a499c9
Scene python API.
Adrien4193 Dec 4, 2024
718ef99
Scene objects tested.
Adrien4193 Dec 9, 2024
5bfb22a
Updated task system.
Adrien4193 Dec 9, 2024
3712d82
Rendering tested.
Adrien4193 Dec 10, 2024
51386fe
Fix tests + format.
Adrien4193 Dec 10, 2024
c3a2982
Fix release build error.
Adrien4193 Dec 10, 2024
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
Prev Previous commit
Next Next commit
Materials tested.
  • Loading branch information
Adrien4193 committed Nov 26, 2024
commit f1b43ccba2541bfa319f63d7ec61c4d0f69d179a
48 changes: 48 additions & 0 deletions python/brayns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,31 @@
get_tone_mapper,
update_tone_mapper,
)
from .api.core.material import (
AoMaterial,
CreateAoMaterialParams,
CreatePrincipledMaterialParams,
CreateScivisMaterialParams,
GetAoMaterialResult,
GetPrincipledMaterialResult,
GetScivisMaterialResult,
Material,
MaterialColor3,
MaterialFloat,
MaterialTexture2D,
MaterialVolumeTexture,
PrincipledMaterial,
ScivisMaterial,
create_ao_material,
create_principled_material,
create_scivis_material,
get_ao_material,
get_principled_material,
get_scivis_material,
update_ao_material,
update_principled_material,
update_scivis_material,
)
from .api.core.objects import (
CreateObjectParams,
EmptyObject,
Expand Down Expand Up @@ -222,6 +247,7 @@
"""Version tag of brayns Python package (major.minor.patch)."""

__all__ = [
"AoMaterial",
"axis_angle",
"BezierBasis",
"Box1",
Expand All @@ -237,6 +263,7 @@
"Color4",
"connect",
"Connection",
"create_ao_material",
"create_boxes",
"create_curve",
"create_cylinders",
Expand All @@ -250,14 +277,17 @@
"create_panoramic_camera",
"create_perspective_camera",
"create_planes",
"create_principled_material",
"create_quad_mesh",
"create_regular_volume",
"create_ribbon",
"create_scivis_material",
"create_spheres",
"create_texture2d",
"create_tone_mapper",
"create_triangle_mesh",
"create_volume_texture",
"CreateAoMaterialParams",
"CreateBoxesParams",
"CreateCurveParams",
"CreateCylindersParams",
Expand All @@ -267,9 +297,11 @@
"CreateLinearTransferFunctionParams",
"CreateObjectParams",
"CreatePlanesParams",
"CreatePrincipledMaterialParams",
"CreateQuadMeshParams",
"CreateRegularVolumeParams",
"CreateRibbonParams",
"CreateScivisMaterialParams",
"CreateSpheresParams",
"CreateTexture2DParams",
"CreateToneMapperParams",
Expand All @@ -287,6 +319,7 @@
"FutureResponse",
"Geometry",
"get_all_objects",
"get_ao_material",
"get_boxes",
"get_camera",
"get_curve",
Expand All @@ -307,17 +340,20 @@
"get_perspective_camera",
"get_perspective_camera",
"get_planes",
"get_principled_material",
"get_quad_mesh",
"get_regular_volume",
"get_ribbon",
"get_rotation_between",
"get_scivis_material",
"get_spheres",
"get_texture2d",
"get_tone_mapper",
"get_tone_mapper",
"get_triangle_mesh",
"get_version",
"get_volume_texture",
"GetAoMaterialResult",
"GetBoxesResult",
"GetCameraResult",
"GetCurveResult",
Expand All @@ -331,9 +367,11 @@
"GetPanoramicCameraResult",
"GetPerspectiveCameraResult",
"GetPlanesResult",
"GetPrincipledMaterialResult",
"GetQuadMeshResult",
"GetRegularVolumeResult",
"GetRibbonResult",
"GetScivisMaterialResult",
"GetSpheresResult",
"GetTexture2DResult",
"GetToneMapperResult",
Expand All @@ -351,12 +389,18 @@
"JsonRpcSuccessResponse",
"LinearBasis",
"LinearTransferFunction",
"Material",
"MaterialColor3",
"MaterialFloat",
"MaterialTexture2D",
"MaterialVolumeTexture",
"Object",
"OrthographicCamera",
"PanoramicCamera",
"PerspectiveCamera",
"Planes",
"PngChannel",
"PrincipledMaterial",
"Quaternion",
"read_framebuffer_as_exr",
"read_framebuffer_as_jpeg",
Expand All @@ -368,6 +412,7 @@
"Ribbon",
"RibbonBasis",
"Rotation",
"ScivisMaterial",
"ServiceUnavailable",
"Stereo",
"stop_service",
Expand All @@ -378,14 +423,17 @@
"TextureWrap",
"ToneMapper",
"TransferFunction",
"update_ao_material",
"update_camera",
"update_framebuffer",
"update_linear_transfer_function",
"update_object",
"update_orthographic_camera",
"update_panoramic_camera",
"update_perspective_camera",
"update_principled_material",
"update_regular_volume",
"update_scivis_material",
"update_texture2d",
"update_tone_mapper",
"update_volume_texture",
Expand Down
221 changes: 221 additions & 0 deletions python/brayns/api/core/material.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
# Copyright (c) 2015-2024 EPFL/Blue Brain Project
# All rights reserved. Do not distribute without permission.
#
# Responsible Author: [email protected]
#
# This file is part of Brayns <https://github.com/BlueBrain/Brayns>
#
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License version 3.0 as published
# by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

from dataclasses import dataclass
from typing import Generic, TypedDict, TypeVar, Unpack

from brayns.network.connection import Connection
from brayns.utils.composing import serialize
from brayns.utils.parsing import deserialize

from .objects import CreateObjectParams, Object, create_specific_object, get_specific_object, update_specific_object
from .texture import Texture2D, VolumeTexture

T = TypeVar("T", float, tuple[float, float, float])


class Material(Object): ...


@dataclass
class MaterialTexture2D(Generic[T]):
texture2d: Texture2D
translation: tuple[float, float] = (0, 0)
rotation: float = 0
scale: tuple[float, float] = (1, 1)
factor: T | None = None


@dataclass
class MaterialVolumeTexture(Generic[T]):
volume_texture: VolumeTexture
translation: tuple[float, float, float] = (0, 0, 0)
rotation: tuple[float, float, float, float] = (0, 0, 0, 1)
scale: tuple[float, float, float] = (0, 0, 0)
factor: T | None = None


MaterialField = T | MaterialTexture2D[T] | MaterialVolumeTexture[T]

MaterialFloat = MaterialField[float]
MaterialColor3 = MaterialField[tuple[float, float, float]]


class AoMaterial(Material): ...


@dataclass
class GetAoMaterialResult:
diffuse: MaterialColor3
opacity: MaterialFloat


class UpdateAoMaterialParams(TypedDict, total=False):
diffuse: MaterialColor3
opacity: MaterialFloat


class CreateAoMaterialParams(CreateObjectParams, UpdateAoMaterialParams): ...


async def create_ao_material(connection: Connection, **settings: Unpack[CreateAoMaterialParams]) -> AoMaterial:
object = await create_specific_object(connection, "AoMaterial", serialize(settings))
return AoMaterial(object.id)


async def get_ao_material(connection: Connection, material: AoMaterial) -> GetAoMaterialResult:
result = await get_specific_object(connection, "AoMaterial", material)
return deserialize(result, GetAoMaterialResult)


async def update_ao_material(
connection: Connection, material: AoMaterial, **settings: Unpack[UpdateAoMaterialParams]
) -> None:
await update_specific_object(connection, "AoMaterial", material, serialize(settings))


class ScivisMaterial(Material): ...


@dataclass
class GetScivisMaterialResult:
diffuse: MaterialColor3
opacity: MaterialFloat
specular: MaterialColor3
shininess: MaterialFloat
transparency_filter: tuple[float, float, float]


class UpdateScivisMaterialParams(TypedDict, total=False):
diffuse: MaterialColor3
opacity: MaterialFloat
specular: MaterialColor3
shininess: MaterialFloat
transparency_filter: tuple[float, float, float]


class CreateScivisMaterialParams(CreateObjectParams, UpdateScivisMaterialParams): ...


async def create_scivis_material(
connection: Connection, **settings: Unpack[CreateScivisMaterialParams]
) -> ScivisMaterial:
object = await create_specific_object(connection, "ScivisMaterial", serialize(settings))
return ScivisMaterial(object.id)


async def get_scivis_material(connection: Connection, material: ScivisMaterial) -> GetScivisMaterialResult:
result = await get_specific_object(connection, "ScivisMaterial", material)
return deserialize(result, GetScivisMaterialResult)


async def update_scivis_material(
connection: Connection, material: ScivisMaterial, **settings: Unpack[UpdateScivisMaterialParams]
) -> None:
await update_specific_object(connection, "ScivisMaterial", material, serialize(settings))


class PrincipledMaterial(Material): ...


@dataclass
class GetPrincipledMaterialResult:
base_color: MaterialColor3
edge_color: MaterialColor3
metallic: MaterialFloat
diffuse: MaterialFloat
specular: MaterialFloat
ior: MaterialFloat
transmission: MaterialFloat
transmission_color: MaterialColor3
transmission_depth: MaterialFloat
roughness: MaterialFloat
anisotropy: MaterialFloat
rotation: MaterialFloat
normal: MaterialFloat
base_normal: MaterialFloat
thin: float
thickness: MaterialFloat
backlight: MaterialFloat
coat: MaterialFloat
coat_ior: MaterialFloat
coat_color: MaterialColor3
coat_thickness: MaterialFloat
coat_roughness: MaterialFloat
coat_normal: MaterialFloat
sheen: MaterialFloat
sheen_color: MaterialColor3
sheen_tint: MaterialFloat
sheen_roughness: MaterialFloat
opacity: MaterialFloat
emissive_color: MaterialColor3


class UpdatePrincipledMaterialParams(TypedDict, total=False):
base_color: MaterialColor3
edge_color: MaterialColor3
metallic: MaterialFloat
diffuse: MaterialFloat
specular: MaterialFloat
ior: MaterialFloat
transmission: MaterialFloat
transmission_color: MaterialColor3
transmission_depth: MaterialFloat
roughness: MaterialFloat
anisotropy: MaterialFloat
rotation: MaterialFloat
normal: MaterialFloat
base_normal: MaterialFloat
thin: float
thickness: MaterialFloat
backlight: MaterialFloat
coat: MaterialFloat
coat_ior: MaterialFloat
coat_color: MaterialColor3
coat_thickness: MaterialFloat
coat_roughness: MaterialFloat
coat_normal: MaterialFloat
sheen: MaterialFloat
sheen_color: MaterialColor3
sheen_tint: MaterialFloat
sheen_roughness: MaterialFloat
opacity: MaterialFloat
emissive_color: MaterialColor3


class CreatePrincipledMaterialParams(CreateObjectParams, UpdatePrincipledMaterialParams): ...


async def create_principled_material(
connection: Connection, **settings: Unpack[CreatePrincipledMaterialParams]
) -> PrincipledMaterial:
object = await create_specific_object(connection, "PrincipledMaterial", serialize(settings))
return PrincipledMaterial(object.id)


async def get_principled_material(connection: Connection, material: PrincipledMaterial) -> GetPrincipledMaterialResult:
result = await get_specific_object(connection, "PrincipledMaterial", material)
return deserialize(result, GetPrincipledMaterialResult)


async def update_principled_material(
connection: Connection, material: PrincipledMaterial, **settings: Unpack[UpdatePrincipledMaterialParams]
) -> None:
await update_specific_object(connection, "PrincipledMaterial", material, serialize(settings))
Loading