Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
dgud committed Sep 27, 2024
1 parent b961144 commit 07ba7d6
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 8 deletions.
27 changes: 27 additions & 0 deletions cube-special.dae

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions cube-special2.dae
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<COLLADA version="1.4.0" xmlns="http://www.collada.org/2005/11/COLLADASchema">
<asset>
<contributor>
<author>Wings3D Collada Exporter</author>
<authoring_tool>Wings3D 2.3.25.gb961.dirty Collada Exporter</authoring_tool>
<comments/>
<copyright/>
<source_data/>
</contributor>
<created>2024-09-26T15:35:48</created>
<modified>2024-09-26T15:35:48</modified>
<unit meter="0.01" name="centimeter"/>
<up_axis>Y_UP</up_axis>
</asset>
<library_effects/>

<library_materials/>
<library_geometries/>
<library_visual_scenes><visual_scene id="Scene" name="Scene"/></library_visual_scenes>
<scene><instance_visual_scene url="#Scene"/></scene>
</COLLADA>
50 changes: 42 additions & 8 deletions e3d/e3d_mesh.erl
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,14 @@ hard_edges_from_normals(#e3d_mesh{fs=Ftab,vs=Vtab,he=[],ns=[_|_]=Ntab0}=Mesh) ->
FN = face_normals(Ftab, list_to_tuple(Vtab)),
Ntab = array:from_list([e3d_vec:norm(N) || N <- Ntab0]),
{_,He0} = foldl(fun(#e3d_face{vs=Vs, ns=VNs}, {N, Acc}) ->
io:nl(),
{N+1, add_hard_edges(Vs, VNs, {Vs,VNs},
Ntab, gb_trees:get(N,FN), Acc)}
end, {0, []}, Ftab),
%% Cannot use sofs:relation_to_family because family is a set!!
He = filter_edges(lists:sort(He0), []),
io:format("Prefilter: ~p ~n",[lists:sort(He0)]),
io:format("Postflter: ~p ~n",[He]),
Mesh#e3d_mesh{he=He};
%% He already set or no normals available
hard_edges_from_normals(Mesh) ->
Expand All @@ -128,33 +131,64 @@ filter_edges([{Edge,N1},{Edge,N2}|Rest], Acc) ->
true -> filter_edges(Rest, Acc);
false -> filter_edges(Rest, [Edge|Acc])
end;
filter_edges([_|Rest], Acc) ->
filter_edges(Rest, Acc);
filter_edges([{Edge, _}|Rest], Acc) ->
filter_edges(Rest, [Edge|Acc]);
filter_edges([], Acc) ->
Acc.

add_hard_edges([V1|[V2|_]=Vs], [N1|[N2|_]=Ns], First, Ntab, FaceN, Acc) ->
case is_equal_v(array:get(N1,Ntab),FaceN) orelse
is_equal_v(array:get(N2,Ntab),FaceN)
VN1 = array:get(N1,Ntab),
VN2 = array:get(N2,Ntab),
case is_equal_v(VN1,FaceN) orelse
is_equal_v(VN2,FaceN)
of
true ->
io:format("Add0 ~4w = ~s ~w = ~s FN = ~s~n",
[V1,e3d_vec:format(VN1), V2, e3d_vec:format(VN2), e3d_vec:format(FaceN)]),
Edge = {vn_edge_name(V1,V2),FaceN},
add_hard_edges(Vs, Ns, First, Ntab, FaceN, [Edge|Acc]);
false ->
add_hard_edges(Vs, Ns, First, Ntab, FaceN, Acc)
Combined = e3d_vec:norm(e3d_vec:add(VN1,VN2)),
case is_equal_v(Combined, FaceN) of
true ->
io:format("Add1 ~4w ~w = ~s FN = ~s~n",
[V1, V2, e3d_vec:format(Combined), e3d_vec:format(FaceN)]),
Edge = {vn_edge_name(V1,V2),FaceN},
add_hard_edges(Vs, Ns, First, Ntab, FaceN, [Edge|Acc]);
false ->
io:format("Drop ~4w = ~s ~w = ~s FN = ~s~n",
[V1,e3d_vec:format(array:get(N1,Ntab)), V2, e3d_vec:format(array:get(N2,Ntab)), e3d_vec:format(FaceN)]),
add_hard_edges(Vs, Ns, First, Ntab, FaceN, Acc)
end
end;
add_hard_edges([V1], [N1], {[V2|_],[N2|_]}, Ntab, FaceN, Acc) ->
case is_equal_v(array:get(N1,Ntab),FaceN) orelse
is_equal_v(array:get(N2,Ntab),FaceN)
VN1 = array:get(N1,Ntab),
VN2 = array:get(N2,Ntab),
case is_equal_v(VN1,FaceN) orelse
is_equal_v(VN2,FaceN)
of
true ->
io:format("Add0 ~4w = ~s ~w = ~s FN = ~s~n",
[V1,e3d_vec:format(VN1), V2, e3d_vec:format(VN2), e3d_vec:format(FaceN)]),
Edge = {vn_edge_name(V1,V2),FaceN},
[Edge|Acc];
false ->
Acc
Combined = e3d_vec:norm(e3d_vec:add(VN1,VN2)),
case is_equal_v(Combined, FaceN) of
true ->
io:format("Add1 ~4w ~w = ~s FN = ~s~n",
[V1, V2, e3d_vec:format(Combined), e3d_vec:format(FaceN)]),
Edge = {vn_edge_name(V1,V2),FaceN},
[Edge|Acc];
false ->
io:format("Drop ~4w = ~s ~w = ~s FN = ~s~n",
[V1,e3d_vec:format(array:get(N1,Ntab)), V2, e3d_vec:format(array:get(N2,Ntab)), e3d_vec:format(FaceN)]),
Acc
end
end;
add_hard_edges(_, _, _, _, _, Acc) ->
%% Ignore if face is missing some normals
io:format("Drop missing VSN~n"),
Acc.

is_equal_v(N,N) -> true;
Expand Down
27 changes: 27 additions & 0 deletions test.dae
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<COLLADA version="1.4.0" xmlns="http://www.collada.org/2005/11/COLLADASchema">
<asset>
<contributor>
<author>Wings3D Collada Exporter</author>
<authoring_tool>Wings3D 2.3.31.g6252 Collada Exporter</authoring_tool>
<comments/>
<copyright/>
<source_data/>
</contributor>
<created>2024-09-25T14:25:46</created>
<modified>2024-09-25T14:25:46</modified>
<unit meter="0.01" name="centimeter"/>
<up_axis>Y_UP</up_axis>
</asset>
<library_effects><effect id="default-fx" name="default-fx"><profile_COMMON><technique sid="wings3d"><phong><emission><color>0.000000 0.000000 0.000000 1.000000
</color></emission><ambient><color>0.000000 0.000000 0.000000 0.000000
</color></ambient><diffuse><color>0.789854 0.813333 0.694044 1.000000
</color></diffuse><specular><color>0.168985 0.171333 0.159404 1.000000
</color></specular><shininess><float>0.200000</float></shininess></phong></technique></profile_COMMON></effect></library_effects>

<library_materials><material id="default" name="default"><instance_effect url="#default-fx"/></material></library_materials>
<library_geometries><geometry name="Cube2-0-0" id="Cube2-0-0"><mesh><source id="Cube2-0-0-Pos"><float_array id="Cube2-0-0-Pos-array" count="12">-2.000000 1.000000 0.000000 0.000000 0.000000 0.000000 0.000000 1.000000 2.000000 0.000000 2.000000 0.000000</float_array><technique_common><accessor count="4" source="#Cube2-0-0-Pos-array" stride="3"><param name="X" type="float"/><param name="Y" type="float"/><param name="Z" type="float"/></accessor></technique_common></source><source id="Cube2-0-0-Normal"><float_array id="Cube2-0-0-Normal-array" count="36">-0.707107 0.000000 0.707107 -0.707107 0.000000 0.707107 0.000000 0.000000 -1.000000 0.707107 0.000000 -0.707107 -0.408248 -0.816497 0.408248 0.707107 0.000000 -0.707107 -0.707107 0.000000 0.707107 1.000000 0.000000 0.000000 -0.707107 0.000000 0.707107 -0.408248 0.816497 0.408248 0.707107 0.000000 -0.707107 0.707107 0.000000 -0.707107</float_array><technique_common><accessor count="12" source="#Cube2-0-0-Normal-array" stride="3"><param name="X" type="float"/><param name="Y" type="float"/><param name="Z" type="float"/></accessor></technique_common></source><vertices id="Cube2-0-0-Vtx"><input semantic="POSITION" source="#Cube2-0-0-Pos"/></vertices><polylist count="4" material="default"><input offset="0" semantic="VERTEX" source="#Cube2-0-0-Vtx"/><input offset="1" semantic="NORMAL" source="#Cube2-0-0-Normal"/><vcount>3 3 3 3</vcount><p>0 2 3 11 1 5 1 4 2 8 0 1 1 3 3 10 2 7 2 6 3 9 0 0</p></polylist></mesh></geometry></library_geometries>
<library_visual_scenes><visual_scene id="Scene" name="Scene"><node layer="L1" id="Cube2-0-0L1" name="Cube2-0-0"><translate sid="translate">0.00000 0.00000 0.00000</translate>
<rotate sid="rotateZ">0 0 1 0.00000</rotate><rotate sid="rotateY">0 1 0 0.00000</rotate><rotate sid="rotateX">1 0 0 0.00000</rotate><scale sid="scale">1.0000 1.0000 1.0000</scale><instance_geometry url="#Cube2-0-0"><bind_material><technique_common><instance_material symbol="default" target="#default"><bind_vertex_input input_semantic="TEXCOORD" input_set="1" semantic="CHANNEL1"/></instance_material></technique_common></bind_material></instance_geometry></node></visual_scene></library_visual_scenes>
<scene><instance_visual_scene url="#Scene"/></scene>
</COLLADA>
27 changes: 27 additions & 0 deletions test2.dae
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<COLLADA version="1.4.0" xmlns="http://www.collada.org/2005/11/COLLADASchema">
<asset>
<contributor>
<author>Wings3D Collada Exporter</author>
<authoring_tool>Wings3D 2.3.25.gb961.dirty Collada Exporter</authoring_tool>
<comments/>
<copyright/>
<source_data/>
</contributor>
<created>2024-09-26T15:14:08</created>
<modified>2024-09-26T15:14:08</modified>
<unit meter="0.01" name="centimeter"/>
<up_axis>Y_UP</up_axis>
</asset>
<library_effects><effect id="default-fx" name="default-fx"><profile_COMMON><technique sid="wings3d"><phong><emission><color>0.000000 0.000000 0.000000 1.000000
</color></emission><ambient><color>0.000000 0.000000 0.000000 0.000000
</color></ambient><diffuse><color>0.789854 0.813333 0.694044 1.000000
</color></diffuse><specular><color>0.168985 0.171333 0.159404 1.000000
</color></specular><shininess><float>0.200000</float></shininess></phong></technique></profile_COMMON></effect></library_effects>

<library_materials><material id="default" name="default"><instance_effect url="#default-fx"/></material></library_materials>
<library_geometries><geometry name="Cube1-0" id="Cube1-0"><mesh><source id="Cube1-0-Pos"><float_array id="Cube1-0-Pos-array" count="48">-0.590421 -1.426579 0.604218 -0.590421 -1.426579 -0.604218 0.618016 -1.426579 -0.604218 0.618016 -1.426579 0.604218 -0.590421 -2.802500 0.604218 -0.590421 -2.802500 -0.604218 0.618016 -2.802500 -0.604218 0.618016 -2.802500 0.604218 -0.590421 -0.227604 -0.604218 -0.590421 -0.227604 0.604218 0.618016 -0.227604 0.604218 0.618016 -0.227604 -0.604218 0.618016 -0.827091 -0.604218 0.618016 -0.827091 0.604218 -0.590421 -0.827091 0.604218 -0.590421 -0.827091 -0.604218</float_array><technique_common><accessor count="16" source="#Cube1-0-Pos-array" stride="3"><param name="X" type="float"/><param name="Y" type="float"/><param name="Z" type="float"/></accessor></technique_common></source><source id="Cube1-0-Normal"><float_array id="Cube1-0-Normal-array" count="108">-0.577350 0.577350 -0.577350 -0.577350 0.577350 0.577350 0.577350 0.577350 0.577350 0.577350 0.577350 -0.577350 0.707107 0.000000 -0.707107 0.707107 0.000000 0.707107 -0.707107 0.000000 0.707107 -0.707107 0.000000 -0.707107 -0.707107 0.000000 0.707107 -0.707107 0.000000 0.707107 -0.707107 0.000000 0.707107 -0.707107 0.000000 0.707107 -0.707107 0.000000 -0.707107 -0.707107 0.000000 -0.707107 -0.707107 -0.000000 -0.707107 -0.707107 -0.000000 -0.707107 0.707107 0.000000 -0.707107 0.707107 0.000000 -0.707107 0.707107 0.000000 -0.707107 0.707107 0.000000 -0.707107 0.707107 -0.000000 0.707107 0.707107 -0.000000 0.707107 0.707107 0.000000 0.707107 0.707107 0.000000 0.707107 -0.000000 -1.000000 0.000000 -0.707107 0.000000 0.707107 -0.707107 0.000000 0.707107 -0.000000 -1.000000 0.000000 -0.707107 0.000000 -0.707107 -0.707107 0.000000 -0.707107 -0.000000 -1.000000 0.000000 0.707107 0.000000 -0.707107 0.707107 0.000000 -0.707107 -0.000000 -1.000000 0.000000 0.707107 -0.000000 0.707107 0.707107 -0.000000 0.707107</float_array><technique_common><accessor count="36" source="#Cube1-0-Normal-array" stride="3"><param name="X" type="float"/><param name="Y" type="float"/><param name="Z" type="float"/></accessor></technique_common></source><vertices id="Cube1-0-Vtx"><input semantic="POSITION" source="#Cube1-0-Pos"/></vertices><polylist count="14" material="default"><input offset="0" semantic="VERTEX" source="#Cube1-0-Vtx"/><input offset="1" semantic="NORMAL" source="#Cube1-0-Normal"/><vcount>4 4 4 4 4 4 4 4 4 4 4 4 4 4</vcount><p>1 15 15 7 12 4 2 19 2 18 12 4 13 5 3 23 3 22 13 5 14 6 0 11 0 10 14 6 15 7 1 14 11 3 12 4 15 7 8 0 10 2 13 5 12 4 11 3 9 1 14 6 13 5 10 2 8 0 15 7 14 6 9 1 9 1 10 2 11 3 8 0 0 9 4 26 7 35 3 21 3 20 7 34 6 32 2 17 2 16 6 31 5 29 1 13 1 12 5 28 4 25 0 8 5 27 6 30 7 33 4 24</p></polylist></mesh></geometry></library_geometries>
<library_visual_scenes><visual_scene id="Scene" name="Scene"><node layer="L1" id="Cube1-0L1" name="Cube1-0"><translate sid="translate">0.00000 0.00000 0.00000</translate>
<rotate sid="rotateZ">0 0 1 0.00000</rotate><rotate sid="rotateY">0 1 0 0.00000</rotate><rotate sid="rotateX">1 0 0 0.00000</rotate><scale sid="scale">1.0000 1.0000 1.0000</scale><instance_geometry url="#Cube1-0"><bind_material><technique_common><instance_material symbol="default" target="#default"><bind_vertex_input input_semantic="TEXCOORD" input_set="1" semantic="CHANNEL1"/></instance_material></technique_common></bind_material></instance_geometry></node></visual_scene></library_visual_scenes>
<scene><instance_visual_scene url="#Scene"/></scene>
</COLLADA>

0 comments on commit 07ba7d6

Please sign in to comment.