Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Robot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
celmart
Robot
Commits
28454e48
Commit
28454e48
authored
Jan 12, 2022
by
celmart
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
712ca73d
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
RobotFinal.js
+258
-0
258 additions, 0 deletions
RobotFinal.js
with
258 additions
and
0 deletions
RobotFinal.js
0 → 100644
+
258
−
0
View file @
28454e48
var
scene
,
camera
,
renderer
,
geometry
,
materialcube
,
sphere
,
cylindre
,
circle
;
var
xSpeed
=
1.0
;
var
direction
=
"
stop
"
;
function
init
(){
scene
=
new
THREE
.
Scene
();
scene
.
background
=
new
THREE
.
Color
(
0xB7D5E5
);
camera
=
new
THREE
.
PerspectiveCamera
(
75
,
window
.
innerWidth
/
window
.
innerHeight
,
0.1
,
1000
);
camera
.
position
.
z
=
3
;
renderer
=
new
THREE
.
WebGLRenderer
({
antialias
:
true
});
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
// Añade la salida del renderer al documento HTML
document
.
body
.
appendChild
(
renderer
.
domElement
);
//Luz ambiente
var
ambiColor
=
"
#0c0c0c
"
;
var
ambientLight
=
new
THREE
.
AmbientLight
(
ambiColor
);
scene
.
add
(
ambientLight
);
//Fuente de luz puntual
var
pointColor
=
"
#ccffcc
"
;
var
pointLight
=
new
THREE
.
PointLight
(
pointColor
);
pointLight
.
distance
=
100
;
//Distancia de la luz
pointLight
.
position
.
set
(
3
,
-
20
,
-
20
);
pointLight
.
intensity
=
1
;
pointLight
.
visible
=
true
;
scene
.
add
(
pointLight
);
//Luz direccional
const
light
=
new
THREE
.
DirectionalLight
();
light
.
position
.
set
(
0
,
-
3
,
2
);
scene
.
add
(
light
);
var
singleGeometryCabeza
=
new
THREE
.
Geometry
();
var
singleGeometryCuerpo
=
new
THREE
.
Geometry
();
//Este es un material que considera los efectos de
//la luz y se utiliza para crear objetos opacos y opacos.
texturaCabeza
=
new
THREE
.
TextureLoader
().
load
(
"
http://virtual.lab.inf.uva.es:27182/texturas/texturaCabeza.JPG
"
);
material
=
new
THREE
.
MeshLambertMaterial
({
map
:
texturaCabeza
});
//Esfera para la cabeza
geometry
=
new
THREE
.
SphereGeometry
(
0.3
,
20
,
10
);
sphere
=
new
THREE
.
Mesh
(
geometry
);
sphere
.
position
.
y
=
1
;
sphere
.
updateMatrix
();
singleGeometryCabeza
.
merge
(
sphere
.
geometry
,
sphere
.
matrix
);
//esfera para el ojo derecho
geometry
=
new
THREE
.
CircleGeometry
(
0.06
,
32
);
circledcha
=
new
THREE
.
Mesh
(
geometry
);
circledcha
.
position
.
x
=
0.1
;
circledcha
.
position
.
y
=
1
;
circledcha
.
position
.
z
=
0.29
;
circledcha
.
updateMatrix
();
singleGeometryCabeza
.
merge
(
circledcha
.
geometry
,
circledcha
.
matrix
);
//esfera blanco para el ojo izquierdo
geometry
=
new
THREE
.
CircleGeometry
(
0.06
,
32
);
circleizda
=
new
THREE
.
Mesh
(
geometry
);
circleizda
.
position
.
x
=-
0.1
;
circleizda
.
position
.
y
=
1
;
circleizda
.
position
.
z
=
0.29
;
circleizda
.
updateMatrix
();
singleGeometryCabeza
.
merge
(
circleizda
.
geometry
,
circleizda
.
matrix
);
var
mesh
=
new
THREE
.
Mesh
(
singleGeometryCabeza
,
material
);
scene
.
add
(
mesh
);
//CUERPO
//Cilindro para el cuello
geometry
=
new
THREE
.
CylinderGeometry
(
0.08
,
0.08
,
0.4
,
10
);
cylinderneck
=
new
THREE
.
Mesh
(
geometry
);
cylinderneck
.
position
.
y
=
0.7
;
cylinderneck
.
updateMatrix
();
singleGeometryCuerpo
.
merge
(
cylinderneck
.
geometry
,
cylinderneck
.
matrix
);
//Cubo para el cuerpo
var
anchura
=
0.5
;
var
altura
=
1
;
var
profundidad
=
0.5
;
geometry
=
new
THREE
.
BoxGeometry
(
anchura
,
altura
,
profundidad
);
cube
=
new
THREE
.
Mesh
(
geometry
);
cube
.
position
.
x
=
0.0
;
cube
.
position
.
y
=
0.0
;
cube
.
position
.
z
=
0.0
;
cube
.
updateMatrix
();
singleGeometryCuerpo
.
merge
(
cube
.
geometry
,
cube
.
matrix
);
//Cubos para los brazos
//Brazo derecho
anchura
=
0.6
;
altura
=
0.2
;
profundidad
=
0.2
;
geometry
=
new
THREE
.
BoxGeometry
(
anchura
,
altura
,
profundidad
);
cubedcha
=
new
THREE
.
Mesh
(
geometry
);
cubedcha
.
position
.
x
=
0.5
;
cubedcha
.
position
.
y
=
0.25
;
cubedcha
.
updateMatrix
();
singleGeometryCuerpo
.
merge
(
cubedcha
.
geometry
,
cubedcha
.
matrix
);
//Brazo izquierdo
geometry
=
new
THREE
.
BoxGeometry
(
anchura
,
altura
,
profundidad
);
cubeizda
=
new
THREE
.
Mesh
(
geometry
);
cubeizda
.
position
.
x
=-
0.5
;
cubeizda
.
position
.
y
=
0.25
;
cubeizda
.
updateMatrix
();
singleGeometryCuerpo
.
merge
(
cubeizda
.
geometry
,
cubeizda
.
matrix
);
//Cilindros para las piernas
//Pierna derecha
geometry
=
new
THREE
.
CylinderGeometry
(
0.08
,
0.08
,
0.6
,
10
);
cylinderdcha
=
new
THREE
.
Mesh
(
geometry
);
cylinderdcha
.
position
.
x
=
0.15
;
cylinderdcha
.
position
.
y
=-
0.8
;
cylinderdcha
.
updateMatrix
();
singleGeometryCuerpo
.
merge
(
cylinderdcha
.
geometry
,
cylinderdcha
.
matrix
);
//Pierna izquierda
geometry
=
new
THREE
.
CylinderGeometry
(
0.08
,
0.08
,
0.6
,
10
);
cylinderizda
=
new
THREE
.
Mesh
(
geometry
);
cylinderizda
.
position
.
x
=-
0.15
;
cylinderizda
.
position
.
y
=-
0.8
;
cylinderizda
.
updateMatrix
();
singleGeometryCuerpo
.
merge
(
cylinderizda
.
geometry
,
cylinderizda
.
matrix
);
//Este es un material simple que calcula el color de la superficie
//del objeto en función del vector normal.
//var materialCuerpo= new THREE.MeshNormalMaterial();
//Este es un material que considera los efectos de la luz
//y se utiliza para crear objetos brillantes.
//Material para el cuerpo
texturaCuerpo
=
new
THREE
.
TextureLoader
().
load
(
"
http://virtual.lab.inf.uva.es:27182/texturas/texturaCuerpo.JPG
"
);
var
materialCuerpo
=
new
THREE
.
MeshPhongMaterial
({
map
:
texturaCuerpo
});
var
meshCuerpo
=
new
THREE
.
Mesh
(
singleGeometryCuerpo
,
materialCuerpo
);
scene
.
add
(
meshCuerpo
);
camera
.
lookAt
(
scene
.
position
);
//controles
createControls
();
renderer
.
render
(
scene
,
camera
);
document
.
addEventListener
(
"
keydown
"
,
onDocumentKeyDown
,
false
);
function
onDocumentKeyDown
(
event
){
var
keyCode
=
event
.
which
;
// Flecha Izda
if
(
keyCode
==
37
){
mesh
.
position
.
x
-=
0.1
;
meshCuerpo
.
position
.
x
-=
0.1
;
//Flecha Derecha
}
else
if
(
keyCode
==
39
){
mesh
.
position
.
x
+=
0.1
;
meshCuerpo
.
position
.
x
+=
0.1
;
//Flecha Arriba
}
else
if
(
keyCode
==
38
){
mesh
.
position
.
y
+=
0.1
;
meshCuerpo
.
position
.
y
+=
0.1
;
//Flecha abajo
}
else
if
(
keyCode
==
40
){
mesh
.
position
.
y
-=
0.1
;
meshCuerpo
.
position
.
y
-=
0.1
;
//Teclaspace
}
else
if
(
keyCode
==
32
){
mesh
.
position
.
x
=
0.0
;
mesh
.
position
.
y
=
0.0
;
meshCuerpo
.
position
.
x
=
0.0
;
meshCuerpo
.
position
.
y
=
0.0
;
//Girar la cabeza al lado izquierdo
//Tecla a
}
else
if
(
keyCode
==
65
){
mesh
.
rotation
.
y
-=
0.1
;
//Girar la cabeza al lado derecho
//Tecla d
}
else
if
(
keyCode
==
68
){
mesh
.
rotation
.
y
+=
0.1
;
//Girar el cuerpo hacia la izquierda
//Tecla q
}
else
if
(
keyCode
==
81
){
meshCuerpo
.
rotation
.
y
-=
0.1
;
//Girar el cuerpo para la derecha
//Tecla e
}
else
if
(
keyCode
==
69
){
meshCuerpo
.
rotation
.
y
+=
0.1
;
//Gira el robot entero a la izqueirda
//Tecla g
}
else
if
(
keyCode
==
71
){
mesh
.
rotation
.
y
-=
0.1
;
meshCuerpo
.
rotation
.
y
-=
0.1
;
//Gira el robot entero a la derecha
//Letra h
}
else
if
(
keyCode
==
72
){
mesh
.
rotation
.
y
+=
0.1
;
meshCuerpo
.
rotation
.
y
+=
0.1
;
}
//z mueve cabeza a la izquierda
else
if
(
keyCode
==
90
){
mesh
.
position
.
x
-=
0.1
;
}
//x mueve cabeza a la derecha
else
if
(
keyCode
==
88
){
mesh
.
position
.
x
+=
0.1
;
}
//c mueve cuerpo a la izquierda
else
if
(
keyCode
==
67
){
meshCuerpo
.
position
.
x
-=
0.1
;
}
//v mueve cuerpo a la derecha
else
if
(
keyCode
==
86
){
meshCuerpo
.
position
.
x
+=
0.1
;
}
};
function
render
(){
requestAnimationFrame
(
render
);
controls
.
update
();
renderer
.
render
(
scene
,
camera
);
};
render
();
}
function
createControls
()
{
controls
=
new
THREE
.
TrackballControls
(
camera
,
renderer
.
domElement
);
controls
.
rotateSpeed
=
1.0
;
controls
.
zoomSpeed
=
1.2
;
controls
.
panSpeed
=
0.8
;
controls
.
keys
=
[
65
,
83
,
68
];
}
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