Code Monkey home page Code Monkey logo

lesson-mixed-mode-starter-kit's Introduction

layout title
default
Using Meshes

The Mesh Component

Before thinking about how to structure our demo, we should learn about the primary component of the WebGLRenderer, the Mesh Component

Boilerplate

Let's get our app up and running with some boilerplate code. This should look familiar. Copy and paste the code snippets below into index.js.

var FamousEngine = require('famous/core/FamousEngine');

// Create the scene based on a selector.

var scene = FamousEngine.createScene('body');

// Initialize the engine.
    
FamousEngine.init();

// App Code

var App = require('./js/App');
var app = new App(scene);

The App code section at the bottom of the index page is where we create our app and pass in a selector. If we look into App.js we can see exactly what this App function is.

Creating our App

var FamousEngine = require('famous/core/FamousEngine');
var Mesh = require('famous/webgl-renderables/Mesh');

function App(scene) {

    // Add a child node to add our mesh to.

    var child = scene.addChild();

    // Pass child node into new Mesh component.

    var mesh = new Mesh(child);

    // Give the mesh a geometry.

    mesh.setGeometry('Circle');
}

module.exports = App;

Here you can see that our App is nothing more than a function that takes in a scene as an argument.

From there, a child node is added to the scene and passed into the Mesh Component. You can think of a mesh as a WebGL object. In drawing our mesh, we must decide it's geometry (shape) and its color.

In the above example we set our Mesh's geometry to that of a circle. We won't set the color of the Mesh quite yet, which should leave the mesh with the default color.

The result is a soothing-gray circle, the size of our scene, which in this case is the size of screen.

The MIT License (MIT)

Copyright (c) 2015 Famous Industries Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

lesson-mixed-mode-starter-kit's People

Contributors

solomon-gumball avatar wgester avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lesson-mixed-mode-starter-kit's Issues

Forgot to require DOMElement

On the second page of the tutorial, App.js adds a div to the meshNode, but DOMElement was not required. This leads to the sphere rendering in 2D and not rotating, as well as the div not rendering:

var PointLight = require('famous/webgl-renderables/lights/PointLight');
var FamousEngine = require('famous/core/FamousEngine');
var Mesh = require('famous/webgl-renderables/Mesh');
var Camera = require('famous/components/Camera');
var Color = require('famous/utilities/Color');
var DOMElement = require('famous/dom-renderables/DOMElement'); // Tutorial missing this line

function App(scene) {
// Add a camera to our scene for perspective rendering.

var camera = new Camera(scene).setDepth(1000);

// Add mesh to our scene.

var meshNode = scene.addChild()
.setOrigin(0.5, 0.5, 0.5)
.setAlign(0.5, 0.5, 0.5)
.setMountPoint(0.5, 0.5, 0.5)
.setSizeMode(1, 1, 1)
.setAbsoluteSize(200, 200, 200);

var mesh = new Mesh(meshNode).setGeometry('Sphere');

var element = new DOMElement(meshNode, { tagName: 'div' }).setProperty('background-color', 'pink');

// Add light component to our scene.

var lightNode = scene.addChild()
.setAlign(0.5, 0.5, 0.5)
.setPosition(0, 0, 250);

var light = new PointLight(lightNode)
.setColor(new Color('white'));

var clock = FamousEngine.getClock();

// Define update loop

FamousEngine.getClock().setInterval(function() {
var time = clock.getTime();

meshNode.setRotation(
  time / 1500,
  time / 1200,
  time / 1300
);

}, 16);
}

module.exports = App;

Macbook object model

I probably missed an obvious (as always), but where do I find this macbook obj file, used in tutorial?

npm comands not running?

I have cloned this repo and can't start the server or run some of the commands..

for example when I run "npm start" ๐Ÿ‘ [email protected] start: npm run build && serve --compress public/ -p 1618
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is most likely a problem with the lesson-mixed-mode-starter-kit package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm run build && serve --compress public/ -p 1618
npm ERR! You can get their info via:
npm ERR! npm owner ls lesson-mixed-mode-starter-kit
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 14.3.0
npm ERR! command "node" "/usr/local/bin/npm" "start"
npm ERR! cwd /Users/leeblazek/Sites/famous denver/lesson-mixed-mode-starter-kit
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.