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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
8cf68aeb
Commit
8cf68aeb
authored
7 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
simple model matrix injector
parent
ec7670c8
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
src/mol-gl/model.ts
+57
-0
57 additions, 0 deletions
src/mol-gl/model.ts
with
57 additions
and
0 deletions
src/mol-gl/model.ts
0 → 100644
+
57
−
0
View file @
8cf68aeb
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import
REGL
=
require
(
'
regl
'
);
import
{
Mat4
,
Quat
,
Vec3
}
from
'
mol-math/linear-algebra
'
import
{
defaults
}
from
'
mol-util
'
;
const
tmpMat4
=
Mat4
()
type
ModelProps
=
{
rotation
?:
Quat
,
position
?:
Vec3
,
scale
?:
Vec3
}
function
createModel
(
regl
:
REGL
.
Regl
,
props
:
ModelProps
=
{})
{
const
transform
=
Mat4
.
identity
()
const
rotation
=
defaults
(
props
.
rotation
,
Quat
.
identity
())
const
position
=
defaults
(
props
.
position
,
Vec3
.
zero
())
const
scale
=
defaults
(
props
.
scale
,
Vec3
.
create
(
1
,
1
,
1
))
const
draw
=
regl
({
context
:
{
transform
,
rotation
,
position
,
scale
},
uniforms
:
{
model
(
ctx
:
REGL
.
DefaultContext
,
props
:
any
=
{})
{
const
model
=
Mat4
.
identity
()
if
(
'
rotation
'
in
props
)
Quat
.
copy
(
rotation
,
props
.
rotation
)
if
(
'
position
'
in
props
)
Vec3
.
copy
(
position
,
props
.
position
)
if
(
'
scale
'
in
props
)
Vec3
.
copy
(
scale
,
props
.
scale
)
Mat4
.
translate
(
model
,
model
,
position
)
Mat4
.
mul
(
model
,
model
,
Mat4
.
fromQuat
(
tmpMat4
,
rotation
))
Mat4
.
scale
(
model
,
model
,
scale
)
if
(
'
transform
'
in
props
)
Mat4
.
mul
(
model
,
props
.
transform
,
model
)
Mat4
.
copy
(
transform
,
model
)
return
model
}
}
})
return
Object
.
assign
(
draw
,
{
get
transform
()
{
return
transform
},
get
position
()
{
return
position
},
get
rotation
()
{
return
rotation
},
get
scale
()
{
return
scale
},
})
}
export
default
createModel
\ No newline at end of file
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