{"id":15827244,"url":"https://github.com/victor-lis/cube-project","last_synced_at":"2026-04-24T16:37:13.302Z","repository":{"id":216311623,"uuid":"740965256","full_name":"Victor-Lis/Cube-Project","owner":"Victor-Lis","description":null,"archived":false,"fork":false,"pushed_at":"2024-01-09T13:08:00.000Z","size":64,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-12T10:12:10.366Z","etag":null,"topics":["html-css-javascript","js-modules","logic-programming","three-js"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Victor-Lis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2024-01-09T12:40:59.000Z","updated_at":"2024-02-19T01:02:00.000Z","dependencies_parsed_at":"2024-01-09T15:42:40.009Z","dependency_job_id":null,"html_url":"https://github.com/Victor-Lis/Cube-Project","commit_stats":null,"previous_names":["victor-lis/cube-project"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Victor-Lis%2FCube-Project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Victor-Lis%2FCube-Project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Victor-Lis%2FCube-Project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Victor-Lis%2FCube-Project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Victor-Lis","download_url":"https://codeload.github.com/Victor-Lis/Cube-Project/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246627325,"owners_count":20808101,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html-css-javascript","js-modules","logic-programming","three-js"],"created_at":"2024-10-05T10:02:29.618Z","updated_at":"2026-04-24T16:37:08.276Z","avatar_url":"https://github.com/Victor-Lis.png","language":"JavaScript","readme":"\n# Cube-Project-ThreeJS\n\nEsse é o um projeto utilizando ThreeJS, uma biblioteca que venho estudando pois acredito que agregue bastante em projetos no Front-End!\n\n# Desafios\n\n- Carregar uma imagem para cada lado do dado;\n- Fazer o dado parar em um ângulo de 90°;\n- Interagir com o botão no HTML.\n\nPor final aprendi algumas coisas interessantes como: \n\n# Na prática\n\n## Carregando lados do triângulo\n```js\nimport * as THREE from 'three'\n\nimport dado1 from '../images/1.png'\nimport dado2 from '../images/2.png'\nimport dado3 from '../images/3.png'\nimport dado4 from '../images/4.png'\nimport dado5 from '../images/5.png'\nimport dado6 from '../images/6.png'\n\n// TextureLoader\nconst textureLoader = new THREE.TextureLoader();\n\nconst textures = [\n    textureLoader.load(dado1),\n    textureLoader.load(dado2),\n    textureLoader.load(dado3),\n    textureLoader.load(dado4),\n    textureLoader.load(dado5),\n    textureLoader.load(dado6)\n];\n\nconst boxGeometry = new THREE.BoxGeometry(1, 1, 1, 6); // Specify 6 faces\n\nconst materials = [];\nfor (let i = 0; i \u003c 6; i++) {\n    materials.push(new THREE.MeshBasicMaterial({ map: textures[i] }));\n}\n\nconst box = new THREE.Mesh(boxGeometry, materials);\n```\n\n## Animação\nA animação abaixo recebe x, y, z de maneira randômica, para sempre cair um aleatório.\nO i é o index atual, similar ao i de um for(let i = 0; i \u003c num; i++).\n```js\nfunction animate(x, y, z, i) {\n\n    // Round each rotation to the nearest multiple of 90 degrees only after 100 rotations\n    if (i \u003e= 100) {\n        box.rotation.x = Math.round(box.rotation.x / (Math.PI / 2)) * (Math.PI / 2) + x;\n        box.rotation.y = Math.round(box.rotation.y / (Math.PI / 2)) * (Math.PI / 2) + y;\n        box.rotation.z = Math.round(box.rotation.z / (Math.PI / 2)) * (Math.PI / 2) + z;\n        camera.position.set(0, 5, 0)\n        camera.lookAt(new THREE.Vector3(0, 0, 0))\n    } else {\n        camera.position.set(3, 5, 0)\n        box.rotation.x += x;\n        box.rotation.y += y;\n        box.rotation.z += z;\n    }\n\n    renderer.render(scene, camera);\n}\n```\n\n## Interagindo com o HTML\nHTML\n```html\n  \u003chead\u003e\n    \u003cscript src=\"./JS/script.js\" type=\"module\" defer\u003e\u003c/script\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ccanvas id=\"dado\" style=\"background-color: #000;\"\u003e\u003c/canvas\u003e   \n    \u003cbutton\u003e Girar \u003c/button\u003e \n  \u003c/body\u003e\n```\n\nJS\n```js\nconst botao = document.querySelector('button');\n\nbotao.addEventListener('click', iniciarAnimacao);\nlet canSpin = true\n\nfunction iniciarAnimacao() {\n\n    if (canSpin) {\n        canSpin = false\n        camera.position.set(3, 5, 0)\n        camera.lookAt(new THREE.Vector3(0, 1, 0))\n\n        let i = 0;\n        let x = (Math.round(Math.random()) / 10)+0.10\n        let y = (Math.round(Math.random()) / 10)+0.10\n        let z = (Math.round(Math.random()) / 10)+0.10\n        let interval = setInterval(() =\u003e {\n            if (i \u003c= 100) {\n                animate(x, y, z, i)\n                i++\n            } else {\n                canSpin = true\n                clearInterval(interval)\n            }\n        }, 25)\n    }\n}\n```\n\n### Screenshots\n\nGirando\n![PrintGirando](https://github.com/Victor-Lis/Cube-Project/blob/master/src/images/PrintGirando.png)\n\nResultado Final\n![Print1](https://github.com/Victor-Lis/Cube-Project/blob/master/src/images/Print1.png)\n\n![Print2](https://github.com/Victor-Lis/Cube-Project/blob/master/src/images/Print2.png)\n\n![Print3](https://github.com/Victor-Lis/Cube-Project/blob/master/src/images/Print3.png)\n\n## Autores\n\n- [@Victor-Lis](https://github.com/Victor-Lis)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictor-lis%2Fcube-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvictor-lis%2Fcube-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictor-lis%2Fcube-project/lists"}