abrahimladha 9 years ago
commit
21cfdfeac3
3 changed files with 91 additions and 0 deletions
  1. 22 0
      LICENSE
  2. 22 0
      README.md
  3. 47 0
      mosher.cpp

+ 22 - 0
LICENSE

@ -0,0 +1,22 @@
1
The MIT License (MIT)
2
3
Copyright (c) 2015 Abrahim Ladha
4
5
Permission is hereby granted, free of charge, to any person obtaining a copy
6
of this software and associated documentation files (the "Software"), to deal
7
in the Software without restriction, including without limitation the rights
8
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
copies of the Software, and to permit persons to whom the Software is
10
furnished to do so, subject to the following conditions:
11
12
The above copyright notice and this permission notice shall be included in all
13
copies or substantial portions of the Software.
14
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
SOFTWARE.
22

+ 22 - 0
README.md

@ -0,0 +1,22 @@
1
# obj-mosher
2
Very simple program. Will take .obj file as input and output scrambled .obj file, reverse scrambling all but on a specified layer.
3
4
Follow this tutorial to generate an obj from an image using blender. https://www.youtube.com/watch?v=_YbvXgls1Yw
5
This program works assuming you have isolated your object in your image using some editor already. Open up your obj in a text editor and look for the most common second value of lines beginning with "v " and use that as the height parameter. 
6
Using this image of an egg:
7
8
![pure image](http://i.imgur.com/DEPMGPp.jpg)
9
10
I used GIMP and upped the contrast and so that the background would be a solid black:
11
![after gimp](http://i.imgur.com/hjepRLQ.png)
12
13
Then used the blender displace technique to create a surface that looks like:
14
![in 3D](http://i.imgur.com/QKDF6L3.png)
15
16
And then ran my program on it to make this, (notice the background is not moshed)
17
![glitched!](http://i.imgur.com/vBeXuqy.png)
18
19
Adding the edited egg image back on as a texture and rendering the surface as BSDF Glossy:
20
![final art project](http://i.imgur.com/uVFomyX.png)
21
22
The final product turned out nicely I think.

+ 47 - 0
mosher.cpp

@ -0,0 +1,47 @@
1
#include <fstream>
2
#include <string>
3
#include <vector>
4
using namespace std;
5
int main(){
6
	string FILE_NAME = "egg";
7
	string HEIGHT_VALUE = "-0.050000";
8
	string line;
9
	vector<string> vert; 
10
	ifstream input;
11
	ofstream output;
12
	ifstream input1;
13
	ofstream output1;
14
	string a;
15
	input.open(FILE_NAME + ".obj");
16
	output.open(FILE_NAME + "_half.obj");
17
		while(getline(input,line)){
18
			if(line.substr(0,2) == "v "){
19
				if(line.find(HEIGHT_VALUE) != std::string::npos){
20
					output << line << "\n";
21
				}
22
				else{
23
				vert.push_back(line);
24
				output << "\n";
25
				}
26
			}
27
			else{
28
				output << line << "\n";
29
			}
30
		}
31
	input.close();
32
	output.close();
33
	input1.open(FILE_NAME + "_half.obj");
34
	output1.open(FILE_NAME + "_mosh.obj");
35
		while(getline(input1,line)){
36
			if(line == ""){
37
				output1 << vert.back(); << "\n";
38
				vert.pop_back();
39
			}
40
			else{
41
				output1 << line << "\n";
42
			}
43
		}
44
	
45
	input1.close();
46
	output1.close();
47
}