فهرست منبع

feat: adds CapsuleGeometry (#23586)

* feat: adds CapsuleGeometry

* .

* Update src/geometries/CapsuleGeometry.js

* Update docs/api/en/geometries/CapsuleGeometry.html

* removes radiusBottom

* Update src/geometries/CapsuleGeometry.js

* adds test import

* fixes test file name typo

* .

* fixes imports in capsuleGeometry module

* .

* pre-translate path

* lint
Gianmarco 3 سال پیش
والد
کامیت
3d24599bf2

+ 73 - 0
docs/api/en/geometries/CapsuleGeometry.html

@@ -0,0 +1,73 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<meta charset="utf-8" />
+		<base href="../../../" />
+		<script src="page.js"></script>
+		<link type="text/css" rel="stylesheet" href="page.css" />
+	</head>
+	<body>
+		[page:BufferGeometry] &rarr; [page:LatheGeometry] &rarr;
+
+		<h1>[name]</h1>
+
+		<p class="desc">
+			[name] is a geometry class for a capsule with given radii and height.
+			It is constructed using a lathe.
+		</p>
+
+		<iframe id="scene" src="scenes/geometry-browser.html#CapsuleGeometry"></iframe>
+
+		<script>
+
+		// iOS iframe auto-resize workaround
+
+		if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
+
+			const scene = document.getElementById( 'scene' );
+
+			scene.style.width = getComputedStyle( scene ).width;
+			scene.style.height = getComputedStyle( scene ).height;
+			scene.setAttribute( 'scrolling', 'no' );
+
+		}
+
+		</script>
+
+		<h2>Code Example</h2>
+
+		<code>const geometry = new THREE.CapsuleGeometry( 1, 1, 4, 8 );
+		const material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
+		const capsule = new THREE.Mesh( geometry, material );
+		scene.add( capsule );
+		</code>
+
+		<h2>Constructor</h2>
+
+		<h3>[name]([param:Float radius], [param:Float length], [param:Integer capSubdivisions], [param:Integer radialSegments])</h3>
+		<p>
+
+		radius — Radius of the capsule. Optional; defaults to 1.<br />
+		length — Length of the middle section. Optional; defaults to 1.<br />
+		capSegments — Number of curve segments used to build the caps. Optional; defaults to 4.<br />
+		radialSegments — Number of segmented faces around the circumference of the capsule. Optional; defaults to 8.<br />
+		</p>
+
+		<h2>Properties</h2>
+		<p>See the base [page:BufferGeometry] class for common properties.</p>
+
+		<h3>[property:Object parameters]</h3>
+		<p>
+		An object with a property for each of the constructor parameters. Any modification after instantiation does not change the geometry.
+		</p>
+
+		<h2>Methods</h2>
+		<p>See the base [page:BufferGeometry] class for common methods.</p>
+
+		<h2>Source</h2>
+
+		<p>
+			[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
+		</p>
+	</body>
+</html>

+ 1 - 0
docs/list.json

@@ -134,6 +134,7 @@
 
 			"Geometries": {
 				"BoxGeometry": "api/en/geometries/BoxGeometry",
+				"CapsuleGeometry": "api/en/geometries/CapsuleGeometry",
 				"CircleGeometry": "api/en/geometries/CircleGeometry",
 				"ConeGeometry": "api/en/geometries/ConeGeometry",
 				"CylinderGeometry": "api/en/geometries/CylinderGeometry",

+ 29 - 0
docs/scenes/geometry-browser.html

@@ -41,6 +41,7 @@
 			import {
 				BoxGeometry,
 				BufferGeometry,
+				CapsuleGeometry,
 				CircleGeometry,
 				Color,
 				ConeGeometry,
@@ -165,6 +166,34 @@
 
 				},
 
+				CapsuleGeometry: function ( mesh ) {
+
+					const data = {
+						radius: 5,
+						length: 5,
+						capSegments: 10,
+						heightSegments: 20
+					};
+
+					function generateGeometry() {
+
+						updateGroupGeometry( mesh,
+							new CapsuleGeometry( data.radius, data.length, data.capSegments, data.heightSegments ),
+						);
+
+					}
+
+					const folder = gui.addFolder( 'THREE.CapsuleGeometry' );
+
+					folder.add( data, 'radius', 1, 30 ).onChange( generateGeometry );
+					folder.add( data, 'length', 1, 30 ).onChange( generateGeometry );
+					folder.add( data, 'capSegments', 1, 32 ).step( 1 ).onChange( generateGeometry );
+					folder.add( data, 'heightSegments', 1, 64 ).step( 1 ).onChange( generateGeometry );
+
+					generateGeometry();
+
+				},
+
 				CylinderGeometry: function ( mesh ) {
 
 					const data = {

+ 33 - 0
src/geometries/CapsuleGeometry.js

@@ -0,0 +1,33 @@
+import { Path } from '../extras/core/Path.js';
+import { LatheGeometry } from './LatheGeometry.js';
+
+class CapsuleGeometry extends LatheGeometry {
+
+	constructor( radius = 1, length = 1, capSegments = 4, radialSegments = 8 ) {
+
+		const path = new Path();
+		path.absarc( 0, - length / 2, radius, Math.PI * 1.5, 0 );
+		path.absarc( 0, length / 2, radius, 0, Math.PI * 0.5 );
+
+		super( path.getPoints( capSegments ), radialSegments );
+
+		this.type = 'CapsuleGeometry';
+
+		this.parameters = {
+			radius: radius,
+			height: length,
+			capSegments: capSegments,
+			radialSegments: radialSegments,
+		};
+
+	}
+
+	static fromJSON( data ) {
+
+		return new CapsuleGeometry( data.radius, data.length, data.capSegments, data.radialSegments );
+
+	}
+
+}
+
+export { CapsuleGeometry, CapsuleGeometry as CapsuleBufferGeometry };

+ 1 - 0
src/geometries/Geometries.js

@@ -1,4 +1,5 @@
 export * from './BoxGeometry.js';
+export * from './CapsuleGeometry.js';
 export * from './CircleGeometry.js';
 export * from './ConeGeometry.js';
 export * from './CylinderGeometry.js';

+ 54 - 0
test/unit/src/geometries/CapsuleGeometry.tests.js

@@ -0,0 +1,54 @@
+/* global QUnit */
+
+import { runStdGeometryTests } from '../../utils/qunit-utils.js';
+import { CapsuleGeometry, CapsuleBufferGeometry } from '../../../../src/geometries/CapsuleGeometry.js';
+
+export default QUnit.module( 'Geometries', () => {
+
+	QUnit.module( 'CapsuleGeometry', ( hooks ) => {
+
+		var geometries = undefined;
+		hooks.beforeEach( function () {
+
+			const parameters = {
+				radius: 2,
+				length: 2,
+				capSegments: 20,
+				heightSegments: 20
+			};
+
+			geometries = [
+				new CapsuleGeometry(),
+				new CapsuleGeometry( parameters.radius ),
+				new CapsuleGeometry( parameters.radius, parameters.length ),
+				new CapsuleGeometry( parameters.radius, parameters.length, parameters.capSegments ),
+				new CapsuleGeometry( parameters.radius, parameters.length, parameters.capSegments, parameters.heightSegments ),
+				new CapsuleBufferGeometry(),
+			];
+
+		} );
+
+		// INHERITANCE
+		QUnit.todo( 'Extending', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		// INSTANCING
+		QUnit.todo( 'Instancing', ( assert ) => {
+
+			assert.ok( false, 'everything\'s gonna be alright' );
+
+		} );
+
+		// OTHERS
+		QUnit.test( 'Standard geometry tests', ( assert ) => {
+
+			runStdGeometryTests( assert, geometries );
+
+		} );
+
+	} );
+
+} );

+ 1 - 0
test/unit/three.source.unit.js

@@ -83,6 +83,7 @@ import './src/extras/curves/SplineCurve.tests.js';
 
 //src/geometries
 import './src/geometries/BoxGeometry.tests.js';
+import './src/geometries/CapsuleGeometry.tests.js';
 import './src/geometries/CircleGeometry.tests.js';
 import './src/geometries/ConeGeometry.tests.js';
 import './src/geometries/CylinderGeometry.tests.js';