Friday, May 17, 2024
Homepage · 3d
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  177] [ 2]  / answers: 1 / hits: 16503  / 9 Years ago, wed, july 8, 2015, 12:00:00

I want to create a plane in three.js, but with more points than default (so I don't want to use PlaneGeometry, as I don't think it will let me define custom points). The reason being is that I want to be able to animate or move any given point in time.



This is what I have so far:



var camera;
var scene;
var renderer;
var mesh;

init();
animate();

function init() {

scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000);

var light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 0, 1, 1 ).normalize();
scene.add(light);


var geometry = new THREE.PlaneGeometry( 50, 50);

var texture = THREE.ImageUtils.loadTexture('images/03032122.png', {}, function() {
renderer.render(scene, camera);
})
var material = new THREE.MeshBasicMaterial({map: texture, transparent: true })


mesh = new THREE.Mesh(geometry, material );
mesh.position.z = -50;
scene.add( mesh );

renderer = new THREE.WebGLRenderer({ alpha: true });
renderer.setSize( window.innerWidth, window.innerHeight );

renderer.setClearColor( 0xffffff, 1);
document.body.appendChild( renderer.domElement );

window.addEventListener( 'resize', onWindowResize, false );

render();
}

function animate() {
//mesh.scale.x+= 0.0003;


render();
requestAnimationFrame( animate );

}

function render() {
renderer.render( scene, camera );
}


function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
render();
}


What I'm looking to do, is create something like this:



http://www.math.ubc.ca/~cass/courses/m308-02b/projects/schweber/square%20tiles.gif


More From » 3d

 Answers
49

Becare about PlaneGeometry, it is deprecated (so it will be removed in a next revision). Use PlaneBufferGeometry instead.



@pailhead's answer is correct if you want the 'normal' plane division.



If you want the vertices to have other positions you would have to build the geometry vertex per vertex that is something else*.



Also and that answers your need to move/animate the vertices later, you can change each vertex'position after the geometry creation by writing :



planeMesh.geometry.vertices[i].set(x,y,z);// this way you can move each vertex coordinates
planeMesh.geometry.verticesNeedUpdate=true;





* : example for a plane with 4 vertices (=2 triangles) :



var geo=new THREE.Geometry();
geometry.vertices.push(
new THREE.Vector3(x1,y1,z1),//vertex0
new THREE.Vector3(x2,y2,z2),//1
new THREE.Vector3(x3,y3,z3),//2
new THREE.Vector3(x4,y4,z4)//3
);
geometry.faces.push(
new THREE.Face3(2,1,0),//use vertices of rank 2,1,0
new THREE.Face3(3,1,2)//vertices[3],1,2...
);


of course what makes this geometry a plane is that the 4 vertices are coplonar.



When you create a geometry with many faces, you understand you need a pen + paper to draw your faces :) Depending on your geometry you can also use an algorithm.


[#65885] Monday, July 6, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mira

Total Points: 460
Total Questions: 108
Total Answers: 99

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
mira questions
;