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

x3d_import: Fixed transparency, added gzip support #564

Merged
merged 1 commit into from
Dec 7, 2023
Merged
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: 37 additions & 5 deletions plugins_src/import_export/x3d_import.erl
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ init_import() ->
props() ->
[{extensions,
[{".x3d", "X3D File"},
{".x3dz", "X3D File Compressed"},
{".x3d.gz", "X3D File (gzipped)"},
{".wrl", "VRML World"},
{".iv", "SGI Inventor File"}]}].
{".wrz", "VRML World Compressed"},
{".wrl.gz", "VRML World (gzipped)"},
{".iv", "SGI Inventor File"},
{".iv.gz", "SGI Inventor File (gzipped)"}]}].

do_import(Ask, _St) when is_atom(Ask) ->
wpa:dialog(Ask, ?__(1,"X3D/VRML Import Options"), dialog(import),
Expand Down Expand Up @@ -315,7 +320,7 @@ appearance_opengl(#materialprops{
{ambient, intensity_to_rgba(AmbInt)},
{specular, rgb_to_rgba(SpecCol)},
{shininess, Shine},
{diffuse, rgb_to_rgba(DifCol, Transparency)},
{diffuse, rgb_to_rgba(DifCol, 1.0 - Transparency)},
{emission, rgb_to_rgba(EmCol)},
{metallic,0.1},
{roughness,0.8},
Expand Down Expand Up @@ -416,9 +421,17 @@ dialog(import) ->

get_file_type(FileName) ->
case string:to_lower(filename:extension(FileName)) of
".x3d" -> x3d;
".wrl" -> wrl;
".iv" -> wrl
".x3d" ++ _ -> x3d;
".wrl" ++ _ -> wrl;
".wrz" -> wrl;
".iv" -> wrl;
".gz" ++ _ ->
case string:to_lower(filename:extension(filename:rootname(FileName))) of
".x3d" ++ _ -> x3d;
".wrl" ++ _ -> wrl;
".wrz" -> wrl;
".iv" -> wrl
end
end.

read_file_content(x3d, Filename) ->
Expand Down Expand Up @@ -453,7 +466,17 @@ read_file_content(wrl, Filename) ->
inscene = false % Is event inside the <Scene> tag
}).


read_x3d_content(Bin_0) ->
case Bin_0 of
<<31,139,_/binary>> ->
%% A gz header, the file is compressed.
read_x3d_content_1(zlib:gunzip(Bin_0));
_ ->
%% Uncompressed
read_x3d_content_1(Bin_0)
end.
read_x3d_content_1(Bin_0) ->
EF = {event_fun, fun x3d_tok/3},
ES = {event_state, #x3dtk{}},
{ok, Bin_1} = x3d_change_prolog(Bin_0),
Expand Down Expand Up @@ -867,6 +890,15 @@ x3d_sub_of(_) -> root.
%%

read_vrml_content(Cont) ->
case Cont of
<<31,139,_/binary>> ->
%% A gz header the file is compressed.
read_vrml_content_1(zlib:gunzip(Cont));
_ ->
%% Uncompressed
read_vrml_content_1(Cont)
end.
read_vrml_content_1(Cont) ->
[FirstLine, VRMLContent] = binary:split(Cont, <<10>>),
case header(FirstLine) of
{ok, vrml2, _Enc} ->
Expand Down