three

package module
v0.0.0-...-17df547 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2016 License: MIT Imports: 1 Imported by: 0

README

Three.js bindings for GopherJS

This is still very early work. It currently wraps enough of the three.js object model to allow meshes to be added to a scene, but setting up the renderer is still handled in javascript.

I'll be adding more of the interface as I need it, so feel free to send pull requests if you need parts that are missing. Needless to say, this library is NOT STABLE and may change without warning.

Example

package main

import (
	"bitbucket.org/mikehouston/three"
	"github.com/gopherjs/gopherjs/js"
)

func main() {
	scene := three.SceneFromJS(js.Global.Get("scene"))

	size := 32
	step := 50
	geometry := three.NewGeometry()
	for x := 0; x < size; x++ {
		for z := 0; z < size; z++ {
			geometry.Vertices().Push(three.NewVector3(
				float64(x*step-size*step/2),
				float64(z*z-x*x),
				float64(z*step-size*step/2),
			))

			if x > 0 && z > 0 {
				p1 := z + x*size
				p2 := (z - 1) + x*size
				p3 := (z - 1) + (x-1)*size
				p4 := z + (x-1)*size

				geometry.Faces().Push(three.NewFace3(p1, p2, p3))
				geometry.Faces().Push(three.NewFace3(p3, p4, p1))

				geometry.Faces().Push(three.NewFace3(p3, p2, p1))
				geometry.Faces().Push(three.NewFace3(p1, p4, p3))
			}
		}
	}
	geometry.ComputeFaceNormals()

	material := three.NewMeshNormalMaterial()
	mesh := three.NewMesh(geometry, material)
	scene.Add(mesh)
}

Documentation

Overview

Package three provides GopherJS bindings for the three.js project See http://threejs.org/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventDispatcher

type EventDispatcher struct {
	// contains filtered or unexported fields
}

EventDispatcher binds JavaScript events for custom objects. https://github.com/mrdoob/eventdispatcher.js

func (*EventDispatcher) JSObject

func (e *EventDispatcher) JSObject() *js.Object

JSObject returns the underlying js.Object pointer for this object

type Face3

type Face3 struct {
	// contains filtered or unexported fields
}

Face3 is a triangle face

func NewFace3

func NewFace3(a, b, c int) *Face3

NewFace3 constructs a new Face3 object a — Vertex A index. b — Vertex B index. c — Vertex C index. normal — Face normal or array of vertex normals. color — Face color or array of vertex colors. materialIndex — Material index.

func NewFace3Normal

func NewFace3Normal(a, b, c int, normal *Vector3, color, materialIndex int) *Face3

NewFace3Normal constructs a new Face3 object with a face normal, color and material

func NewFace3VertexNormals

func NewFace3VertexNormals(a, b, c int, normals [3]*Vector3, colors [3]int, materialIndex int) *Face3

NewFace3VertexNormals constructs a new Face3 object with vertex normals and vertex colors

type Faces

type Faces struct {
	// contains filtered or unexported fields
}

Faces is an array of Face3 objects

func (*Faces) Push

func (v *Faces) Push(faces ...*Face3)

Push appends faces to this array

func (*Faces) Update

func (v *Faces) Update()

Update sets the elementsNeedUpdate flag on the associated Geometry

type Geometry

type Geometry struct {
	EventDispatcher
}

A Geometry holds all data necessary to describe a 3D model.

func NewGeometry

func NewGeometry() *Geometry

NewGeometry creates a new Geometry object The constructor takes no arguments.

func (*Geometry) ComputeBoundingSphere

func (g *Geometry) ComputeBoundingSphere()

ComputeBoundingSphere computes bounding sphere of the geometry, updating Geometry.boundingSphere attribute. Neither bounding boxes or bounding spheres are computed by default. They need to be explicitly computed, otherwise they are null.

func (*Geometry) ComputeFaceNormals

func (g *Geometry) ComputeFaceNormals()

ComputeFaceNormals computes face normals.

func (*Geometry) ElementsNeedUpdate

func (g *Geometry) ElementsNeedUpdate() bool

Set to true if the faces array has been updated.

func (*Geometry) Faces

func (g *Geometry) Faces() *Faces

Faces describe how each vertex in the model is connected with each other. To signal an update in this array, Geometry.elementsNeedUpdate needs to be set to true.

func (*Geometry) ID

func (g *Geometry) ID() int

ID is a unique number for this geometry instance.

func (*Geometry) Name

func (g *Geometry) Name() string

Name for this geometry. Default is an empty string.

func (*Geometry) SetElementsNeedUpdate

func (g *Geometry) SetElementsNeedUpdate(value bool)

func (*Geometry) SetVerticesNeedUpdate

func (g *Geometry) SetVerticesNeedUpdate(value bool)

func (*Geometry) Vertices

func (g *Geometry) Vertices() *Vertices

Vertices holds every position of points in the model. To signal an update in this array, Geometry.verticesNeedUpdate needs to be set to true.

func (*Geometry) VerticesNeedUpdate

func (g *Geometry) VerticesNeedUpdate() bool

Set to true if the vertices array has been updated.

type HasMaterial

type HasMaterial interface {
	// contains filtered or unexported methods
}

HasMaterial identifies sub-types of Material

type HasObject3D

type HasObject3D interface {
	// contains filtered or unexported methods
}

HasObject3D marks subtypes of Object3D

type Material

type Material struct {
	EventDispatcher
}

A Material describes the appearance of objects. They are defined in a (mostly) renderer-independent way, so you don't have to rewrite materials if you decide to use a different renderer.

type Mesh

type Mesh struct {
	Object3D
}

Mesh is a base class for Mesh objects, such as MorphAnimMesh and SkinnedMesh.

func NewMesh

func NewMesh(geometry *Geometry, material HasMaterial) *Mesh

NewMesh constructs a new mesh object. geometry — An instance of Geometry. material — An instance of Material (optional).

type MeshBasicMaterial

type MeshBasicMaterial struct {
	Material
}

MeshBasicMaterial is a material for drawing geometries in a simple shaded (flat or wireframe) way. The default will render as flat polygons. To draw the mesh as wireframe, simply set the 'wireframe' property to true.

func NewMeshBasicMaterial

func NewMeshBasicMaterial(params *MeshBasicMaterialParams) *MeshBasicMaterial

NewMeshBasicMaterial constructs a new MeshBasicMaterial

type MeshBasicMaterialParams

type MeshBasicMaterialParams struct {
	// contains filtered or unexported fields
}

MeshBasicMaterialParams is an object with one or more properties defining the material's appearance.

type MeshNormalMaterial

type MeshNormalMaterial struct {
	Material
}

MeshNormalMaterial is a material that maps the normal vectors to RGB colors.

func NewMeshNormalMaterial

func NewMeshNormalMaterial() *MeshNormalMaterial

NewMeshNormalMaterial constructs a new MeshNormalMaterial

type Object3D

type Object3D struct {
	EventDispatcher
}

Object3D is the base class for scene graph objects.

func (*Object3D) Add

func (o *Object3D) Add(object ...HasObject3D)

Add appends an object as child of this object. An arbitrary number of objects may be added. object - An object.

type Scene

type Scene struct {
	Object3D
}

A Scene allows you to set up what and where is to be rendered by three.js. This is where you place objects, lights and cameras.

func NewScene

func NewScene() *Scene

NewScene constructs a new scene object.

func SceneFromJS

func SceneFromJS(o *js.Object) *Scene

SceneFromJS wraps a js.Object

type Vector3

type Vector3 struct {
	// contains filtered or unexported fields
}

Vector3 is a 3 dimensional vector

func NewVector3

func NewVector3(x, y, z float64) *Vector3

NewVector3 creates a new Vector3 x -- Float the vector's x value y -- Float the vector's y value z -- Float the vector's z value

func (*Vector3) X

func (v *Vector3) X() float64

X returns the x coordinate of the vector

func (*Vector3) Y

func (v *Vector3) Y() float64

Y returns the y coordinate of the vector

func (*Vector3) Z

func (v *Vector3) Z() float64

Z returns the z coordinate of the vector

type Vertices

type Vertices struct {
	// contains filtered or unexported fields
}

Vertices is an array of Vector3 objects

func (*Vertices) Push

func (v *Vertices) Push(vectors ...*Vector3)

Push appends vectors to this array

func (*Vertices) Update

func (v *Vertices) Update()

Update sets the veticesNeedUpdate flag on the associated Geometry

Directories

Path Synopsis
examples
surface command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL