mirror of
https://github.com/anatolykopyl/vue-three-d-mockup.git
synced 2026-03-26 12:55:08 +00:00
Multiple mockups
This commit is contained in:
@@ -152,7 +152,7 @@ var script = {
|
|||||||
const container = ref(null);
|
const container = ref(null);
|
||||||
let camera;
|
let camera;
|
||||||
let scene;
|
let scene;
|
||||||
let phone;
|
const phones = [];
|
||||||
let renderer;
|
let renderer;
|
||||||
let mouseX = 0;
|
let mouseX = 0;
|
||||||
let mouseY = 0;
|
let mouseY = 0;
|
||||||
@@ -172,6 +172,21 @@ var script = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const phoneInit = (screenSrc, home) => {
|
const phoneInit = (screenSrc, home) => {
|
||||||
|
const phone = new MockupModel({
|
||||||
|
position: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0,
|
||||||
|
...home.position,
|
||||||
|
},
|
||||||
|
rotation: {
|
||||||
|
x: -0.2,
|
||||||
|
y: 0.3,
|
||||||
|
z: 0.06,
|
||||||
|
...home.rotation,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const screenInit = () => {
|
const screenInit = () => {
|
||||||
const scale = 6;
|
const scale = 6;
|
||||||
const width = scale * 9; const height = scale * 19.3;
|
const width = scale * 9; const height = scale * 19.3;
|
||||||
@@ -236,31 +251,42 @@ var script = {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
phone = new MockupModel({
|
|
||||||
position: {
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
z: 0,
|
|
||||||
...home.position,
|
|
||||||
},
|
|
||||||
rotation: {
|
|
||||||
x: -0.2,
|
|
||||||
y: 0.3,
|
|
||||||
z: 0.06,
|
|
||||||
...home.rotation,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
phone.startFloat();
|
phone.startFloat();
|
||||||
scene.add(phone);
|
scene.add(phone);
|
||||||
screenInit();
|
screenInit();
|
||||||
bodyInit();
|
bodyInit();
|
||||||
|
|
||||||
|
return phone;
|
||||||
};
|
};
|
||||||
|
|
||||||
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
|
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
|
||||||
renderer.setSize(container.value.clientWidth, container.value.clientHeight);
|
renderer.setSize(container.value.clientWidth, container.value.clientHeight);
|
||||||
|
|
||||||
environmentInit();
|
environmentInit();
|
||||||
phoneInit(props.screen, { position: props.position, rotation: props.rotation });
|
|
||||||
|
if (Array.isArray(props.screen)) {
|
||||||
|
for (let i = 0; i <= props.screen.length - 1; i += 1) {
|
||||||
|
phones.push(
|
||||||
|
phoneInit(
|
||||||
|
props.screen[i],
|
||||||
|
{
|
||||||
|
position: props.position[i],
|
||||||
|
rotation: props.rotation[i],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
phones.push(
|
||||||
|
phoneInit(
|
||||||
|
props.screen,
|
||||||
|
{
|
||||||
|
position: props.position,
|
||||||
|
rotation: props.rotation,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
container.value.appendChild(renderer.domElement);
|
container.value.appendChild(renderer.domElement);
|
||||||
}
|
}
|
||||||
@@ -273,23 +299,31 @@ var script = {
|
|||||||
|
|
||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
|
|
||||||
if (phone) {
|
if (phones.length) {
|
||||||
|
phones.forEach((phone) => {
|
||||||
phone.animation(deltaTime, { x: mouseX, y: mouseY, z: camera.position.z });
|
phone.animation(deltaTime, { x: mouseX, y: mouseY, z: camera.position.z });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.render(scene, camera);
|
renderer.render(scene, camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMouseEnter() {
|
function handleMouseEnter() {
|
||||||
if (phone) {
|
if (phones.length) {
|
||||||
|
phones.forEach((phone) => {
|
||||||
phone.animation = phone.lookAtAnim;
|
phone.animation = phone.lookAtAnim;
|
||||||
phone.goingHome = false;
|
phone.goingHome = false;
|
||||||
clearTimeout(phone.homeTimeout);
|
clearTimeout(phone.homeTimeout);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMouseLeave() {
|
function handleMouseLeave() {
|
||||||
if (phone) { phone.animation = phone.homeAnim; }
|
if (phones.length) {
|
||||||
|
phones.forEach((phone) => {
|
||||||
|
phone.animation = phone.homeAnim;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMouseMove(event) {
|
function handleMouseMove(event) {
|
||||||
|
|||||||
29
src/Demo.vue
29
src/Demo.vue
@@ -3,22 +3,25 @@
|
|||||||
<h1>
|
<h1>
|
||||||
vue-three-d-mockup
|
vue-three-d-mockup
|
||||||
</h1>
|
</h1>
|
||||||
<div class="showcase">
|
|
||||||
<Mockup
|
<Mockup
|
||||||
v-if="vidReady"
|
v-if="vidReady"
|
||||||
class="mockup"
|
class="mockup"
|
||||||
:screen="$refs.video"
|
:screen="[$refs.video, require('./assets/screen.png')]"
|
||||||
/>
|
:position="[
|
||||||
<Mockup
|
{
|
||||||
class="mockup"
|
x: -50
|
||||||
:screen="require('./assets/screen.png')"
|
},
|
||||||
:rotation="{
|
{
|
||||||
|
x: 50
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
:rotation="[{}, {
|
||||||
y: -0.3,
|
y: -0.3,
|
||||||
z: -0.06,
|
z: -0.06,
|
||||||
}"
|
}]"
|
||||||
phoneClr="black"
|
phoneClr="black"
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<video
|
<video
|
||||||
src="@/assets/screen.mp4"
|
src="@/assets/screen.mp4"
|
||||||
@@ -67,14 +70,8 @@ video {
|
|||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.showcase {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-evenly;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mockup {
|
.mockup {
|
||||||
width: 500px;
|
width: 800px;
|
||||||
height: 500px;
|
height: 500px;
|
||||||
margin: auto;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export default {
|
|||||||
const container = ref(null);
|
const container = ref(null);
|
||||||
let camera;
|
let camera;
|
||||||
let scene;
|
let scene;
|
||||||
let phone;
|
const phones = [];
|
||||||
let renderer;
|
let renderer;
|
||||||
let mouseX = 0;
|
let mouseX = 0;
|
||||||
let mouseY = 0;
|
let mouseY = 0;
|
||||||
@@ -63,6 +63,21 @@ export default {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const phoneInit = (screenSrc, home) => {
|
const phoneInit = (screenSrc, home) => {
|
||||||
|
const phone = new MockupModel({
|
||||||
|
position: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0,
|
||||||
|
...home.position,
|
||||||
|
},
|
||||||
|
rotation: {
|
||||||
|
x: -0.2,
|
||||||
|
y: 0.3,
|
||||||
|
z: 0.06,
|
||||||
|
...home.rotation,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const screenInit = () => {
|
const screenInit = () => {
|
||||||
const scale = 6;
|
const scale = 6;
|
||||||
const width = scale * 9; const height = scale * 19.3;
|
const width = scale * 9; const height = scale * 19.3;
|
||||||
@@ -127,31 +142,42 @@ export default {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
phone = new MockupModel({
|
|
||||||
position: {
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
z: 0,
|
|
||||||
...home.position,
|
|
||||||
},
|
|
||||||
rotation: {
|
|
||||||
x: -0.2,
|
|
||||||
y: 0.3,
|
|
||||||
z: 0.06,
|
|
||||||
...home.rotation,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
phone.startFloat();
|
phone.startFloat();
|
||||||
scene.add(phone);
|
scene.add(phone);
|
||||||
screenInit();
|
screenInit();
|
||||||
bodyInit();
|
bodyInit();
|
||||||
|
|
||||||
|
return phone;
|
||||||
};
|
};
|
||||||
|
|
||||||
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
|
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
|
||||||
renderer.setSize(container.value.clientWidth, container.value.clientHeight);
|
renderer.setSize(container.value.clientWidth, container.value.clientHeight);
|
||||||
|
|
||||||
environmentInit();
|
environmentInit();
|
||||||
phoneInit(props.screen, { position: props.position, rotation: props.rotation });
|
|
||||||
|
if (Array.isArray(props.screen)) {
|
||||||
|
for (let i = 0; i <= props.screen.length - 1; i += 1) {
|
||||||
|
phones.push(
|
||||||
|
phoneInit(
|
||||||
|
props.screen[i],
|
||||||
|
{
|
||||||
|
position: props.position[i],
|
||||||
|
rotation: props.rotation[i],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
phones.push(
|
||||||
|
phoneInit(
|
||||||
|
props.screen,
|
||||||
|
{
|
||||||
|
position: props.position,
|
||||||
|
rotation: props.rotation,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
container.value.appendChild(renderer.domElement);
|
container.value.appendChild(renderer.domElement);
|
||||||
}
|
}
|
||||||
@@ -164,23 +190,31 @@ export default {
|
|||||||
|
|
||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
|
|
||||||
if (phone) {
|
if (phones.length) {
|
||||||
|
phones.forEach((phone) => {
|
||||||
phone.animation(deltaTime, { x: mouseX, y: mouseY, z: camera.position.z });
|
phone.animation(deltaTime, { x: mouseX, y: mouseY, z: camera.position.z });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.render(scene, camera);
|
renderer.render(scene, camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMouseEnter() {
|
function handleMouseEnter() {
|
||||||
if (phone) {
|
if (phones.length) {
|
||||||
|
phones.forEach((phone) => {
|
||||||
phone.animation = phone.lookAtAnim;
|
phone.animation = phone.lookAtAnim;
|
||||||
phone.goingHome = false;
|
phone.goingHome = false;
|
||||||
clearTimeout(phone.homeTimeout);
|
clearTimeout(phone.homeTimeout);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMouseLeave() {
|
function handleMouseLeave() {
|
||||||
if (phone) { phone.animation = phone.homeAnim; }
|
if (phones.length) {
|
||||||
|
phones.forEach((phone) => {
|
||||||
|
phone.animation = phone.homeAnim;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMouseMove(event) {
|
function handleMouseMove(event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user