JSFiddle - React, Tailwind, and code Playground

by Akbar1909

HTML

<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
    
<script type="importmap">
	{
		"imports": {
			"three": "https://unpkg.com/three/build/three.module.js",
      "three/addons/": "https://unpkg.com/three/examples/jsm/"
		}
	}
</script>

CSS

body {
	margin: 0px;
}

JavaScript

// Simple three.js example

import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

let plane, renderer, scene, camera, controls;

const width=window.innerWidth;
const height=window.innerHeight;

init();
animate();



function init() {

    // renderer
    renderer = new THREE.WebGLRenderer();
    renderer.setSize( width, height );
    renderer.setPixelRatio( window.devicePixelRatio );
    document.body.appendChild( renderer.domElement );

    // scene
    scene = new THREE.Scene();
    
    // camera
    camera = new THREE.OrthographicCamera( width / - 2, width / 2, height / 2, height / - 2, 1, 1000);
    camera.position.set( 20, 20, 0 );
    

    // controls
    controls = new OrbitControls( camera, renderer.domElement );
    
    // ambient
    scene.add( new THREE.AmbientLight( 0x222222 ) );
    
    // light
    const light = new THREE.DirectionalLight( 0xffffff, 1 );
    light.position.set( 20,20, 20 );
    scene.add( light );
    
    // axes
    scene.add( new THREE.AxesHelper( 20 ) );

    // geometry
    const geometry = new THREE.PlaneGeometry(100,100);
    
    // material
    const material = new THREE.MeshPhongMaterial( {
        color: 0x00ffff
    } );
    
      // mesh
    plane = new THREE.Mesh( geometry, material );
    
    const rectShape=new THREE.Shape();
    rectShape.moveTo(10,20);
    rectShape.moveTo(30,20);
    rectShape.moveTo(30,10)
    rectShape.moveTo(10,10);
    
    
     const rectGeometry = new THREE.ShapeGeometry(rectShape);
    
   const rectMaterial = new THREE.MeshLambertMaterial({
                    color: 0xff0000,
                  
                });
    
                
     
   const rect=new THREE.Mesh(rectGeometry, rectMaterial);
   rect.userData.id='test'

    plane.add(rect)
  
    scene.add( plane );
    
    window.addEventListener('click',onClick,false)
    
}

function onClick(){
   console.log(plane.children[0].position)
   
   const...