JSFiddle - React, Tailwind, and code Playground
by realhunts
HTML
<script src="http://threejs.org/build/three.min.js"></script>
<script src="http://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script src="https://rawcdn.githack.com/sciecode/three.js/f4e363a8e0cf6c496f4191192d7eb15110442a7c/examples/js/TexturePainter.js"></script>
JavaScript
// a basic three.js scene
var container, renderer, scene, camera, controls, painter;
var raycaster = new THREE.Raycaster (), mesh;
var mouse = { x: 0, y: 0, down: false };
var canvas = document.createElement ('canvas');
canvas.width = 256; canvas.height = 256;
var context = canvas.getContext ('2d');
context.rect (0, 0, canvas.width, canvas.height);
context.fillStyle = 'aliceblue';
context.fill ();
var texture = new THREE.Texture (canvas);
texture.needsUpdate = true;
init();
animate();
function init() {
// renderer
renderer = new THREE.WebGLRenderer({
antialias: false
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0xccccff);
container = document.createElement('div');
document.body.appendChild(container);
container.appendChild(renderer.domElement);
// scene
scene = new THREE.Scene();
// camera
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.set(0, 200, 800);
camera.lookAt(scene.position);
// (camera) controls
// mouse controls: left button to rotate,
// mouse wheel to zoom, right button to pan
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enabled = false
// light
var light = new THREE.PointLight(0xffffff);
light.position.set(100, 250, 250);
scene.add(light);
// mesh
var sphereGeometry = new THREE.SphereGeometry(100, 32, 16);
var sphereMaterial = new THREE.MeshLambertMaterial({
color: 0xff0000
});
var sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
sphere.position.y = 100;
//scene.add(sphere);
THREE.ImageUtils.crossOrigin = '';
var planeTexture = THREE.ImageUtils.loadTexture('https://rawcdn.githack.com/sciecode/three.js/f4e363a8e0cf6c496f4191192d7eb15110442a7c/examples/textures/UV_Grid_Sm.jpg')
planeTexture.mapping = THREE.UVMapping
planeTexture.wrapS =...