Blender (jusqu'à 2.49)
Python
MESH :  "trim" to plane :
project selected vertices to a plane or a  face
(version française)
Beginning Index
previous Script Python
Random duplivert : Nextt
Download the script  (updated : 2005/10/16)

 

Objective
to project the selected  vertices towards the plan defined by a face of  the same mesh

Installation 
Copy the file trimvertex2plane.py in the .blender/scripts directory .

Procedure
Simple and functions in edit mode:

1/ open a  python window or pass by  the Scripts menu:

2/ load  the script trimVertex2plane.py which must bear the name "Trim Vertices to face" in the menu Scripts/Mesh.

3/ pass in the 3D window,  select a face and only one.
4/ press on the button Original Face

5/ select the vertices or the faces to which you wish to apply the displacement.
6/ press on the button  Selected vertex list.

#!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-->2005/10/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 teh Mesh menu
3/ in the 3d window, select one and only one face
4/ push the button Original Face
5/ then select all the vertices you want to trim
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, sélectionnez une face et une seule 
4/ appuyez sur le bouton Original Face
5/ sélectionnez tous les vertices/sommets qui devront être modifies
6/ appuyez sur Selected vertex list.

""" 

# --------------------------------------------------------------------------
# ***** 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.co[0] 
    y =v1.co[1]
    z =v1.co[2]
    X1=x; Y1=y; Z1=z;

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

    x =v3.co[0] 
    y =v3.co[1]
    z =v3.co[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_miroite(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]
        F=[f for f in O.getData().faces if f.sel==1]
        if len(F)==1:
           d={}
           d['pos']=EquationPlan (F[0].v[0],F[0].v[1],F[0].v[2])
           SetKey('TRIMFACE',d,True)
           #print d['pos']
        else:
           PupMenu("Sorry, only one Face ! %t| OK.") 

        if in_editmode: 
            Blender.Window.EditMode(1)

    if   (evt== 3):
           d=GetKey('TRIMFACE',True) 
           pos=d['pos']
           print pos
           in_editmode = Blender.Window.EditMode()
           if in_editmode: 
              Blender.Window.EditMode(0)
           O=Blender.Object.GetSelected()[0]
           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_miroite(pos[0],pos[1],pos[2],pos[3],v0.co)# point_projete(pos,v0.co)
           M.update()
           if in_editmode: 
                 Blender.Window.EditMode(1)

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


 
previous Script Python
 Random duplivert : Next
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