Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Analyst WebApp
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fidentis
Analyst WebApp
Commits
f35c07cd
There was an error fetching the commit references. Please try again later.
Commit
f35c07cd
authored
5 years ago
by
Marek Bařinka
Browse files
Options
Downloads
Patches
Plain Diff
Update MeshObjLoader.java
First almost finished version.
parent
1e4feaca
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MeshModel/src/main/java/cz/fidentis/analyst/mesh/io/MeshObjLoader.java
+43
-15
43 additions, 15 deletions
.../main/java/cz/fidentis/analyst/mesh/io/MeshObjLoader.java
with
43 additions
and
15 deletions
MeshModel/src/main/java/cz/fidentis/analyst/mesh/io/MeshObjLoader.java
+
43
−
15
View file @
f35c07cd
...
@@ -11,13 +11,20 @@ import com.mokiat.data.front.parser.OBJObject;
...
@@ -11,13 +11,20 @@ import com.mokiat.data.front.parser.OBJObject;
import
com.mokiat.data.front.parser.OBJParser
;
import
com.mokiat.data.front.parser.OBJParser
;
import
com.mokiat.data.front.parser.OBJTexCoord
;
import
com.mokiat.data.front.parser.OBJTexCoord
;
import
com.mokiat.data.front.parser.OBJVertex
;
import
com.mokiat.data.front.parser.OBJVertex
;
import
cz.fidentis.analyst.mesh.core.MeshEdge
;
import
cz.fidentis.analyst.mesh.core.MeshFace
;
import
cz.fidentis.analyst.mesh.core.MeshFacet
;
import
cz.fidentis.analyst.mesh.core.MeshModel
;
import
cz.fidentis.analyst.mesh.core.MeshPoint
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.logging.Level
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
import
javax.vecmath.Vector3d
;
import
javax.vecmath.Vector3d
;
...
@@ -41,18 +48,25 @@ public class MeshObjLoader {
...
@@ -41,18 +48,25 @@ public class MeshObjLoader {
return
null
;
return
null
;
}
}
OBJObject
object
=
model
.
getObjects
().
get
(
0
);
// Předpokládá se celý obličej jako jeden prvek
// Expecting only one face in file as one object
OBJObject
object
=
model
.
getObjects
().
get
(
0
);
List
<
MeshFacet
>
listFacet
=
new
ArrayList
();
for
(
OBJMesh
mesh
:
object
.
getMeshes
())
{
// Sjednotit s facet
// Our facet = loader mesh, create and fill all facets
for
(
OBJMesh
mesh
:
object
.
getMeshes
())
{
MeshFacet
meshFacet
=
new
MeshFacet
();
MeshFacet
meshFacet
=
new
MeshFacet
();
// Map for all edges with one face. Can't use Set because missing get();
Map
<
MeshEdge
,
MeshEdge
>
oneFaceEdges
=
new
HashMap
();
// Create and fill all faces
for
(
OBJFace
face
:
mesh
.
getFaces
())
{
for
(
OBJFace
face
:
mesh
.
getFaces
())
{
List
<
OBJDataReference
>
references
=
face
.
getReferences
();
List
<
OBJDataReference
>
references
=
face
.
getReferences
();
List
<
MeshPoint
>
p
oints
=
new
ArrayList
();
List
<
MeshPoint
>
faceP
oints
=
new
ArrayList
();
MeshFace
meshFace
=
new
MeshFace
();
// Load all point from one mesh
for
(
OBJDataReference
reference
:
references
)
{
for
(
OBJDataReference
reference
:
references
)
{
final
OBJVertex
vertex
=
model
.
getVertex
(
reference
);
final
OBJVertex
vertex
=
model
.
getVertex
(
reference
);
Vector3d
coords
=
new
Vector3d
(
vertex
.
x
,
vertex
.
y
,
vertex
.
z
);
Vector3d
coords
=
new
Vector3d
(
vertex
.
x
,
vertex
.
y
,
vertex
.
z
);
...
@@ -67,18 +81,33 @@ public class MeshObjLoader {
...
@@ -67,18 +81,33 @@ public class MeshObjLoader {
texCoords
=
new
Vector3d
(
texCoord
.
u
,
texCoord
.
v
,
texCoord
.
w
);
texCoords
=
new
Vector3d
(
texCoord
.
u
,
texCoord
.
v
,
texCoord
.
w
);
}
}
MeshPoint
meshPoint
=
new
MeshPoint
(
coords
,
norm
,
texCoords
);
MeshPoint
meshPoint
=
meshFacet
.
getPoint
(
new
MeshPoint
(
coords
,
norm
,
texCoords
)
)
;
p
oints
.
add
(
meshPoint
);
faceP
oints
.
add
(
meshPoint
);
}
}
// Create edges
List
<
MeshEdge
>
edges
=
new
ArrayList
();
for
(
int
i
=
1
;
i
<=
facePoints
.
size
();
i
++)
{
for
(
int
i
=
1
;
i
<
points
.
size
();
i
++)
{
MeshEdge
meshEdge
=
new
MeshEdge
(
facePoints
.
get
((
i
-
1
)%
facePoints
.
size
()),
facePoints
.
get
((
i
)%
facePoints
.
size
()));
edges
.
add
(
new
MeshEdge
(
points
.
get
(
i
-
1
),
points
.
get
(
i
)));
if
(
oneFaceEdges
.
containsKey
(
meshEdge
))
{
meshEdge
=
oneFaceEdges
.
get
(
meshEdge
);
meshFacet
.
getEdge
(
meshEdge
);
//meshEdge.add this face as second face
oneFaceEdges
.
remove
(
meshEdge
);
}
else
{
oneFaceEdges
.
put
(
meshEdge
,
meshEdge
);
}
meshFace
.
addChild
(
meshEdge
);
}
}
meshFacet
.
addChild
(
meshFace
);
}
}
listFacet
.
add
(
meshFacet
);
// Add remaining edges with only one asociated face, i. e. edge of facet
for
(
MeshEdge
edge
:
oneFaceEdges
.
values
())
{
meshFacet
.
getEdge
(
edge
);
}
meshModel
.
addChild
(
meshFacet
);
}
}
meshModel
.
addFacets
(
listFacet
);
}
catch
(
IOException
ex
)
{
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
MeshObjLoader
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
MeshObjLoader
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
...
@@ -95,6 +124,5 @@ public class MeshObjLoader {
...
@@ -95,6 +124,5 @@ public class MeshObjLoader {
Logger
.
getLogger
(
MeshObjLoader
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
Logger
.
getLogger
(
MeshObjLoader
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
return
null
;
return
null
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment