Commit f23ebdd0 authored by frankie's avatar frankie 💬

removal of unused files

parent 7a0d28c1
import bpy
import math
import mathutils
export_path = "/home/frankiezafe/forge.godot/softskin_demo/softskin/platypus.softskin"
softskin_version = 2
ligament_prefix = "_liga"
corr_mat = mathutils.Matrix()
corr_mat[0] = mathutils.Vector( (-1,0,0,0) )
corr_mat[1] = mathutils.Vector( (0,0,1,0) )
corr_mat[2] = mathutils.Vector( (0,1,0,0) )
corr_mat[3] = mathutils.Vector( (0,0,0,1) )
# export_path = "/home/frankiezafe/forge.godot/softskin_demo/softskin/cylinder.softskin"
obj = bpy.data.objects["duck"]
mesh = obj.data
vgroups = obj.vertex_groups
uvlayer = mesh.uv_layers[0]
verts = []
anchors = []
orphans = []
fibers = []
tensors = []
ligaments = []
muscles = []
def belong_to_edge( vid ):
for e in mesh.edges:
if e.vertices[0] == vid:
return True
if e.vertices[1] == vid:
return True
return False
def belong_to_face( vid ):
for p in mesh.polygons:
for i in range(0,len(p.vertices)):
if p.vertices[i] == vid:
return True
return False
def ligament( e ):
# at least one of the vertice must NOT belong to a face!
if belong_to_face(e.vertices[0]) == True and belong_to_face(e.vertices[1]) == True:
return False
return True
'''
v0 = mesh.vertices[e.vertices[0]]
v1 = mesh.vertices[e.vertices[1]]
# seeking if both vertices belongs to the same vertex group starting with "ligament"
res = "" + str(e.vertices[0]) + ":" + str(e.vertices[1]) + " > "
lg0 = "0"
lg1 = "1"
for g in v0.groups:
vg = vgroups[g.group]
if vg.name[:len(ligament_prefix)] == ligament_prefix:
lg0 = vg.name
res += vg.name + ", "
break
for g in v1.groups:
vg = vgroups[g.group]
if vg.name[:len(ligament_prefix)] == ligament_prefix:
lg1 = vg.name
res += vg.name + ", "
break
return lg0 == lg1
'''
def edge_groups(e, groups):
v0 = mesh.vertices[e.vertices[0]]
v1 = mesh.vertices[e.vertices[1]]
out = []
for g0 in v0.groups:
found = False
for gg in groups:
if g0.group == gg[0]:
found = True
break
if not found:
continue
found = False
for g1 in v1.groups:
if g1.group == g0.group:
i = 0
for gg in groups:
if g0.group == gg[0]:
if not i in out:
out.append( i )
found = True
break
i += 1
if found:
break
return out
def anchor_groups(a,groups):
out = []
for g0 in a.groups:
i = 0
for gg in groups:
if g0.group == gg[0]:
if not i in out:
out.append( i )
break
i += 1
return out
def get_position( id, list ):
for i in range( 0, len(list) ):
if list[i] == id:
return i
return -1
# splitting vertices in 2 groups: vertices and anchors
# detection of vertices not included in faces (will be saved as anchors)
for i in range( 0, len(mesh.vertices) ):
if belong_to_edge(i):
if belong_to_face(i):
verts.append(i)
else:
anchors.append(i)
else:
orphans.append(i)
# collecting groups not prefixed by "_"
groups = []
for gr in vgroups:
if gr.name[:1] == "_":
continue
empty = True
for v in mesh.vertices:
for g in v.groups:
if g.group == gr.index:
empty = False
if not empty:
groups.append( [ gr.index, gr.name ] )
# starting export
export = open(export_path, "w")
export.write( "++softskinversion++" + str(softskin_version) + "\n" )
export.write( "++vertices++" + str(len(verts)) + "\n" )
export.write( "# id x y z normx normy normz\n" )
i = 0
for id in verts:
vert = mesh.vertices[id]
mat_loc = corr_mat * mathutils.Matrix.Translation((vert.co[0], vert.co[1], vert.co[2]))
v = mat_loc.to_translation()
mat_loc = corr_mat * mathutils.Matrix.Translation((vert.normal[0], vert.normal[1], vert.normal[2]))
n = mat_loc.to_translation()
export.write( str(i) + " " + str(v[0]) + " " + str(v[1]) + " " + str(v[2]) + " " + str(n[0]) + " " + str(n[1]) + " " + str(n[2]) + "\n" )
i += 1
export.flush()
export.write( "++anchors++" + str(len(anchors)) + "\n" )
export.write( "# id x y z\n" )
i = 0
for id in anchors:
vert = mesh.vertices[id]
mat_loc = corr_mat * mathutils.Matrix.Translation((vert.co[0], vert.co[1], vert.co[2]))
v = mat_loc.to_translation()
export.write( str(i) + " " + str(v[0]) + " " + str(v[1]) + " " + str(v[2]) + "\n" )
i += 1
export.flush()
export.write( "++groups++" + str(len(groups)) + "\n" )
i = 0
for g in groups:
export.write( str(i) + " " + str(g[1]) + "\n" )
i += 1
# sorting edges in 4 kinds:
# - fiber ( NOT belongs to a "ligament*" group and is NOT sharp )
# - tensor ( NOT belongs to a "ligament*" group and IS sharp )
# - ligament ( belongs to a "ligament*" group and is NOT sharp )
# - muscle ( belongs to a "ligament*" group and IS sharp )
i = 0
for e in mesh.edges:
if not ligament(e):
if e.use_edge_sharp == False:
fibers.append(i)
else:
tensors.append(i)
else:
if e.use_edge_sharp == False:
ligaments.append(i)
else:
muscles.append(i)
i += 1
export.write( "++fibers++" + str(len(fibers)) + "\n" )
export.write( "# verticeid verticeid [groupid...]\n" )
for i in fibers:
e = mesh.edges[i]
export.write( str(get_position(e.vertices[0],verts)) + " " + str(get_position(e.vertices[1],verts)) )
fgs = edge_groups(e,groups)
for i in fgs:
export.write( " " + str(i) )
export.write( "\n" )
export.write( "++tensors++" + str(len(tensors)) + "\n" )
export.write( "# verticeid verticeid [groupid...]\n" )
for i in tensors:
e = mesh.edges[i]
print( "tensors", i, edge_groups(e,groups) )
export.write( str(get_position(e.vertices[0],verts)) + " " + str(get_position(e.vertices[1],verts)) )
fgs = edge_groups(e,groups)
for i in fgs:
export.write( " " + str(i) )
export.write( "\n" )
export.flush()
export.write( "++ligaments++" + str(len(ligaments)) + "\n" )
export.write( "# verticeid anchorid [groupid...]\n" )
for i in ligaments:
e = mesh.edges[i]
v0 = get_position(e.vertices[0],verts)
v1 = get_position(e.vertices[1],anchors)
anchor = e.vertices[1]
if v0 == -1:
v0 = get_position(e.vertices[1],verts)
v1 = get_position(e.vertices[0],anchors)
anchor = e.vertices[0]
if v0 == -1:
print( "Error in ligaments! can not locate vertice and anchor!!!" )
continue
export.write( str(v0) + " " + str(v1) )
efgs = edge_groups(e,groups)
for i in efgs:
export.write( " " + str(i) )
afgs = anchor_groups(mesh.vertices[anchor],groups)
for i in afgs:
if not i in efgs:
export.write( " " + str(i) )
export.write( "\n" )
export.write( "++muscles++" + str(len(muscles)) + "\n" )
export.write( "# verticeid anchorid [groupid...]\n" )
for i in muscles:
e = mesh.edges[i]
v0 = get_position(e.vertices[0],verts)
v1 = get_position(e.vertices[1],anchors)
anchor = e.vertices[1]
if v0 == -1:
v0 = get_position(e.vertices[1],verts)
v1 = get_position(e.vertices[0],anchors)
anchor = e.vertices[0]
if v0 == -1:
print( "Error in muscles! can not locate vertice and anchor!!!" )
continue
export.write( str(v0) + " " + str(v1) )
efgs = edge_groups(e,groups)
for i in efgs:
export.write( " " + str(i) )
afgs = anchor_groups(mesh.vertices[anchor],groups)
for i in afgs:
if not i in efgs:
export.write( " " + str(i) )
export.write( "\n" )
export.flush()
'''
export.write( "++edges++" + str(len(mesh.edges)) + "\n" )
for e in mesh.edges:
s = 0
if ligament( e ) == True:
s += 2
if e.use_edge_sharp == True:
s += 1
export.write( str(e.vertices[0]) + " " + str(e.vertices[1]) + " " + str(s) + "\n" )
export.flush()
'''
export.write( "++faces++" + str(len(mesh.polygons)) + "\n" )
export.write( "# verticeid verticeid verticeid u v\n" )
for p in mesh.polygons:
for i in range(0,len(p.vertices)):
if i > 0:
export.write( " " )
export.write( str(p.vertices[i]) )
# link uv data for this face
for i in range(0,p.loop_total):
export.write( " " )
uv = uvlayer.data[ p.loop_start + i ].uv
export.write( str(uv.x) + " " + str(uv.y) )
export.write( "\n" )
export.flush()
export.close()
'''
print( "verts", verts )
print( "anchors", anchors )
print( "orphans", orphans )
print( "fibers", fibers )
print( "tensors", tensors )
print( "ligaments", ligaments )
print( "muscles", muscles )
'''
print( mesh, len(mesh.vertices) )
\ No newline at end of file
import bpy
import bmesh
import mathutils
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
def search_next_quad( mesh ):
for p in mesh.polygons:
if len(p.vertices) != 3:
p.select = True
vs = []
for i in p.vertices:
vs.append( i )
return vs
return None
vs = search_next_quad(obj.data)
while vs != None and len(vs) == 4:
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.delete(type='FACE')
# barycenter of points
bary = mathutils.Vector((0.0,0.0,0.0))
for i in vs:
bary += mathutils.Vector(obj.data.vertices[i].co)
bary /= len( vs )
bm = bmesh.from_edit_mesh(obj.data)
bm.verts.new(bary)
bmesh.update_edit_mesh(obj.data, False, True)
#select new vert
for i in range( 0, 4 ):
nexti = (i + 1) % 4
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT')
obj.data.vertices[ vs[i] ].select = True
obj.data.vertices[ vs[nexti] ].select = True
obj.data.vertices[ len( obj.data.vertices ) - 1 ].select = True
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.edge_face_add()
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT')
#vs = None
vs = search_next_quad(obj.data)
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
/*
*
*
* _________ ____ .-. _________/ ____ .-. ____
* __|__ (_)_/(_)( )____< \| ( ) (_)
* `-' `-'
*
*
* art & game engine
*
* ____________________________________ ? ____________________________________
* (._.)
*
*
* This file is part of softskin library
* For the latest info, see http://polymorph.cool/
*
* Copyright (c) 2018 polymorph.cool
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* ___________________________________( ^3^)_____________________________________
* []
* ascii font: rotated by MikeChat & myflix
* have fun and be cool :)
*/
#ifndef SOFTSKIN_H
#define SOFTSKIN_H
#include <iostream>
#include <vector>
#include "skin_dot.h"
#include "skin_anchor.h"
#include "skin_edge.h"
#include "skin_fiber.h"
#include "skin_group.h"
#include "skin_common.h"
#include "skinnotifier.h"
#include "scene/3d/immediate_geometry.h"
class Skin : public VisualInstance, public SkinNotifierListener {
GDCLASS(Skin, VisualInstance);
enum surface_position_t {
surf_MAIN = 0,
surf_FIBER = 1,
surf_TENSOR = 2,
surf_LIGAMENT = 3,
surf_MUSCLE = 4,
surf_COUNT = 5
};
public:
Skin();
~Skin();
static std::string print_type(const surface_position_t& t) {
switch (t) {
case surf_MAIN:
return "surf_MAIN";
case surf_FIBER:
return "surf_FIBER";
case surf_TENSOR:
return "surf_TENSOR";
case surf_LIGAMENT:
return "surf_LIGAMENT";
case surf_MUSCLE:
return "surf_MUSCLE";
default:
return "INVALID TYPE!";
}
}
// interactions
void hit(
const Vector3& from,
const Vector3& to,
const real_t& radius,
SkinRay& ray
);
void drag(SkinRay& ray);
void ray_world_position(
const Vector3& from,
const Vector3& to,
SkinRay& ray);
void cube();
void grid(uint32_t divx, uint32_t divy);
void parse(const String& path);
void update(const float& delta_time);
//***********
//* SETTERS *
//***********
void set_type(const int& type);
void set_soft_skin_path(const String& path);
void set_main_display(const bool& display);
void set_fiber_display(const bool& display);
void set_tensor_display(const bool& display);
void set_ligament_display(const bool& display);
void set_muscle_display(const bool& display);
void set_local_gravity(const Vector3& g);
void set_main_material(const Ref<Material> &material);
void set_fiber_material(const Ref<Material> &material);
void set_tensor_material(const Ref<Material> &material);
void set_ligament_material(const Ref<Material> &material);
void set_muscle_material(const Ref<Material> &material);
void set_axis_material(const Ref<Material> &material);
void set_feedback_damping(const float& s);
void set_feedback_softness(const float& s);
//***********
//* GETTERS *
//***********
int type() const;
String soft_skin_path() const;
bool main_display() const;
bool fiber_display() const;
bool tensor_display() const;
bool ligament_display() const;
bool muscle_display() const;
Vector3 local_gravity() const;
Ref<Material> main_material() const;
Ref<Material> fiber_material() const;
Ref<Material> tensor_material() const;
Ref<Material> ligament_material() const;
Ref<Material> muscle_material() const;
Ref<Material> axis_material() const;
float feedback_damping() const;
float feedback_softness() const;
const Vector3& feedback() const;
const Vector3& delta_position() const;
const Vector3& local_motion_orientation() const;
// mandatory methods for VisualInstance
virtual AABB get_aabb() const;
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
SkinGroupFiber* get_fibers( const String& name );
SkinGroupLigament* get_ligaments( const String& name );
Vector3 get_global_barycenter( const String& name );
Vector3 get_local_barycenter( const String& name );
protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
static void _bind_methods();
AABB aabb;
private:
bool first_update; // avoid skin to explode at the first frame
uint32_t dots_num;
uint32_t anchors_num;
uint32_t edges_num;
uint32_t fibers_num;
uint32_t ligaments_num;
uint32_t faces_num;
uint32_t groups_num;
SkinDot* dots;
SkinAnchor* anchors;
Vector3* forces;
Vector< SkinEdge* > edges;
SkinFiber* fibers;
SkinLigament* ligaments;
Vector< SkinGroup* > groups;
Vector3 _local_gravity;
Vector3 _gravity;
bool _update_gravity;
float _ligament_strength;
float _tensor_frequency; // 0.5 by default
float _tensor_mult_min; // 0.2 by default
float _tensor_mult_max; // 1.4 by default
float _muscle_strength;
float _muscle_frequency;
Vector3 _feedback_force;
Vector3 _feedback_consumed;
Vector3 _feedback;
float _feedback_damping;
float _feedback_softness;
Quat _previous_orientation;
Vector3 _previous_position;
Vector3 _delta_position;
Vector3 _local_motion_orientation;
Ref<ArrayMesh> root_mesh;
Vector<ShapeUpdateSurface> surfaces;
String _soft_skin_path;
bool _main_display;
bool _fiber_display;
bool _tensor_display;
bool _ligament_display;
bool _muscle_display;
Ref<Material> _main_material;
Ref<Material> _fiber_material;
Ref<Material> _tensor_material;
Ref<Material> _ligament_material;
Ref<Material> _muscle_material;
void purge();
// returns a vector of indices
void generate_mesh(SkinRaw& raw, Vector< uint32_t >&);
void generate_debug(SkinRaw& raw, surface_position_t spt);
void push_in_group( uint32_t gid, SkinEdge* );