@@ -1708,10 +1708,61 @@ class AppBase extends EventHandler {
17081708 * var worldLayer = app.scene.layers.getLayerById(pc.LAYERID_WORLD);
17091709 * app.drawLine(start, end, pc.Color.WHITE, true, worldLayer);
17101710 */
1711- drawLine ( start , end , color , depthTest , layer ) {
1711+ drawLine ( start , end , color , depthTest , layer = this . scene . defaultDrawLayer ) {
17121712 this . scene . drawLine ( start , end , color , depthTest , layer ) ;
17131713 }
17141714
1715+ /**
1716+ * Draws a single line using the given material. Line start and end coordinates are specified in world-space.
1717+ * We expose the following vertex attributes for the material:
1718+ * - aPosition: pc.Vec3 (vertex position)
1719+ * - aTAndLength: pc.Vec2 (x - 1D texture coordinate [0..1], y - line length)
1720+ * - aColor: pc.Vec4 (vertex color)
1721+ *
1722+ * @param {Material } material - The material used for rendering the line.
1723+ * @param {Vec3 } start - The start world-space coordinate of the line.
1724+ * @param {Vec3 } end - The end world-space coordinate of the line.
1725+ * @param {Color } [color] - The color of the line. It defaults to white if not specified.
1726+ * @param {Layer } [layer] - The layer to render the line into. Defaults to {@link LAYERID_IMMEDIATE}.
1727+ * @example
1728+ * // Render a 1-unit long white line
1729+ * const material = new pc.BasicMaterial();
1730+ * material.vertexColors = true;
1731+ * material.blend = true;
1732+ * material.blendType = BLEND_NORMAL;
1733+ * material.depthTest = true;
1734+ * material.update();
1735+ * const start = new pc.Vec3(0, 0, 0);
1736+ * const end = new pc.Vec3(1, 0, 0);
1737+ * app.drawLineWithMaterial(material, start, end);
1738+ * @example
1739+ * // Render a 1-unit long red line which is not depth tested and renders on top of other geometry
1740+ * const material = new pc.BasicMaterial();
1741+ * material.vertexColors = true;
1742+ * material.blend = true;
1743+ * material.blendType = BLEND_NORMAL;
1744+ * material.depthTest = false;
1745+ * material.update();
1746+ * const start = new pc.Vec3(0, 0, 0);
1747+ * const end = new pc.Vec3(1, 0, 0);
1748+ * app.drawLineWithMaterial(material, start, end, pc.Color.RED);
1749+ * @example
1750+ * // Render a 1-unit long white line into the world layer
1751+ * const material = new pc.BasicMaterial();
1752+ * material.vertexColors = true;
1753+ * material.blend = true;
1754+ * material.blendType = BLEND_NORMAL;
1755+ * material.depthTest = true;
1756+ * material.update();
1757+ * const start = new pc.Vec3(0, 0, 0);
1758+ * const end = new pc.Vec3(1, 0, 0);
1759+ * const worldLayer = app.scene.layers.getLayerById(pc.LAYERID_WORLD);
1760+ * app.drawLineWithMaterial(material, start, end, pc.Color.WHITE, worldLayer);
1761+ */
1762+ drawLineWithMaterial ( material , start , end , color , layer = this . scene . defaultDrawLayer ) {
1763+ this . scene . drawLineWithMaterial ( material , start , end , color , layer ) ;
1764+ }
1765+
17151766 /**
17161767 * Renders an arbitrary number of discrete line segments. The lines are not connected by each
17171768 * subsequent point in the array. Instead, they are individual segments specified by two
@@ -1755,6 +1806,64 @@ class AppBase extends EventHandler {
17551806 this . scene . drawLines ( positions , colors , depthTest , layer ) ;
17561807 }
17571808
1809+ /**
1810+ * Renders an arbitrary number of discrete line segments with a given material.
1811+ * The lines are not connected by each subsequent point in the array. Instead, they are individual segments
1812+ * specified by two points. Therefore, the lengths of the supplied position and color arrays must be the same
1813+ * and also must be a multiple of 2. The colors of the ends of each line segment will be interpolated along
1814+ * the length of each line.
1815+ * We expose the following vertex attributes for the material:
1816+ * - aPosition: pc.Vec3 (vertex position)
1817+ * - aTAndLength: pc.Vec2 (x - 1D texture coordinate [0..1], y - line length)
1818+ * - aColor: pc.Vec4 (vertex color)
1819+ *
1820+ * @param {Material } material - The material used for rendering the lines.
1821+ * @param {Vec3[] } positions - An array of points to draw lines between. The length of the
1822+ * array must be a multiple of 2.
1823+ * @param {Color[] } colors - An array of colors to color the lines. This must be the same
1824+ * length as the position array. The length of the array must also be a multiple of 2.
1825+ * @param {Layer } [layer] - The layer to render the lines into. Defaults to {@link LAYERID_IMMEDIATE}.
1826+ * @example
1827+ * // Render a single line, with unique colors for each point
1828+ * const material = new pc.BasicMaterial();
1829+ * material.vertexColors = true;
1830+ * material.blend = true;
1831+ * material.blendType = BLEND_NORMAL;
1832+ * material.depthTest = false;
1833+ * material.update();
1834+ * const start = new pc.Vec3(0, 0, 0);
1835+ * const end = new pc.Vec3(1, 0, 0);
1836+ * app.drawLinesWithMaterial(material, [start, end], [pc.Color.RED, pc.Color.WHITE]);
1837+ * @example
1838+ * // Render 2 discrete line segments
1839+ * const material = new pc.BasicMaterial();
1840+ * material.vertexColors = true;
1841+ * material.blend = true;
1842+ * material.blendType = BLEND_NORMAL;
1843+ * material.depthTest = false;
1844+ * material.update();
1845+ * const points = [
1846+ * // Line 1
1847+ * new pc.Vec3(0, 0, 0),
1848+ * new pc.Vec3(1, 0, 0),
1849+ * // Line 2
1850+ * new pc.Vec3(1, 1, 0),
1851+ * new pc.Vec3(1, 1, 1)
1852+ * ];
1853+ * const colors = [
1854+ * // Line 1
1855+ * pc.Color.RED,
1856+ * pc.Color.YELLOW,
1857+ * // Line 2
1858+ * pc.Color.CYAN,
1859+ * pc.Color.BLUE
1860+ * ];
1861+ * app.drawLinesWithMaterial(material, points, colors);
1862+ */
1863+ drawLinesWithMaterial ( material , positions , colors , layer = this . scene . defaultDrawLayer ) {
1864+ this . scene . drawLinesWithMaterial ( material , positions , colors , layer ) ;
1865+ }
1866+
17581867 /**
17591868 * Renders an arbitrary number of discrete line segments. The lines are not connected by each
17601869 * subsequent point in the array. Instead, they are individual segments specified by two
@@ -1791,6 +1900,51 @@ class AppBase extends EventHandler {
17911900 this . scene . drawLineArrays ( positions , colors , depthTest , layer ) ;
17921901 }
17931902
1903+ /**
1904+ * Renders an arbitrary number of discrete line segments with a given material.
1905+ * The lines are not connected by each subsequent point in the array. Instead, they are
1906+ * individual segments specified by two points.
1907+ * We expose the following vertex attributes for the material:
1908+ * - aPosition: pc.Vec3 (vertex position)
1909+ * - aTAndLength: pc.Vec2 (x - 1D texture coordinate [0..1], y - line length)
1910+ * - aColor: pc.Vec4 (vertex color)
1911+ *
1912+ * @param {Material } material - The material used for rendering the lines.
1913+ * @param {number[] } positions - An array of points to draw lines between. Each point is
1914+ * represented by 3 numbers - x, y and z coordinate.
1915+ * @param {number[] } colors - An array of colors to color the lines. This must be the same
1916+ * length as the position array. The length of the array must also be a multiple of 2.
1917+ * @param {Layer } [layer] - The layer to render the lines into. Defaults to {@link LAYERID_IMMEDIATE}.
1918+ * @example
1919+ * // Render 2 discrete line segments
1920+ * const material = new pc.BasicMaterial();
1921+ * material.vertexColors = true;
1922+ * material.blend = true;
1923+ * material.blendType = BLEND_NORMAL;
1924+ * material.depthTest = false;
1925+ * material.update();
1926+ * const points = [
1927+ * // Line 1
1928+ * 0, 0, 0,
1929+ * 1, 0, 0,
1930+ * // Line 2
1931+ * 1, 1, 0,
1932+ * 1, 1, 1
1933+ * ];
1934+ * const colors = [
1935+ * // Line 1
1936+ * 1, 0, 0, 1, // red
1937+ * 0, 1, 0, 1, // green
1938+ * // Line 2
1939+ * 0, 0, 1, 1, // blue
1940+ * 1, 1, 1, 1 // white
1941+ * ];
1942+ * app.drawLineArraysWithMaterial(material, points, colors);
1943+ */
1944+ drawLineArraysWithMaterial ( material , positions , colors , layer = this . scene . defaultDrawLayer ) {
1945+ this . scene . drawLineArraysWithMaterial ( material , positions , colors , layer ) ;
1946+ }
1947+
17941948 /**
17951949 * Draws a wireframe sphere with center, radius and color.
17961950 *
0 commit comments