Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
611ead8b
Commit
611ead8b
authored
6 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
ply, handle missing normals or colors
parent
8bab72ea
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mol-model-formats/shape/ply.ts
+32
-19
32 additions, 19 deletions
src/mol-model-formats/shape/ply.ts
with
32 additions
and
19 deletions
src/mol-model-formats/shape/ply.ts
+
32
−
19
View file @
611ead8b
...
@@ -31,13 +31,14 @@ async function getPlyMesh(ctx: RuntimeContext, vertex: PlyTable, face: PlyList,
...
@@ -31,13 +31,14 @@ async function getPlyMesh(ctx: RuntimeContext, vertex: PlyTable, face: PlyList,
const
nx
=
vertex
.
getProperty
(
'
nx
'
)
const
nx
=
vertex
.
getProperty
(
'
nx
'
)
const
ny
=
vertex
.
getProperty
(
'
ny
'
)
const
ny
=
vertex
.
getProperty
(
'
ny
'
)
const
nz
=
vertex
.
getProperty
(
'
nz
'
)
const
nz
=
vertex
.
getProperty
(
'
nz
'
)
if
(
!
nx
||
!
ny
||
!
nz
)
throw
new
Error
(
'
missing normal properties
'
)
// TODO calculate normals when not provided
const
hasNormals
=
!!
nx
&&
!!
ny
&&
!!
nz
for
(
let
i
=
0
,
il
=
vertex
.
rowCount
;
i
<
il
;
++
i
)
{
for
(
let
i
=
0
,
il
=
vertex
.
rowCount
;
i
<
il
;
++
i
)
{
if
(
i
%
10000
===
0
&&
ctx
.
shouldUpdate
)
await
ctx
.
update
({
current
:
i
,
max
:
il
,
message
:
`adding vertex
${
i
}
`
})
if
(
i
%
10000
===
0
&&
ctx
.
shouldUpdate
)
await
ctx
.
update
({
current
:
i
,
max
:
il
,
message
:
`adding vertex
${
i
}
`
})
ChunkedArray
.
add3
(
vertices
,
x
.
value
(
i
),
y
.
value
(
i
),
z
.
value
(
i
))
ChunkedArray
.
add3
(
vertices
,
x
.
value
(
i
),
y
.
value
(
i
),
z
.
value
(
i
))
ChunkedArray
.
add3
(
normals
,
nx
.
value
(
i
),
ny
.
value
(
i
),
nz
.
value
(
i
));
if
(
hasNormals
)
ChunkedArray
.
add3
(
normals
,
nx
!
.
value
(
i
),
ny
!
.
value
(
i
),
nz
!
.
value
(
i
));
ChunkedArray
.
add
(
groups
,
groupIds
[
i
])
ChunkedArray
.
add
(
groups
,
groupIds
[
i
])
}
}
...
@@ -47,7 +48,12 @@ async function getPlyMesh(ctx: RuntimeContext, vertex: PlyTable, face: PlyList,
...
@@ -47,7 +48,12 @@ async function getPlyMesh(ctx: RuntimeContext, vertex: PlyTable, face: PlyList,
const
{
entries
}
=
face
.
value
(
i
)
const
{
entries
}
=
face
.
value
(
i
)
ChunkedArray
.
add3
(
indices
,
entries
[
0
],
entries
[
1
],
entries
[
2
])
ChunkedArray
.
add3
(
indices
,
entries
[
0
],
entries
[
1
],
entries
[
2
])
}
}
return
MeshBuilder
.
getMesh
(
builderState
);
const
m
=
MeshBuilder
.
getMesh
(
builderState
);
m
.
normalsComputed
=
hasNormals
await
Mesh
.
computeNormals
(
m
).
runInContext
(
ctx
)
return
m
}
}
function
getGrouping
(
count
:
number
,
column
?:
Column
<
number
>
)
{
function
getGrouping
(
count
:
number
,
column
?:
Column
<
number
>
)
{
...
@@ -66,10 +72,9 @@ async function getShape(ctx: RuntimeContext, plyFile: PlyFile, props: PD.Values<
...
@@ -66,10 +72,9 @@ async function getShape(ctx: RuntimeContext, plyFile: PlyFile, props: PD.Values<
const
vertex
=
plyFile
.
getElement
(
'
vertex
'
)
as
PlyTable
const
vertex
=
plyFile
.
getElement
(
'
vertex
'
)
as
PlyTable
if
(
!
vertex
)
throw
new
Error
(
'
missing vertex element
'
)
if
(
!
vertex
)
throw
new
Error
(
'
missing vertex element
'
)
const
red
=
vertex
.
getProperty
(
vp
.
red
)
const
red
=
vertex
.
getProperty
(
vp
.
red
)
||
Column
.
ofConst
(
127
,
vertex
.
rowCount
,
Column
.
Schema
.
int
)
const
green
=
vertex
.
getProperty
(
vp
.
green
)
const
green
=
vertex
.
getProperty
(
vp
.
green
)
||
Column
.
ofConst
(
127
,
vertex
.
rowCount
,
Column
.
Schema
.
int
)
const
blue
=
vertex
.
getProperty
(
vp
.
blue
)
const
blue
=
vertex
.
getProperty
(
vp
.
blue
)
||
Column
.
ofConst
(
127
,
vertex
.
rowCount
,
Column
.
Schema
.
int
)
if
(
!
red
||
!
green
||
!
blue
)
throw
new
Error
(
'
missing color properties
'
)
const
face
=
plyFile
.
getElement
(
'
face
'
)
as
PlyList
const
face
=
plyFile
.
getElement
(
'
face
'
)
as
PlyList
if
(
!
face
)
throw
new
Error
(
'
missing face element
'
)
if
(
!
face
)
throw
new
Error
(
'
missing face element
'
)
...
@@ -95,13 +100,20 @@ export const PlyShapeParams = {
...
@@ -95,13 +100,20 @@ export const PlyShapeParams = {
vertexProperties
:
PD
.
Group
({
vertexProperties
:
PD
.
Group
({
group
:
PD
.
Select
(
''
as
string
,
[[
''
,
''
]]),
group
:
PD
.
Select
(
''
as
string
,
[[
''
,
''
]]),
red
:
PD
.
Select
(
'
red
'
as
string
,
[[
'
red
'
,
'
red
'
]]),
red
:
PD
.
Select
(
''
as
string
,
[[
''
,
''
]]),
green
:
PD
.
Select
(
'
green
'
as
string
,
[[
'
green
'
,
'
green
'
]]),
green
:
PD
.
Select
(
''
as
string
,
[[
'
'
,
'
'
]]),
blue
:
PD
.
Select
(
'
blue
'
as
string
,
[[
'
blue
'
,
'
blue
'
]]),
blue
:
PD
.
Select
(
''
as
string
,
[[
'
'
,
'
'
]]),
},
{
isExpanded
:
true
}),
},
{
isExpanded
:
true
}),
}
}
export
type
PlyShapeParams
=
typeof
PlyShapeParams
export
type
PlyShapeParams
=
typeof
PlyShapeParams
function
setGroupDefault
<
T
>
(
group
:
PD
.
Group
<
any
>
,
name
:
string
,
defaultValue
:
T
)
{
group
.
params
[
name
].
defaultValue
=
defaultValue
group
.
defaultValue
.
group
=
defaultValue
}
function
setSelectOptions
(
select
:
PD
.
Select
<
string
>
,
options
:
[
string
,
string
][])
{
select
.
options
=
options
;
}
export
function
getPlyShapeParams
(
plyFile
:
PlyFile
)
{
export
function
getPlyShapeParams
(
plyFile
:
PlyFile
)
{
const
params
=
PD
.
clone
(
PlyShapeParams
)
const
params
=
PD
.
clone
(
PlyShapeParams
)
...
@@ -112,17 +124,18 @@ export function getPlyShapeParams(plyFile: PlyFile) {
...
@@ -112,17 +124,18 @@ export function getPlyShapeParams(plyFile: PlyFile) {
const
name
=
vertex
.
propertyNames
[
i
]
const
name
=
vertex
.
propertyNames
[
i
]
options
.
push
([
name
,
name
])
options
.
push
([
name
,
name
])
}
}
const
vp
=
params
.
vertexProperties
.
params
;
const
vp
=
params
.
vertexProperties
;
(
vp
.
group
as
PD
.
Select
<
string
>
).
options
=
options
;
setSelectOptions
(
vp
.
params
.
group
as
PD
.
Select
<
string
>
,
options
)
;
(
vp
.
red
as
PD
.
Select
<
string
>
).
options
=
options
;
setSelectOptions
(
vp
.
params
.
red
as
PD
.
Select
<
string
>
,
options
)
;
(
vp
.
green
as
PD
.
Select
<
string
>
).
options
=
options
;
setSelectOptions
(
vp
.
params
.
green
as
PD
.
Select
<
string
>
,
options
)
;
(
vp
.
blue
as
PD
.
Select
<
string
>
).
options
=
options
;
setSelectOptions
(
vp
.
params
.
blue
as
PD
.
Select
<
string
>
,
options
)
;
// TODO harcoded as convenience for data provided by MegaMol
// TODO harcoded as convenience for data provided by MegaMol
if
(
vertex
.
propertyNames
.
includes
(
'
atomid
'
))
{
if
(
vertex
.
propertyNames
.
includes
(
'
atomid
'
))
setGroupDefault
(
vp
,
'
group
'
,
'
atomid
'
)
vp
.
group
.
defaultValue
=
'
atomid
'
params
.
vertexProperties
.
defaultValue
.
group
=
'
atomid
'
if
(
vertex
.
propertyNames
.
includes
(
'
red
'
))
setGroupDefault
(
vp
,
'
red
'
,
'
red
'
)
}
if
(
vertex
.
propertyNames
.
includes
(
'
green
'
))
setGroupDefault
(
vp
,
'
green
'
,
'
green
'
)
if
(
vertex
.
propertyNames
.
includes
(
'
blue
'
))
setGroupDefault
(
vp
,
'
blue
'
,
'
blue
'
)
}
}
return
params
return
params
}
}
...
...
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