提交 28cadf54 编写于 作者: W webglzhang

1.update InstancedMesh.d.ts

2.update raycaster and InstanceMesh Doc
3.update demo
上级 af9cae72
......@@ -58,6 +58,7 @@
Examples: [example:webgl_interactive_cubes Raycasting to a Mesh]<br />
[example:webgl_interactive_cubes_ortho Raycasting to a Mesh in using an OrthographicCamera]<br />
[example:webgl_interactive_buffergeometry Raycasting to a Mesh with BufferGeometry]<br />
[example:webgl_instancing_raycast Raycasting to a InstancedMesh]<br />
[example:webgl_interactive_lines Raycasting to a Line]<br />
[example:webgl_interactive_raycasting_points Raycasting to Points]<br />
[example:webgl_geometry_terrain_raycast Terrain raycasting]<br />
......@@ -170,7 +171,8 @@
[page:Integer faceIndex] – index of the intersected face<br />
[page:Object3D object] – the intersected object<br />
[page:Vector2 uv] - U,V coordinates at point of intersection<br />
[page:Vector2 uv2] - Second set of U,V coordinates at point of intersection
[page:Vector2 uv2] - Second set of U,V coordinates at point of intersection<br />
[page:Integer instanceId] – The index number of the instance where the ray intersects the InstancedMesh
</p>
<p>
*Raycaster* delegates to the [page:Object3D.raycast raycast] method of the passed object, when evaluating whether the ray intersects the object or not. This allows [page:Mesh meshes] to respond differently to ray casting than [page:Line lines] and [page:Points pointclouds].
......
......@@ -53,6 +53,23 @@
<h2>Methods</h2>
<p>See the base [page:Mesh] class for common methods.</p>
<h3>[method:null getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )</h3>
<p>
[page:Integer index]: The index of an instance. Values have to be in the range [0, count].
</p>
<p>
[page:Matrix4 matrix]: This 4x4 matrix will be set to the local transformation matrix of the defined instance.
</p>
<p>
Get the local transformation matrix of the defined instance.
</p>
<h3>[method:null raycast]( [param:Raycaster raycaster], [param:Array intersects] )</h3>
<p>
Get intersections between a casted ray and this insatncedmesh.
[page:Raycaster.intersectObject] will call this method, but the results are not ordered.
</p>
<h3>[method:null setMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )</h3>
<p>
[page:Integer index]: The index of an instance. Values have to be in the range [0, count].
......
......@@ -56,6 +56,7 @@
其它示例:<br>[example:webgl_interactive_cubes Raycasting to a Mesh]<br />
[example:webgl_interactive_cubes_ortho Raycasting to a Mesh in using an OrthographicCamera]<br />
[example:webgl_interactive_buffergeometry Raycasting to a Mesh with BufferGeometry]<br />
[example:webgl_instancing_raycast Raycasting to a InstancedMesh]<br />
[example:webgl_interactive_lines Raycasting to a Line]<br />
[example:webgl_interactive_raycasting_points Raycasting to Points]<br />
[example:webgl_geometry_terrain_raycast Terrain raycasting]<br />
......@@ -170,7 +171,8 @@
[page:Integer faceIndex] —— 相交的面的索引<br />
[page:Object3D object] —— 相交的物体<br />
[page:Vector2 uv] —— 相交部分的点的UV坐标。<br />
[page:Vector2 uv2] —— Second set of U,V coordinates at point of intersection
[page:Vector2 uv2] —— Second set of U,V coordinates at point of intersection<br />
[page:Integer instanceId] – The index number of the instance where the ray intersects the InstancedMesh
</p>
<p>
当计算这条射线是否和物体相交的时候,*Raycaster*将传入的对象委托给[page:Object3D.raycast raycast]方法。
......
......@@ -53,6 +53,23 @@
<h2>Methods</h2>
<p>See the base [page:Mesh] class for common methods.</p>
<h3>[method:null getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )</h3>
<p>
[page:Integer index]: The index of an instance. Values have to be in the range [0, count].
</p>
<p>
[page:Matrix4 matrix]: This 4x4 matrix will be set to the local transformation matrix of the defined instance.
</p>
<p>
Get the local transformation matrix of the defined instance.
</p>
<h3>[method:null raycast]( [param:Raycaster raycaster], [param:Array intersects] )</h3>
<p>
Get intersections between a casted ray and this insatncedmesh.
[page:Raycaster.intersectObject] will call this method, but the results are not ordered.
</p>
<h3>[method:null setMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )</h3>
<p>
[page:Integer index]: The index of an instance. Values have to be in the range [0, count].
......
......@@ -18,13 +18,13 @@
var camera, scene, renderer, stats;
var mesh, geometry;
var amount = parseInt( window.location.search.substr( 1 ) ) || 10;
var amount = parseInt( window.location.search.substr( 1 ) ) || 3;
var count = Math.pow( amount, 3 );
var object = new THREE.Object3D();
var intersection;
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
var mouse = new THREE.Vector2( 1, 1 );
var orbitControls;
......@@ -45,11 +45,11 @@
scene = new THREE.Scene();
geometry = new THREE.BoxBufferGeometry( 1, 1, 1 );
geometry.computeVertexNormals();
geometry = new THREE.TorusKnotBufferGeometry( 0.5, 0.2, 16, 4, 2, 3 );
geometry.scale( 0.5, 0.5, 0.5 );
var material = new THREE.MeshNormalMaterial();
var material = new THREE.MeshNormalMaterial( { flatShading: true } );
mesh = new THREE.InstancedMesh( geometry, material, count );
......@@ -125,8 +125,6 @@
function render() {
camera.updateMatrixWorld();
raycaster.setFromCamera( mouse, camera );
intersection = raycaster.intersectObjects( scene.children );
......@@ -148,6 +146,7 @@
}
</script>
</body>
......
......@@ -4,6 +4,7 @@ import { Material } from './../materials/Material';
import { BufferAttribute } from './../core/BufferAttribute';
import { Mesh } from './Mesh';
import { Matrix4 } from './../math/Matrix4';
import {Intersection, Raycaster} from "../core/Raycaster";
export class InstancedMesh extends Mesh {
......@@ -17,6 +18,10 @@ export class InstancedMesh extends Mesh {
instanceMatrix: BufferAttribute;
isInstancedMesh: true;
getMatrixAt( index: number, matrix: Matrix4 ): void;
setMatrixAt( index: number, matrix: Matrix4 ): void;
raycast( raycaster: Raycaster, intersects: Intersection[] ): void;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册