-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from MIERUNE/feature/misc-improvements
Feature処理器の表示名、外観読み込みのアタリ付け
- Loading branch information
Showing
25 changed files
with
320 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from dataclasses import dataclass | ||
from typing import Iterable, Optional | ||
|
||
import lxml.etree as et | ||
import numpy as np | ||
|
||
from .namespaces import BASE_NS as _NS | ||
|
||
|
||
@dataclass | ||
class Material: | ||
__slots__ = ("diffuse_color", "specular_color", "shininess") | ||
diffuse_color: Optional[tuple[float, ...]] | ||
specular_color: Optional[tuple[float, ...]] | ||
shininess: Optional[float] | ||
|
||
|
||
@dataclass | ||
class Texture: | ||
__slots__ = ("image_uri",) | ||
image_uri: str | ||
|
||
|
||
@dataclass | ||
class Appearance: | ||
target_material: dict[str, Material] | ||
ring_texture: dict[str, tuple[Texture, np.ndarray]] | ||
|
||
|
||
def parse_appearances(doc: et._Element) -> Iterable[Appearance]: | ||
target_to_material: dict[str, Material] = {} | ||
ring_to_texture: dict[str, tuple[Texture, np.ndarray]] = {} | ||
|
||
for appearance in doc.iterfind(".//app:appearanceMember/app:Appearance", _NS): | ||
for material in appearance.iterfind( | ||
".//app:surfaceDataMember/app:X3DMaterial", _NS | ||
): | ||
m = Material( | ||
diffuse_color=None, | ||
specular_color=None, | ||
shininess=None, | ||
) | ||
if (diffuse := material.find("./app:diffuseColor", _NS)) is not None: | ||
m.diffuse_color = tuple(float(v) for v in diffuse.text.split()) | ||
if (specular := material.find("./app:specularColor", _NS)) is not None: | ||
m.specular_color = tuple(float(v) for v in specular.text.split()) | ||
if (shininess := material.find("./app:shininess", _NS)) is not None: | ||
m.shininess = float(shininess.text) | ||
|
||
for target in material.iterfind("./app:target", _NS): | ||
assert target.text.startswith("#") | ||
target_id = target.text[1:] | ||
target_to_material[target_id] = m | ||
|
||
for texture in appearance.iterfind( | ||
".//app:surfaceDataMember/app:ParameterizedTexture", _NS | ||
): | ||
image_uri = texture.find("./app:imageURI", _NS).text | ||
t = Texture(image_uri=image_uri) | ||
for target in texture.iterfind("./app:target", _NS): | ||
coords = target.find(".//app:textureCoordinates", _NS) | ||
ring_id = coords.get("ring") | ||
assert ring_id.startswith("#") | ||
ring_id = ring_id[1:] | ||
uv = np.fromstring(coords.text, dtype=np.float32, sep=" ") | ||
ring_to_texture[ring_id] = (t, uv.reshape(-1, 2)) | ||
|
||
yield Appearance(target_to_material, ring_to_texture) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.