Skip to content

a4-sameer-desai #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
package-lock.json
.DS_Store
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
60 changes: 11 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,23 @@
Assignment 4 - Creative Coding: Interactive Multimedia Experiences
===
## a4-sameer-desai

Due: October 2nd, by 11:59 AM.
Glitch url: couldn't get working
Song used: https://soundcloud.com/knowwless/perfect-pair-ft-jel

For this assignment we will focus on client-side development using popular audio/graphics/visualization technologies. The goal of this assignment is to refine our JavaScript knowledge while exploring the multimedia capabilities of the browser.
![](https://github.com/SmeeBoi/a4-sameer-desai/blob/main/assets/a4visual.gif)

[WebAudio / Canvas Tutorial](https://github.com/cs-4241-2023/cs4241-2023.github.io/blob/main/using.webaudio_and_canvas.md)
[SVG + D3 tutorial](https://github.com/cs-4241-2023/cs-4241-2023.github.io/blob/main/using.svg_and_d3.md)
The visualizer is four spheres moving in a circle which scale with the volume of the music. User clicks start button to start music. Then user can click and drag with standard orbit controls to change view and scrolling zooms in and out of the scene. Then user can click spacebar to play/pause music.

Baseline Requirements
---
Goal: Create a 3D scene with multiple shapes which scale with volume of music. When the music is louder, the shapes get larger and when the music is softer, the shapes get smaller.

Your application is required to implement the following functionalities:
Challenges: Yes

- A server created using Express. This server can be as simple as needed.
- A client-side interactive experience using at least one of the following web technologies frameworks.
- [Three.js](https://threejs.org/): A library for 3D graphics / VR experiences
- [D3.js](https://d3js.org): A library that is primarily used for interactive data visualizations
- [Canvas](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API): A 2D raster drawing API included in all modern browsers
- [SVG](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API): A 2D vector drawing framework that enables shapes to be defined via XML.
- [Web Audio API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API): An API for audio synthesis, analysis, processing, and file playback.
- A user interface for interaction with your project, which must expose at least four parameters for user control. [tweakpane](https://cocopon.github.io/tweakpane/) is highly recommended for this, but you can also use regular HTML `<input>` tags (the `range` type is useful to create sliders). You might also explore interaction by tracking mouse movement via the `window.onmousemove` event handler in tandem with the `event.clientX` and `event.clientY` properties. Consider using the [Pointer Events API](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events) to ensure that that both mouse and touch events will both be supported in your app.
- Your application should display basic documentation for the user interface when the application first loads.
Additional notes:
I referenced the following tutorials:
1) https://www.youtube.com/watch?v=6_3YjEc4q1Y&t=2159s
2) https://threejs-journey.com/lessons/local-server#more-about-the-vite-template

The interactive experience should possess a reasonable level of complexity. Some examples:
### Three.js
- A generative algorithm creates simple agents that move through a virtual world. Your interface controls the behavior / appearance of these agents.
- A simple 3D game... you really want this to be a simple as possible or it will be outside the scope of this assignment.
- An 3D audio visualization of a song of your choosing. User interaction should control aspects of the visualization.
### Canvas
- Implement a generative algorithm such as [Conway's Game of Life](https://bitstorm.org/gameoflife/) (or 1D cellular automata) and provide interactive controls. Note that the Game of Life has been created by 100s of people using `<canvas>`; we'll be checking to ensure that your implementation is not a copy of these.
- Design a 2D audio visualizer of a song of your choosing. User interaction should control visual aspects of the experience.
### Web Audio API
- Create a screen-based musical instrument using the Web Audio API. You can use projects such as [Interface.js](http://charlie-roberts.com/interface/) or [Nexus UI](https://nexus-js.github.io/ui/api/#Piano) to provide common musical interface elements, or use dat.GUI in combination with mouse/touch events (use the Pointer Events API). Your GUI should enable users to control aspects of sound synthesis. If you want to use higher-level instruments instead of the raw WebAudio API sounds, consider trying the instruments provided by [Tone.js]() or [Gibber](https://github.com/charlieroberts/gibber.audio.lib).
### D3.js
- Create visualizations using the datasets found at [Awesome JSON Datasets](https://github.com/jdorfman/Awesome-JSON-Datasets). Experiment with providing different visualizations of the same data set, and providing users interactive control over visualization parameters and/or data filtering. Alternatively, create a single visualization with using one of the more complicated techniques shown at [d3js.org](d3js.org) and provide meaningful points of interaction for users.

Deliverables
---

Do the following to complete this assignment:

1. Implement your project with the above requirements.
3. Test your project to make sure that when someone goes to your main page on Glitch/Heroku/etc., it displays correctly.
4. Ensure that your project has the proper naming scheme `a4-firstname-lastname` so we can find it.
5. Fork this repository and modify the README to the specifications below. *NOTE: If you don't use Glitch for hosting (where we can see the files) then you must include all project files that you author in your repo for this assignment*.
6. Create and submit a Pull Request to the original repo. Name the pull request using the following template: `a4-firstname-lastname`.

Sample Readme (delete the above when you're ready to submit, and modify the below so with your links and descriptions)
---

## Your Web Application Title

your hosting link e.g. http://a4-charlieroberts.glitch.me

Include a very brief summary of your project here. Images are encouraged when needed, along with concise, high-level text. Be sure to include:

- the goal of the application
- challenges you faced in realizing the application
- the instructions you present in the website should be clear enough to use the application, but if you feel any need to provide additional instructions please do so here.
Binary file added assets/a4visual.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "threejs-journey-exercise",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"vite": "^4.3.9"
},
"dependencies": {
"gsap": "^3.12.2",
"stats-js": "^1.0.1",
"three": "^0.153.0",
"tweakpane": "^4.0.1"
}
}
26 changes: 26 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>04 - Local Server</title>

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Josefin+Sans:wght@300&family=Jost&display=swap" rel="stylesheet">

<link rel="stylesheet" href="./style.css">
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
</head>

<body>
<div id="container">
<h1 class="vert-move"> Audio Visualizer </h1>
<button id="start">Start</button>
</div>
<canvas class="scene"></canvas>
<script type="module" defer src="../js/index.js"></script>
</body>

</html>
197 changes: 197 additions & 0 deletions src/js/LoaderManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader.js'
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js'
import { FontLoader } from 'three/examples/jsm/loaders/FontLoader.js'
import { TextureLoader } from 'three'
import { AudioLoader } from 'three'

class LoaderManager {
#assets
#textureLoader = new TextureLoader()
#GLTFLoader = new GLTFLoader()
#OBJLoader = new OBJLoader()
#DRACOLoader = new DRACOLoader()
#FontLoader = new FontLoader()
#AudioLoader = new AudioLoader()

constructor() {
this.#assets = {} // Dictionary of assets, can be different type, gltf, texture, img, font, feel free to make a Enum if using TypeScript
}

get assets() {
return this.#assets
}

set assets(value) {
this.#assets = value
}

/**
* Public method
*/

get(name) {
return this.#assets[name]
}

load = (data) =>
new Promise((resolve) => {
const promises = []
for (let i = 0; i < data.length; i++) {
const { name, gltf, texture, img, font, obj, audio } = data[i]

if (!this.#assets[name]) {
this.#assets[name] = {}
}

if (gltf) {
promises.push(this.loadGLTF(gltf, name))
}

if (texture) {
promises.push(this.loadTexture(texture, name))
}

if (img) {
promises.push(this.loadImage(img, name))
}

if (font) {
promises.push(this.loadFont(font, name))
}

if (obj) {
promises.push(this.loadObj(obj, name))
}

if (audio) {
promises.push(this.loadAudio(audio, name))
}
}

Promise.all(promises).then(() => resolve())
})

loadGLTF(url, name) {
return new Promise((resolve) => {
this.#DRACOLoader.setDecoderPath('https://www.gstatic.com/draco/v1/decoders/')
this.#GLTFLoader.setDRACOLoader(this.#DRACOLoader)

this.#GLTFLoader.load(
url,
(result) => {
this.#assets[name].gltf = result
resolve(result)
},
undefined,
(e) => {
console.log(e)
}
)
})
}

loadTexture(url, name) {
if (!this.#assets[name]) {
this.#assets[name] = {}
}
return new Promise((resolve) => {
this.#textureLoader.load(url, (result) => {
this.#assets[name].texture = result
resolve(result)
})
})
}

loadImage(url, name) {
return new Promise((resolve) => {
const image = new Image()

image.onload = () => {
this.#assets[name].img = image
resolve(image)
}

image.src = url
})
}

loadFont(url, name) {
// you can convert font to typeface.json using https://gero3.github.io/facetype.js/
return new Promise((resolve) => {
this.#FontLoader.load(
url,

// onLoad callback
(font) => {
this.#assets[name].font = font
resolve(font)
},

// onProgress callback
() =>
// xhr
{
// console.log((xhr.loaded / xhr.total) * 100 + '% loaded')
},

// onError callback
(err) => {
console.log('An error happened', err)
}
)
})
}

// https://threejs.org/docs/#examples/en/loaders/OBJLoader
loadObj(url, name) {
return new Promise((resolve) => {
// load a resource
this.#OBJLoader.load(
// resource URL
url,
// called when resource is loaded
(object) => {
this.#assets[name].obj = object
resolve(object)
},
// onProgress callback
() =>
// xhr
{
// console.log((xhr.loaded / xhr.total) * 100 + '% loaded')
},
// called when loading has errors
(err) => {
console.log('An error happened', err)
}
)
})
}

//loadAudio
loadAudio(url, name) {
return new Promise((resolve) => {
this.#AudioLoader.load(
url,
(audioBuffer) => {
this.#assets[name].buffer = audioBuffer
resolve(audioBuffer)
},
(xhr) => {
console.log((xhr.loaded / xhr.total) * 100 + '% loaded')
},
(err) => {
console.log('An error happened', err)
}
)
})
}





}

export default new LoaderManager()
7 changes: 7 additions & 0 deletions src/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test import of a JavaScript module
import Scene from './scene'

(() => {
// scene
new Scene()
})()
Loading