Blender (jusqu'à 2.49)
Python
MESH :  "trim" vers un plan :
projeter les sommets sélectionnés 
vers un plan ou une face
(english version )
    Début   Index
précédentScript Python
Random duplivert : Suivant
Télécharger le script

Objectif
projeter orthogonalement les sommets sélectionnées vers le plan défini par une face du même mesh .
(dans le même style et avec les mêmes équations :cpl_scriptmirror3.htm )

Installation 
Copiez le fichier trimvertex2plane.py dans le répertoire .blender/scripts

Procédure
Simple et fonctionne en mode edit : 
1/ ouvrez une fenêtre python  ou passez par le menu Scripts :

2/ chargez le script  trimvertex2plane.py qui doit porter le nom "Trim Vertices to face" dans le menu Scripts/Mesh
3/ passez dans la fenêtre 3d, sélectionnez une face et une seule
4/ appuyez sur le bouton Original Face

5/ sélectionnez les sommets ou faces auxquels vous souhaitez applique le déplacement .
6/ appuyez sur Selected vertex list.

Les sommets sélectionnés seront projetés en suivant un axe perpendiculaire au plan défini par la face originale . 

#!BPY

"""
Name: 'Trim Vertices to a plane'
Blender: 237
Group: 'Mesh'
Tooltip: 'Make a orthogonal projection of the selected vertices to the selected face'
"""
__author__ = "Jean-Michel Soler (jms)"
__url__ = ("Script's homepage, jmsoler/didacticiel/blender/tutor/py_trimvertex2plane.htm",
"Communicate problems and errors, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender")
__version__ = "Trim Vertices to face, 2005/06/05-->2006/07/16"

__bpydoc__ = """

The  procedure is very simple and works in edit mode:

1/ open the Scrips window
2/ select and load the script Trim Vertices to face in the Mesh menu
3/ in the 3d window, select one and only one face in a mesh
4/ get out of this mesh
5/ push the button Original Face
5/ then select all the vertices you want to trim in an another mesh
6/ push Selected vertex list button.
_________________

La procedure est simple et fonctionne en mode edit : 

1/ Ouvrez une fenêtre python 
2/ Chargez le script TrimVertices2face.py
3/ Passez dans la fenêtre 3d, 
4/ Selectionnez un objet mesh
5/ Passez en mode edit, 
6/ Dans cet objet selectionnez une face et une seule 
7/ Sortez du mode edit
8/ Dans l'interface du script, appuyez sur le bouton Original Face
9/ Selectionner un autre objet mesh 
10/ Entrez en mode edit 
11/ Selectionnez tous les vertices/sommets qui devront être modifies
11 bis/ Il est toujours possible de faire un extrude sur place 
12/ Appuyez sur Selected vertex list. Les sommets sont projetes sur 
    le plan d elaface selectionner dans l'autre mesh 

""" 

# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Copyright (C) 2005: jm soler, jmsoler_at_free.fr
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# -------------------------------------------------------------------------- 
import Blender
from Blender.Draw import *
from Blender.BGL import *
from Blender.NMesh import *
from Blender.Registry import *

axe={} 
pos=[]
#a,b,c,d=0,0,0,0
#x,y,z=0.0,0.0,0.0

def draw():
    glClear(GL_COLOR_BUFFER_BIT)
    glRasterPos2f(20, 80)
    Text("orthogonal projection to the selected plane.")

    dec=20

    Button("Original Face", 2, 20, 55, 120, 18)
    Button("Selected Vertex list", 3, 145, 55, 120, 18)

    #boutons de sortie
    Button("Exit", 1, 20, 10, 80, 19)

def  EquationPlan (v1,v2,v3):

    x =v1[0] 
    y =v1[1]
    z =v1[2]
    X1=x; Y1=y; Z1=z;

    x =v2[0] 
    y =v2[1]
    z =v2[2]
    X2=x; Y2=y; Z2=z;

    x =v3[0] 
    y =v3[1]
    z =v3[2]
    X3=x; Y3=y; Z3=z;

    a  = Y1 * (Z2 - Z3) + Y2 * (Z3 - Z1) + Y3 * (Z1 - Z2)
    b  = -X1 * (Z2 - Z3) + X2 * (Z1 - Z3) - X3 * (Z1 - Z2)
    c  = X1 * (Y2 - Y3) - X2 * (Y1 - Y3) + X3 * (Y1 - Y2)
    d  = -X1*(Y2*Z3-Y3*Z2)+X2*(Y1*Z3-Y3*Z1)-X3*(Y1*Z2-Y2*Z1)
    return [a,b,c,d]

#Point miroite dans le plan
def point_trime(nx,ny,nz,k,p):
    A=-(nx*p[0]+ny*p[1]+nz*p[2]+k)/(nx*nx+ny*ny+nz*nz)
    print p
    return nx*A+p[0], ny*A+p[1], nz*A+p[2]
 

def event(evt, val): 
    if (evt== QKEY and not val): Exit()

def bevent(evt):
    if   (evt== 1):
        Exit()

    if   (evt== 2):
        in_editmode = Blender.Window.EditMode()
        if in_editmode: 
            Blender.Window.EditMode(0)
        O=Blender.Object.GetSelected()[0]
        ME=O.getData()
        ME.transform(O.matrix)
        FACES=ME.faces
        F=[f for f in FACES if f.sel==1]

        if len(F)==1:
           d={}
           d['loc']=O.matrix.translationPart()[:]
           d['pos']=[F[0].v[0].co,F[0].v[1].co,F[0].v[2].co]
           for n in [0,1,2]  :
               d['pos'][n][0]+=d['loc'][0]
               d['pos'][n][1]+=d['loc'][1]
               d['pos'][n][2]+=d['loc'][2]

           print d['loc']
           SetKey('TRIMFACE',d,True)

        else:
           PupMenu("Sorry, only one Face ! %t| OK.") 

        if in_editmode: 
            Blender.Window.EditMode(1)

    if   (evt== 3):
           O=Blender.Object.GetSelected()[0]
           if O.getType()=='Mesh':
             in_editmode = Blender.Window.EditMode()
             if in_editmode: 
                Blender.Window.EditMode(0)
             d=GetKey('TRIMFACE',True) 
             pos = d['pos'][:]
             loc = d['loc'][:]
             print '\n\npos',pos
             mat=Blender.Mathutils.Matrix(O.matrix)
             mat.invert() 
             for n in [0,1,2]  :
               pos[n][0]-=O.matrix.translationPart()[0]+loc[0]
               pos[n][1]-=O.matrix.translationPart()[1]+loc[1]
               pos[n][2]-=O.matrix.translationPart()[2]+loc[2]
               pos[n]*=mat 
             pos=EquationPlan(pos[0],pos[1],pos[2])
             M=O.getData()

             v=[v for v in M.verts if v.sel==1]
             for v0 in v: 
                 v0.co[0],v0.co[1],v0.co[2]=point_trime(pos[0],pos[1],pos[2],pos[3],v0.co)

             M.update()
             if in_editmode: 
                    Blender.Window.EditMode(1)
             O.makeDisplayList()

    Blender.Window.RedrawAll()
Register(draw, event, bevent)


 
précédentScript Python
 Random duplivert : Suivant
Vers le  Haut de page

Les questions concernant cette page  peuvent être posées sur  :
 news://news.zoo-logique.org/3D.Blender


 

 

Livre en français
Blender : apprenez, pratiquez, Créez, livre, Ed. Campus Press, coll. Starter Kit
Blender Starter Kit

Forum
FAQ
Lexique
Didacticiels
Compilations
Blender2KT
Débuter
Modelage
Blender python
Materiaux
Lumière
Animation
API python (eng)
Archives nzn
Statistiques
Doc flash Sculptris
Galerie Sculptris

mon site de démos sur youtube