From 28cadf5475a7a78304fa33a585b4d720c3cbcbc3 Mon Sep 17 00:00:00 2001 From: webglzhang <493458883@qq.com> Date: Sat, 23 Nov 2019 19:19:48 +0800 Subject: [PATCH] 1.update InstancedMesh.d.ts 2.update raycaster and InstanceMesh Doc 3.update demo --- docs/api/en/core/Raycaster.html | 4 +++- docs/api/en/objects/InstancedMesh.html | 17 +++++++++++++++++ docs/api/zh/core/Raycaster.html | 4 +++- docs/api/zh/objects/InstancedMesh.html | 17 +++++++++++++++++ examples/webgl_instancing_raycast.html | 13 ++++++------- src/objects/InstancedMesh.d.ts | 5 +++++ 6 files changed, 51 insertions(+), 9 deletions(-) diff --git a/docs/api/en/core/Raycaster.html b/docs/api/en/core/Raycaster.html index 5c90ef9692..3ba8d30a75 100644 --- a/docs/api/en/core/Raycaster.html +++ b/docs/api/en/core/Raycaster.html @@ -58,6 +58,7 @@ Examples: [example:webgl_interactive_cubes Raycasting to a Mesh]
[example:webgl_interactive_cubes_ortho Raycasting to a Mesh in using an OrthographicCamera]
[example:webgl_interactive_buffergeometry Raycasting to a Mesh with BufferGeometry]
+ [example:webgl_instancing_raycast Raycasting to a InstancedMesh]
[example:webgl_interactive_lines Raycasting to a Line]
[example:webgl_interactive_raycasting_points Raycasting to Points]
[example:webgl_geometry_terrain_raycast Terrain raycasting]
@@ -170,7 +171,8 @@ [page:Integer faceIndex] – index of the intersected face
[page:Object3D object] – the intersected object
[page:Vector2 uv] - U,V coordinates at point of intersection
- [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
+ [page:Integer instanceId] – The index number of the instance where the ray intersects the InstancedMesh

*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]. diff --git a/docs/api/en/objects/InstancedMesh.html b/docs/api/en/objects/InstancedMesh.html index 761527f1f8..10000e4492 100644 --- a/docs/api/en/objects/InstancedMesh.html +++ b/docs/api/en/objects/InstancedMesh.html @@ -53,6 +53,23 @@

Methods

See the base [page:Mesh] class for common methods.

+

[method:null getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )

+

+ [page:Integer index]: The index of an instance. Values have to be in the range [0, count]. +

+

+ [page:Matrix4 matrix]: This 4x4 matrix will be set to the local transformation matrix of the defined instance. +

+

+ Get the local transformation matrix of the defined instance. +

+ +

[method:null raycast]( [param:Raycaster raycaster], [param:Array intersects] )

+

+ Get intersections between a casted ray and this insatncedmesh. + [page:Raycaster.intersectObject] will call this method, but the results are not ordered. +

+

[method:null setMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )

[page:Integer index]: The index of an instance. Values have to be in the range [0, count]. diff --git a/docs/api/zh/core/Raycaster.html b/docs/api/zh/core/Raycaster.html index e2ac93ef74..de0a8223ef 100644 --- a/docs/api/zh/core/Raycaster.html +++ b/docs/api/zh/core/Raycaster.html @@ -56,6 +56,7 @@ 其它示例:
[example:webgl_interactive_cubes Raycasting to a Mesh]
[example:webgl_interactive_cubes_ortho Raycasting to a Mesh in using an OrthographicCamera]
[example:webgl_interactive_buffergeometry Raycasting to a Mesh with BufferGeometry]
+ [example:webgl_instancing_raycast Raycasting to a InstancedMesh]
[example:webgl_interactive_lines Raycasting to a Line]
[example:webgl_interactive_raycasting_points Raycasting to Points]
[example:webgl_geometry_terrain_raycast Terrain raycasting]
@@ -170,7 +171,8 @@ [page:Integer faceIndex] —— 相交的面的索引
[page:Object3D object] —— 相交的物体
[page:Vector2 uv] —— 相交部分的点的UV坐标。
- [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
+ [page:Integer instanceId] – The index number of the instance where the ray intersects the InstancedMesh

当计算这条射线是否和物体相交的时候,*Raycaster*将传入的对象委托给[page:Object3D.raycast raycast]方法。 diff --git a/docs/api/zh/objects/InstancedMesh.html b/docs/api/zh/objects/InstancedMesh.html index 761527f1f8..10000e4492 100644 --- a/docs/api/zh/objects/InstancedMesh.html +++ b/docs/api/zh/objects/InstancedMesh.html @@ -53,6 +53,23 @@

Methods

See the base [page:Mesh] class for common methods.

+

[method:null getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )

+

+ [page:Integer index]: The index of an instance. Values have to be in the range [0, count]. +

+

+ [page:Matrix4 matrix]: This 4x4 matrix will be set to the local transformation matrix of the defined instance. +

+

+ Get the local transformation matrix of the defined instance. +

+ +

[method:null raycast]( [param:Raycaster raycaster], [param:Array intersects] )

+

+ Get intersections between a casted ray and this insatncedmesh. + [page:Raycaster.intersectObject] will call this method, but the results are not ordered. +

+

[method:null setMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )

[page:Integer index]: The index of an instance. Values have to be in the range [0, count]. diff --git a/examples/webgl_instancing_raycast.html b/examples/webgl_instancing_raycast.html index 2e72fa7891..be49637b8d 100644 --- a/examples/webgl_instancing_raycast.html +++ b/examples/webgl_instancing_raycast.html @@ -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 @@ } + diff --git a/src/objects/InstancedMesh.d.ts b/src/objects/InstancedMesh.d.ts index 3faeb00feb..e2b9a6c89b 100644 --- a/src/objects/InstancedMesh.d.ts +++ b/src/objects/InstancedMesh.d.ts @@ -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; + + } -- GitLab