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
4549b607
There was an error fetching the commit references. Please try again later.
Commit
4549b607
authored
5 years ago
by
Marek Bařinka
Browse files
Options
Downloads
Patches
Plain Diff
Create MeshObjLoader.java
First not finished and not tested version.
parent
7e8da1d3
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
+100
-0
100 additions, 0 deletions
.../main/java/cz/fidentis/analyst/mesh/io/MeshObjLoader.java
with
100 additions
and
0 deletions
MeshModel/src/main/java/cz/fidentis/analyst/mesh/io/MeshObjLoader.java
0 → 100644
+
100
−
0
View file @
4549b607
package
cz.fidentis.analyst.mesh.io
;
import
com.mokiat.data.front.parser.IOBJParser
;
import
com.mokiat.data.front.parser.OBJDataReference
;
import
com.mokiat.data.front.parser.OBJFace
;
import
com.mokiat.data.front.parser.OBJMesh
;
import
com.mokiat.data.front.parser.OBJModel
;
import
com.mokiat.data.front.parser.OBJNormal
;
import
com.mokiat.data.front.parser.OBJObject
;
import
com.mokiat.data.front.parser.OBJParser
;
import
com.mokiat.data.front.parser.OBJTexCoord
;
import
com.mokiat.data.front.parser.OBJVertex
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
javax.vecmath.Vector3d
;
/**
*
* Expects only one face in one file stored as one object.
* @author Marek Bařinka
*/
public
class
MeshObjLoader
{
public
static
MeshModel
read
(
InputStream
is
)
{
MeshModel
meshModel
=
new
MeshModel
();
try
{
final
IOBJParser
parser
=
new
OBJParser
();
final
OBJModel
model
=
parser
.
parse
(
is
);
if
(
model
.
getObjects
().
isEmpty
())
{
return
null
;
}
OBJObject
object
=
model
.
getObjects
().
get
(
0
);
// Předpokládá se celý obličej jako jeden prvek
List
<
MeshFacet
>
listFacet
=
new
ArrayList
();
for
(
OBJMesh
mesh
:
object
.
getMeshes
())
{
// Sjednotit s facet
MeshFacet
meshFacet
=
new
MeshFacet
();
for
(
OBJFace
face
:
mesh
.
getFaces
())
{
List
<
OBJDataReference
>
references
=
face
.
getReferences
();
List
<
MeshPoint
>
points
=
new
ArrayList
();
for
(
OBJDataReference
reference
:
references
)
{
final
OBJVertex
vertex
=
model
.
getVertex
(
reference
);
Vector3d
coords
=
new
Vector3d
(
vertex
.
x
,
vertex
.
y
,
vertex
.
z
);
Vector3d
norm
=
null
;
Vector3d
texCoords
=
null
;
if
(
reference
.
hasNormalIndex
())
{
final
OBJNormal
normal
=
model
.
getNormal
(
reference
);
norm
=
new
Vector3d
(
normal
.
x
,
normal
.
y
,
normal
.
z
);
}
if
(
reference
.
hasTexCoordIndex
())
{
final
OBJTexCoord
texCoord
=
model
.
getTexCoord
(
reference
);
texCoords
=
new
Vector3d
(
texCoord
.
u
,
texCoord
.
v
,
texCoord
.
w
);
}
MeshPoint
meshPoint
=
new
MeshPoint
(
coords
,
norm
,
texCoords
);
points
.
add
(
meshPoint
);
}
List
<
MeshEdge
>
edges
=
new
ArrayList
();
for
(
int
i
=
1
;
i
<
points
.
size
();
i
++)
{
edges
.
add
(
new
MeshEdge
(
points
.
get
(
i
-
1
),
points
.
get
(
i
)));
}
}
listFacet
.
add
(
meshFacet
);
}
meshModel
.
addFacets
(
listFacet
);
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
MeshObjLoader
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
return
meshModel
;
}
public
static
MeshModel
read
(
File
file
)
{
try
(
InputStream
is
=
new
FileInputStream
(
file
))
{
return
read
(
is
);
}
catch
(
FileNotFoundException
ex
)
{
Logger
.
getLogger
(
MeshObjLoader
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
MeshObjLoader
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
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