Giter Site home page Giter Site logo

maxxfrazer / scenekit-scnline Goto Github PK

View Code? Open in Web Editor NEW
85.0 6.0 16.0 17.99 MB

Draw a tube or thick line in SceneKit

License: MIT License

Ruby 8.10% Swift 89.97% Objective-C 1.93%
arkit scenekit augmentedreality augmented-reality geometry-library drawing arkit2 swift ios drawing-app

scenekit-scnline's Introduction

SCNLine

Functions and classes for creating thick line geometries in a application using SceneKit.

Actions Status Actions Status Swift 5.0

Line Drawing Hello 1

Introduction

SCNLine is a class for drawing lines of a given thickness in 3D space. In most situations in 3D projects the typically used method would use GL_LINES; which can be exercised in SceneKit with this primitive type. However glLineWidth is now depricated, which is initially why I made this class.

For more information on drawing primitive types in OpenGL or otherwise, please refer to this document, or if you want to see how it's applied in SceneKit, check out my first Medium article about building primitive geometries.

Please feel free to use and contribute this library however you like. I only ask that you let me know when you're doing so; that way I can see some cool uses of it!

Installation

Swift Package Manager

Add the URL of this repository to your Xcode 11+ Project.

https://github.com/maxxfrazer/SceneKit-SCNLine.git

CocoaPods

Add to Podfile: pod 'SCNLine', '~> 1.0'

Import

Add to .swift file: import SCNLine

Example

It's as easy as this to a line geometry:

let lineGeometry = SCNGeometry.line(points: [
	SCNVector3(0,-1,0),
	SCNVector3(0,-1,-1),
	SCNVector3(1,-1,-1)
], radius: 0.1).0

Or using the node directly SCNLineNode:

drawingNode = SCNLineNode(
	with: [SCNVector3(0,-1,0), SCNVector3(0,-1,-1), SCNVector3(1,-1,-1)],
	radius: 0.01,
	edges: 12,
	maxTurning: 12
)
drawingNode.add(point: SCNVector3(1,-2,-2))

The latter is recommended if you want to update the line at a later time by adding a point to it.

This will draw a line of radius 10cm from below the origin, forwards and then to the right in an ARKit setup. The y value is set to -1 just as an example that assumes the origin of your scene graph is about 1m above the ground.

Other parameters that can be passed into SCNGeometry.path:

name description default example
points Array of SCNVector3 points to make up the line no default [SCNVector3(0,-1,0), SCNVector3(0,-1,-1), SCNVector3(1,-1,-1)]
radius Radius of the line in meters no default 0.1
edges The number of vertices used around the edge of the tube shaped line to be exteneded throughout the geometry. 12, minimum is 3 16
maxTurning Maximum number of points to make up the curved look when the line is turning to a new direction. 4 16

While in the examples below it shows that this can be used for drawing apps I would not recommend this class for that in its current state, because the current class regathers vertices from the very beginning of the line right to the end, which is very inefficient as most will remain the same.

Here's some basic examples of what you can do with this Pod:

Line Drawing Example 1 Line Drawing Hello 2

scenekit-scnline's People

Contributors

chdominguez avatar joluet avatar jrgoodle avatar maxxfrazer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.