Nhúng các code iframe sau vào web nhé!
<div class="photo360-desktop">
<iframe style="width: 100%;height: 500px;border: 0px" src="https://iconcentral.vn/360view.php"></iframe>
</div>
<iframe src="https://storage.googleapis.com/vrview/2.0/index.html?preview=https://storage.googleapis.com/vrview/examples/coral-preview.jpg&image=https://storage.googleapis.com/vrview/examples/coral.jpg&is_stereo=true&"><span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span> </iframe>
Đối với hình ảnh 360 độ thì bạn chỉ cần có thiết bị hỗ trợ chụp chế độ panorama là được. Trong bài hướng dẫn này mình sẽ dùng kèm với thư viện three.js.
Cách đăng hình 360 độ lên WordPress
Bạn chỉ có thể dùng iframe để chèn hình ảnh 360 độ vào bài viết. Do vậy, công việc của bạn là tạo ra một tập tin PHP có thể hiển thị ảnh 360.
<?php
$src = isset( $_GET['src'] ) ? $_GET['src'] : '';
if ( empty( $src ) ) {
return;
}
$title = isset( $_GET['title'] ) ? $_GET['title'] : 'Hình ảnh 360';
$type = isset( $_GET['type'] ) ? $_GET['type'] : 'equirectangular';
$type = strtolower( $type );
?>
<!DOCTYPE html>
<html lang="vi">
<head>
<title><?php echo $title; ?></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
background-color: #000000;
margin: 0;
overflow: hidden;
}
canvas,
img {
cursor: hand;
}
canvas,
img {
cursor: -webkit-grab;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/90/three.min.js"></script>
<script async>
var camera, scene, renderer;
var isUserInteracting = false,
onMouseDownMouseX = 0, onMouseDownMouseY = 0,
lon = 0, onMouseDownLon = 0,
lat = 0, onMouseDownLat = 0,
phi = 0, theta = 0;
init();
animate();
function init() {
var container, mesh;
container = document.getElementById('container');
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 1100);
camera.target = new THREE.Vector3(0, 0, 0);
scene = new THREE.Scene();
var geometry = new THREE.SphereBufferGeometry(500, 60, 40);
geometry.scale(-1, 1, 1);
var material = new THREE.MeshBasicMaterial({
map: new THREE.TextureLoader().load('<?php echo $src; ?>')
});
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
container.appendChild(renderer.domElement);
document.addEventListener('mousedown', onDocumentMouseDown, false);
document.addEventListener('mousemove', onDocumentMouseMove, false);
document.addEventListener('mouseup', onDocumentMouseUp, false);
document.addEventListener('wheel', onDocumentMouseWheel, false);
document.addEventListener('dragover', function (event) {
event.preventDefault();
event.dataTransfer.dropEffect = 'copy';
}, false);
document.addEventListener('dragenter', function (event) {
document.body.style.opacity = 0.5;
}, false);
document.addEventListener('dragleave', function (event) {
document.body.style.opacity = 1;
}, false);
document.addEventListener('drop', function (event) {
event.preventDefault();
var reader = new FileReader();
reader.addEventListener('load', function (event) {
material.map.image.src = event.target.result;
material.map.needsUpdate = true;
}, false);
reader.readAsDataURL(event.dataTransfer.files[0]);
document.body.style.opacity = 1;
}, false);
window.addEventListener('resize', onWindowResize, false);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function onDocumentMouseDown(event) {
event.preventDefault();
isUserInteracting = true;
onMouseDownMouseX = event.clientX;
onMouseDownMouseY = event.clientY;
onMouseDownLon = lon;
onMouseDownLat = lat;
}
function onDocumentMouseMove(event) {
if (isUserInteracting === true) {
lon = ( onMouseDownMouseX - event.clientX ) * 0.1 + onMouseDownLon;
lat = ( event.clientY - onMouseDownMouseY ) * 0.1 + onMouseDownLat;
}
}
function onDocumentMouseUp(event) {
isUserInteracting = false;
}
function onDocumentMouseWheel(event) {
var fov = camera.fov + event.deltaY * 0.05;
camera.fov = THREE.Math.clamp(fov, 10, 75);
camera.updateProjectionMatrix();
}
function animate() {
requestAnimationFrame(animate);
update();
}
function update() {
if (isUserInteracting === false) {
//lon += 0.1;
}
lat = Math.max(-85, Math.min(85, lat));
phi = THREE.Math.degToRad(90 - lat);
theta = THREE.Math.degToRad(lon);
camera.target.x = 500 * Math.sin(phi) * Math.cos(theta);
camera.target.y = 500 * Math.cos(phi);
camera.target.z = 500 * Math.sin(phi) * Math.sin(theta);
camera.lookAt(camera.target);
renderer.render(scene, camera);
}
</script>
</body>
</html>
Chèn vào web thì như 2 ví dụ bên trên
<iframe src="https://domain.com/360.php?src=http://urlhinhanh.jpg&title=Test+360"></iframe>
Bài viết chưa tốt do mình copy vội! code hoạt động 100% mình sẽ trau chuốt thêm sau, cảm ơn các bạn đã đọc và chúc các bạn thành công!
Bài viết mới:
- Hide product zero price / Hide products without price in WooCommerce
- Tra cứu lịch âm
- Kích hoạt Windows Sandbox trên Windows 10 để chạy file .exe không đáng tin cậy
- Lấy danh mục mặc định của bài viết trong wordpress
- Magnetic reels and escalating wins define the experience at slotmonstercasinos.uk for dedicated players
