r/PowerShell • • Nov 20 '20

PowerShell now supports 3D graphics

I got laid off at the start of Covid. During my unemployment, I kept busy by working on a project I call "DDD" (3D). DDD is a module that makes points, vectors, and matrices data types that can be displayed by piping them to an Out-3d command.

I got my project to a point where I can demo it and you can try it out too. I wrote about the preview release in my blog:

http://www.davidlenihan.com/2020/11/08/preview-release-of-ddd/

258 Upvotes

77 comments sorted by

45

u/doomjuice Nov 20 '20

How does someone who knows and can do all this get laid off

33

u/3d-david Nov 20 '20

:) It happens. I found a new job pretty quickly...actually too quickly. I wanted to keep working on this project full time.
...but I do like having an income.

4

u/doomjuice Nov 20 '20

Glad to hear! You seem very talented

0

u/[deleted] Nov 21 '20

[deleted]

1

u/arpan3t Nov 21 '20

Company claims work as IP, sues 3d-david.

34

u/liviuk Nov 20 '20

CIO: Outsource IT... get bonus for cutting costs... got to next company and repeat.

16

u/[deleted] Nov 20 '20

Just remember when they call you in a month to come in and fix shit: consulting rates apply. 3 months or more of pay to fix 1 issue.

15

u/MrECoyne Nov 20 '20

Not living in India, Philippines or Poland might have something to do with it.

7

u/gordonv Nov 20 '20

Business is short term decision, money centric. As soon as your production rate drops from your peak, even in 20% of your capacity is 5x better than anyone else around you, you are suspect to be let go.

Mainly because the people with decision making power don't care. They do care about protecting their own positions though. Actual progress is a threat to their microcosm of power.

0

u/[deleted] Nov 20 '20

[deleted]

12

u/3d-david Nov 20 '20

...although I've worked on 3d graphics my entire career...so this actually makes sense in my world.

Issues I ran into at work is what motivated me to start working on this. I had 3d models that needed to be manipulated/visualized and I wanted to automate that process. The best tools to do that were big animation packages like Maya/3D Studio Max/Blender, but they are overkill. Python has some libraries that are helpful but are too much effort to do what I wanted.

18

u/ka-splam Nov 20 '20

3D text ... in a sense:

$text = "PowerShell!"


import-module DDD

Add-Type -AssemblyName System.Drawing

$bmp = [Drawing.Bitmap]::new(($w = 10*$text.Length), ($h=20))
$g = [Drawing.Graphics]::FromImage($bmp)
$g.DrawString($text, [Drawing.Font]::new("Fixedsys", 10), [Drawing.Brushes]::Black, 0, 0)
    
$allPoints = foreach ($x in 0..($w-1))
{
  foreach ($y in 0..($h-1))
  {
    if ($bmp.GetPixel($x, $y).A -gt 0) {
      new-point $x ($h-$y) 0
    }
  }
}
$allPoints | out-3d

2

u/3d-david Nov 20 '20

Wow! That is awesome! That is a simple/elegant solution to 3d text. I'll have to file this away for future reference.

2

u/RedditRo55 Nov 20 '20

Commenting on this so I can't forget it! Wow!

11

u/ypwu Nov 20 '20

This is amazing work. Good job!

3

u/3d-david Nov 20 '20

Thanks! I'm am new to reddit. This feedback is really helpful. I've worked on this in isolation for several months with no idea if it would amount to anything (all of my previous for fun projects never went anywhere).

7

u/Bits_Not_Bytes Nov 20 '20

This is fantastic, really impressive.

I am curious what kind of use cases there are for this?

8

u/3d-david Nov 20 '20

It is a good question. I made this for me and the small community of people that know how to program and work in 3D computer graphics (movie effects, games, architecture visualization, flight simulators, VR).

Some ideas I have (and I'd like to hear others...it motivates me)...

  • Fix 3d model coordinate systems so that they are oriented the way you expect. For example, you get a 3d model of a car for a game you are making. The model loads into your game engine upside down. You could use this to automatically fix new models that have this problem.

  • Visualize virus/molecules

  • Clean up 3d models that have bad geometry. For example, when you scan a person, you may get unwanted vertices that are outside or inside the person. You could write a script to remove those verts.

  • Create turntables of 3d models automatically. A turntable for a 3d model is like a thumbnail for a photo...a way for you to quickly look at the model without loading it into a heavy 3d program like Maya/3d Studio Max/Blender. You could use DDD to load the model and create an animated .gif that shows what the model looks like when it is rotating on a turntable.

  • Create 3d graphs

  • Add normals (how light bounces off a face) to a model that has none

  • Create 3d models via a script (procedural geometry)

  • Create "Levels of Detail" (LOD) of models. Create a lightweight version when a model is used at a distance

  • Converting 3d data from one file format to another

  • Teaching students how 3d works. You can use DDD to see what a matrix looks like. You can manipulate a matrix and visualize the result. I wish I had something like this when I started learning about 3d graphics.

2

u/BestGermanEver Nov 20 '20

Amazing samples. Wouldn't know what to add for you here.

If you have reliable LOD creation offloaded to a simple, command line driven tool like PowerShell you'd make game modder's lifes so much easier if it can replace the ultra-heavy FNVLODGen & xLODGen maybe?

One thing that may be "spiced up" more with some nice visualization:

  • 3D Visualization of Business Metrics & Analytics (based off a given data set, derived from data and analytics backends; Tableau etc.) should also be a good use case. The standard tools especially in Tableau are lacklustre.

1

u/3d-david Nov 20 '20

Can you give me some real world examples of 3d viz of business metrics and analytics?

3

u/BestGermanEver Nov 21 '20

When I say Data, it's not only "Business" but all kinds of Analytics. It makes sense to try to tie data that correlates into one visual representation. Most graphs in 2D fail to bring things together well simply because 2D graphs are limited and if you stack data, it's just "gone" (because it's covered, mostly, by other data points.

If you are able to twist and turn an analytical dashboard in real-time 3D it makes a world of difference.

Here's a really good write-up of multidimensional analytics with some real-world examples.

https://towardsdatascience.com/the-art-of-effective-visualization-of-multi-dimensional-data-6c7202990c57

Couldn't try to describe it better.

2

u/3d-david Nov 21 '20

That is a great idea. I could see that having more universal appeal than my original intent: using powershell to quickly/easily generate charts and graphs.

2

u/BestGermanEver Nov 22 '20

Just another thought:

another way more "fun" use could be displaying audio / equalizer frequency data visually and maybe manipulate the equalizer & frequency range/cap points. I know there are some visualization models out there already, so it would probably be purely for the "sake of it".

Pretty much sure it sounds way easier than it actually is in application because you somehow need to connect to the sound API and I would have next to no clue where to begin tieing that together to represent X,Y,Z coordinates.

2

u/Bits_Not_Bytes Nov 20 '20

Some good examples there. I donโ€™t have a use for this at the moment but hopefully will soon, this could be one way to learn more about 3D.

25

u/the_sun_flew_away Nov 20 '20

Visualising file structures like Jurassic Park ovbs

11

u/Bits_Not_Bytes Nov 20 '20

This is a valid use case.

7

u/Matty_R Nov 20 '20

This is the way.

4

u/matts1900 Nov 20 '20

ITS A UNIX SYSTEM, I KNOW THIS

1

u/techerton Nov 20 '20

It'd be a shame if after you lock the door, they break the glass...

3

u/Bagelbytez Nov 20 '20

Thatโ€™s no PSMoon

2

u/3d-david Nov 20 '20

I thought about remaking the scene from original star wars showing how to blow up the death star using DDD. Still need to add some features (like animation) before I can do that.

3

u/gordonv Nov 20 '20

Where did you learn how to do the math for 3D?

I did up to Calculus 1 and never saw an example on how to do this. Then again, my teachers never bothered to explain the importance of a right triangle while I was worried as a child about all triangles.

3

u/3d-david Nov 20 '20

The only class I took that covered this was a computer science computer graphics class. If you are interested, I recommend this book:
https://www.amazon.com/Math-Primer-Graphics-Game-Development-dp-1568817231/dp/1568817231/ref=dp_ob_title_def

2

u/gordonv Nov 20 '20

Just bought. Thank you. This is the best answer I've had on this topic for the last 15 years I've been asking.

1

u/wtgreen Nov 21 '20

You use linear algebra for 3D graphics. While it could be taught in high school and has lots of application outside of graphics - it's great for solving multiple equations simultaneously - linear algebra isn't usually encountered outside of college.

3

u/YellowOnline Nov 20 '20

Well, I thought I'm rather good with PoSh, but seeing this makes me want to quit my job and sell hamburgers instead.

1

u/3d-david Nov 20 '20

:) I bet you could teach me a lot about using PowerShell!

2

u/bloodniece Nov 20 '20

Nice. Might have to pair that with Max/MSP and Jitter.

1

u/3d-david Nov 20 '20

I had to look up what Max/MSP/jitter is.
https://en.wikipedia.org/wiki/Max_%28software%29

This sounds very interesting. I'm curious what you find out. Let me know if you need any changes to make it work better with Max.

2

u/bajinabass Nov 20 '20

I wonder what the TTP will be for this. (This is a really cool module thoug!)

2

u/3d-david Nov 20 '20

What is TTP?

3

u/bajinabass Nov 20 '20

An abbreviation for Time To Penis. Used by game developers and graphic designers as a way to describe how long it will be before the players or users find a way to represent penises in the game. These could either be chat or text descriptions, static images, or even animated penises.

1

u/3d-david Nov 20 '20

Ha! I actually knew that...but wasn't expecting that term here.

2

u/NotNotWrongUsually Nov 20 '20 edited Nov 20 '20

Awesome job, I always like to see Powershell utilized outside its normal element!

A heightmap for the hell of it:

Add-Type -Assembly 'System.Drawing'
Import-Module 'DDD'

Invoke-WebRequest 'https://upload.wikimedia.org/wikipedia/commons/5/57/Heightmap.png' -OutFile 'heightmap.png'
$bmp = [System.Drawing.Bitmap]::FromFile('./heightmap.png')

$scale = 50

$points = for ($y = 0; $y -lt $bmp.Height; $y++) {
    for ($x = 0; $x -lt $bmp.Width; $x++) {
        New-Point $x $y ($bmp.GetPixel($x,$y).GetBrightness() * $scale)
    }
}

$points | Out-3d

It sort of turns into a yellow blob because of the density though :/

2

u/3d-david Nov 20 '20

That is cool...but it shows me that I really need to get zoom to work right (I took it out because it was flaky).

I'll use your sample as a test case. Thanks!

2

u/gordonv Nov 21 '20

Just spun up my Ubuntu 20.x test VM and tried it on pwsh.

Doesn't work. womp womp. But, I guess someone had to try. :D

2

u/3d-david Nov 21 '20

I documented that in my blog post. I have not implemented Out-3d for Linux or Mac. That is next on my TODO.

2

u/Jaykul Nov 21 '20

That's awesome. Now you just need to draw it in the console, like Lee ๐Ÿ˜‰
https://www.leeholmes.com/blog/2014/10/09/playing-with-classes-in-powershell-v5-preview/

2

u/3d-david Nov 21 '20

I was excited for a second...the ability to embed graphics in a console window would be awesome...but I can see this is ascii art. That is a cool idea...and it would work cross platform. BUT...it doesn't give me the resolution/color I'd like and it does not take advantage of hardware accelerated graphics.

1

u/Jaykul Dec 18 '20

There are ways to do better graphics (e.g. sixels), but until Windows 10 console and Windows Terminal get them, they're not very cross-platform ๐Ÿ˜‰

https://github.com/microsoft/terminal/issues/448

2

u/Mi4c_posh May 11 '21 edited May 11 '21

Yes powershell was always supporting 3D graphics, here is something I have done.(I know the whole bunch of comments are not encouraging ones, but you have done also good job. I post and share my version just to encourage you more... My doings were just to try to learn and understand more about powershell classes. I'm not a coder or even advanced powershell scripter, so what I have created is beyond over my imagination what I could even create with powershell... Anyone can bitch to my reply, but please provide something that you can show that is more...)

mi4c/Posh3d_cube_ball: This was just my test how to do some 3D graphics with powershell... (github.com)

1

u/3d-david May 12 '21

Very nice. I see you are using WPF for the 3d graphics. I looked into WPF 3d graphics at one point...it is impressive what you can do with it. I decided to go with pure OpenGL for 3d graphics so my module would work on Mac and Linux as well as Windows. It blows my mind that the same powershell "binary" module can work on all three platforms. PowerShell is pretty cool.

110

u/ArgonWilde Nov 20 '20

Start-PSDoom when?

32

u/Bissquitt Nov 20 '20

Crap, I used Invoke-Doom by accident

0

u/[deleted] Nov 20 '20

[deleted]

8

u/Proxiconn Nov 20 '20

yes but with the -Force -ErrorAction Bypass options.

19

u/HeKis4 Nov 20 '20

-Erroraction LoudlyContinue

2

u/Bissquitt Nov 21 '20

Try{ Invoke-Doom -Target Mankind -Type Pestilence -Year 2020 -Force -Erroraction LoudlyBypass }

Catch{ Do{}while($true) }

Finally{ Remove-Item earth32 -recurse }

2

u/HeKis4 Nov 21 '20

Too bad powershell doesn't have goto, because I 100% see a goto january1st2020in that Catch block.

1

u/Bissquitt Nov 25 '20

Start-Process powershell.exe "-File",('"{0}"' -f $MyInvocation.MyCommand.Path)

5

u/-eschguy- Nov 20 '20

Okay you joke.....but seriously. Somebody needs to get on it, followed by the opening to Skyrim.

8

u/therealblergh Nov 20 '20 edited Aug 14 '25

flowery different entertain chase afterthought provide pie zephyr marvelous placid

This post was mass deleted and anonymized with Redact

1

u/gordonv Nov 20 '20

Aww yeah!

1

u/HostileApostle420 Nov 20 '20

Yet pscore still can't properly call dotnet to popup MA prompts

2

u/3d-david Nov 20 '20

MA? What does that stand for?

2

u/jello3d Nov 20 '20

hmmm... Modal AJAX? Hard to tell... these kids and their slang.

1

u/bpgould Nov 20 '20

Just looked through your blog.. what exactly was your job title? I can't tell if you were IT or software engineer or software-writing-server-wrangling-IT-superman?

3

u/3d-david Nov 20 '20

I call myself a "3D Graphics Engineer." My career has been doing 3D graphics using C++. I've worked on: flight simulators, movie special effects, video games, rendering home interiors, creating holograms of people, and self-driving cars.

3

u/surefirelongshot Nov 20 '20

Death Star generator!

2

u/SolidKnight Nov 20 '20

Get-Process | Out-3d and swim through the output in your hololens.

1

u/fungaming51official Aug 18 '23

It only shows the out-3d cmdlet for me.

1

u/[deleted] Nov 20 '20

[removed] โ€” view removed comment

1

u/AutoModerator Nov 20 '20

Sorry, your submission has been automatically removed.

Accounts must be at least 1 day old, which prevents the sub from filling up with bot spam.

Try posting again tomorrow or message the mods to approve your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.