Skip to content

Commit

Permalink
Merge pull request #564 from elblake/eb/x3d-fixes
Browse files Browse the repository at this point in the history
x3d_import: Fixed transparency, added gzip support
  • Loading branch information
dgud authored Dec 7, 2023
2 parents 4d3e856 + 0e94b09 commit 02f3522
Showing 1 changed file with 37 additions and 5 deletions.
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

0 comments on commit 02f3522

Please sign in to comment.